yjs/doc/extra/examples/IwcJson.md.html
2014-08-05 17:04:39 +02:00

176 lines
7.7 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'>examples</span>
&raquo;
<span class='title'>IwcJson.md</span>
</div>
</div>
<div id='content'>
<nav class='toc'>
<p class='title'>
<a class='hide_toc' href='#'>
<strong>Table of Contents</strong>
</a>
<small>
(<a class='float_toc' href='#'>left</a>)
</small>
</p>
</nav>
<div id='filecontents'>
<h2 id="iwc-json-example">IWC + JSON Example</h2><p>Here, I will give a short overview on how to use the IwcJson Framework in Role-SDK widgets.
First you have to include the following libraries in your widget file:</p><pre><code>&lt;script src=&quot;http://open-app.googlecode.com/files/openapp.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;http://dbis.rwth-aachen.de/gadgets/iwc/lib/iwc.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;http://dbis.rwth-aachen.de/~jahns/role-widgets/widgetbundles/libraries/DUIClient.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;../dest/browser/Frameworks/JsonIwcYatta.min.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;./IwcJson.js&quot;&gt;&lt;/script&gt;
</code></pre><pre><code class="lang-js">function init(){
createConnector(function(Connector, user_id){
</code></pre><p>yatta is the shared json object</p><pre><code class="lang-js"> yatta = new JsonYatta(user_id, Connector);
</code></pre><p>Add a integer-property like this</p><pre><code class="lang-js"> yatta.val(&#39;x&#39;, 7);
</code></pre><p>Get the value of property x like this</p><pre><code class="lang-js"> console.log(yatta.val(&#39;x&#39;) === 7); // true
</code></pre><p>A string property can be either mutable or immutable.</p><pre><code class="lang-js"> yatta.val(&#39;mutable_string&#39;, &quot;text&quot;, &quot;mutable&quot;);
yatta.val(&#39;immutable_string&#39;, &quot;text&quot;, &quot;immutable&quot;);
console.log(yatta.val(&#39;immutable_string&#39;) === &quot;text&quot;); // true
yatta.val(&#39;mutable_string&#39;).insertText(2,&quot;XXX&quot;); // position, string
yatta.val(&#39;mutable_string&#39;).deleteText(0,1); // position, deletion length
console.log(yatta.val(&#39;mutable_string&#39;).val() === &quot;eXXXxt&quot;); // true
</code></pre><p>You can omit the mutable - parameter. In that case the default will be used.
Initially the default is &#39;mutable&#39;. You can set it like this:</p><pre><code class="lang-js"> yatta.setMutableDefault(&#39;mutable&#39;);
// or
yatta.setMutableDefault(&#39;immutable&#39;);
yatta.val(&#39;new_string&#39;, &quot;string&quot;);
console.log(yatta.val(&#39;new_string&#39;) === &quot;string&quot;); // true
</code></pre><p>yatta is chainable:</p><pre><code class="lang-js"> yatta.val(&#39;a&#39;, 4).val(&#39;b&#39;,5);
console.log(yatta.val(&#39;a&#39;) === 4); // true
console.log(yatta.val(&#39;b&#39;) === 5); // true
</code></pre><p>You can alse set objects.</p><pre><code class="lang-js"> yatta.val(&#39;object&#39;, {a : {b : &quot;b&quot;}, c : { d : 5 }});
console.log(yatta.val(&#39;object&#39;).val(&#39;c&#39;).val(&#39;d&#39;) === 5); // true
</code></pre><p>Lists are always immutable.</p><pre><code class="lang-js"> yatta.val(&#39;list&#39;, [1,2,3]);
console.log(yatta.val(&#39;list&#39;)[2] === 3); // true
</code></pre><p>But there is a much more convenient way!</p><pre><code class="lang-js"> console.log(yatta.value.list[2] === 3) // true
yatta.value.list = [3,4,5]
console.log(yatta.val(&#39;list&#39;)[2] === 5) // true
yatta.value.object = {c : 4}
console.log(yatta.value.object.c === 4) // true
</code></pre><p>The downside is that you are only allowed to overwrite existing properties.</p><pre><code class="lang-js"> yatta.value.newProperty = &quot;Awesome&quot;
console.log(yatta.value.newProperty !== &quot;Awesome&quot;) // true, yatta.value.newProperty is undefined.
</code></pre><p>So, how do we create new properties?</p><pre><code class="lang-js"> yatta.value = {newProperty : &quot;Awesome&quot;}
console.log(yatta.value.newProperty === &quot;Awesome&quot;) // true, it&#39;s awesome ;)
</code></pre><p>This is stupid! I don&#39;t want to overwrite all my existing properties!
Very well.. The solution is that we merge yatta.value with the new assignment.
For example: assuming we want to overwrite yatta.value with some object o.
Then these two rules apply:</p><ul>
<li>The result has all properties of o</li>
<li>The result has all properties of yatta.value if they don&#39;t occur under the same property-name in o</li>
</ul>
<pre><code class="lang-js"> yatta.value = {newProperty : {Awesome : true }}
console.log(yatta.value.list[2] === 5) // true, old value list still exists.
console.log(yatta.value.newProperty.Awesome === true) // true, newProperty is overwritten.
</code></pre><p>Consider this case.</p><pre><code class="lang-js"> yatta.value = {newProperty : { x : 4} }
console.log(yatta.value.newProperty.Awesome == null) // true, newProperty was replaced, therefore it is now undefined
</code></pre><p>Did you notice that you always set immutable objects if you set properties like this?
Even if the default is &#39;mutable&#39;. If you want to work with mutable objects you have to work with .val().</p><p>One last thing. You are only allowed to set properties like this <code>yatta.value = o</code>.
Yatta can&#39;t observe if you overwrite object references <code>yatta = &quot;Awesome&quot;</code>.</p><pre><code class="lang-js"> w = yatta.value.newProperty
w = &quot;Awesome&quot;
console.log(yatta.value.newProperty !== &quot;Awesome&quot;) // true, still not awesome..
</code></pre><p>Please also read <a href="https://rawgit.com/DadaMonad/Yatta/master/doc/class/JsonWrapper.html">JsonWrapper</a></p><pre><code class="lang-js"> })
}
window.onload = init
</code></pre>
</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>