yjs/doc/class/JsonWrapper.html
2014-08-05 17:04:39 +02:00

195 lines
5.4 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<title>Yatta! Documentation</title>
<script src='../javascript/application.js'></script>
<script src='../javascript/search.js'></script>
<link rel='stylesheet' href='../stylesheets/application.css' type='text/css'>
</head>
<body>
<div id='base' data-path='../'></div>
<div id='header'>
<div id='menu'>
<a href='../extra/README.md.html' title='Yatta!'>
Yatta!
</a>
&raquo;
<a href='../alphabetical_index.html' title='Index'>
Index
</a>
&raquo;
<span class='title'>JsonWrapper</span>
</div>
</div>
<div id='content'>
<h1>
Class:
JsonWrapper
</h1>
<table class='box'>
<tr>
<td>Defined in:</td>
<td>lib&#47;Types&#47;JsonTypes.coffee</td>
</tr>
</table>
<h2>Overview</h2>
<div class='docstring'>
<div class='note'>
<strong>Note:</strong>
You can only overwrite existing values! Setting a new property won&#39;t have any effect!
</div>
<p>A JsonWrapper was intended to be a convenient wrapper for the JsonType.
But it can make things more difficult than they are.</p><p>It creates Javascripts -getter and -setter methods for each property that JsonType maintains.</p><p>In order to set a new property you have to overwrite an existing property.
Therefore the JsonWrapper supports a special feature that should make things more convenient
(we can argue about that, use the JsonType if you don&#39;t like it ;).
If you overwrite an object property of the JsonWrapper with a new object, it will result in a merged version of the objects.
Let w.p the property that is to be overwritten and o the new value. E.g. w.p = o</p><ul>
<li>The result has all properties of o</li>
<li>The result has all properties of w.p if they don&#39;t occur under the same property-name in o.</li>
</ul>
<div class='examples'>
<h3>Examples:</h3>
<h4>
create a JsonWrapper
</h4>
<pre><code class='coffeescript'># You get a JsonWrapper from a JsonType by calling
w = yatta.value</code></pre>
<h4>
Getter Example
</h4>
<pre><code class='coffeescript'># you can access the x property of yatta by calling
w.x
# instead of
yatta.val(&#39;x&#39;)</code></pre>
<h4>
Setter Example
</h4>
<pre><code class='coffeescript'># you can set an existing x property of yatta by calling
w.x = &quot;text&quot;
# instead of
yatta.val(&#39;x&#39;, &quot;text&quot;)</code></pre>
<h4>
Conflict Example
</h4>
<pre><code class='coffeescript'>yatta.value = {a : &quot;string&quot;}
w = yatta.value
console.log(w) # {a : &quot;string&quot;}
w.a = {a : {b : &quot;string&quot;}}
console.log(w) # {a : {b : &quot;String&quot;}}
w.a = {a : {c : 4}}
console.log(w) # {a : {b : &quot;String&quot;, c : 4}}</code></pre>
<h4>
Common Pitfalls
</h4>
<pre><code class='coffeescript'>w = yatta.value
# Setting a new property
w.newProperty = &quot;Awesome&quot;
console.log(w.newProperty == &quot;Awesome&quot;) # false, w.newProperty is undefined
# overwrite the w object
w = {newProperty : &quot;Awesome&quot;}
console.log(w.newProperty == &quot;Awesome&quot;) # true!, but ..
console.log(yatta.value.newProperty == &quot;Awesome&quot;) # false, you are only allowed to set properties!
# The solution
yatta.value = {newProperty : &quot;Awesome&quot;}
console.log(w.newProperty == &quot;Awesome&quot;) # true!</code></pre>
</div>
</div>
<div class='tags'>
<h3>See also:</h3>
<ul class='see'>
<li>
<a href='../class/JsonType.html'>JsonType</a>
</li>
<li>
<a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty'>https:&#47;&#47;developer.mozilla.org&#47;en-US&#47;docs&#47;Web&#47;JavaScript&#47;Reference&#47;Global_Objects&#47;Object&#47;defineProperty</a>
</li>
</ul>
</div>
<h2>Constructor Details</h2>
<div class='methods'>
<div class='method_details'>
<p class='signature' id='constructor-dynamic'>
#
(void)
<b>constructor</b><span>(jsonType)</span>
<br>
</p>
</div>
</div>
</div>
<div id='footer'>
August 05, 14 16:58:39 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>
2.0.9
&#10034;
Press H to see the keyboard shortcuts
&#10034;
<a href='http://twitter.com/netzpirat' target='_parent'>@netzpirat</a>
&#10034;
<a href='http://twitter.com/_inossidabile' target='_parent'>@_inossidabile</a>
</div>
<iframe id='search_frame'></iframe>
<div id='fuzzySearch'>
<input type='text'>
<ol></ol>
</div>
<div id='help'>
<p>
Quickly fuzzy find classes, mixins, methods, file:
</p>
<ul>
<li>
<span>T</span>
Open fuzzy finder dialog
</li>
</ul>
<p>
Control the navigation frame:
</p>
<ul>
<li>
<span>L</span>
Toggle list view
</li>
<li>
<span>C</span>
Show class list
</li>
<li>
<span>I</span>
Show mixin list
</li>
<li>
<span>F</span>
Show file list
</li>
<li>
<span>M</span>
Show method list
</li>
<li>
<span>E</span>
Show extras list
</li>
</ul>
<p>
You can focus and blur the search input:
</p>
<ul>
<li>
<span>S</span>
Focus search input
</li>
<li>
<span>Esc</span>
Blur search input
</li>
</ul>
</div>
</body>
</html>