Issue #5, handle null in json

This commit is contained in:
Kevin Jahns 2014-08-26 03:05:43 +02:00
parent f444b25ac9
commit b03f477a3f
34 changed files with 85 additions and 69 deletions

View File

@ -5,7 +5,7 @@
"authors": [
"Kevin Jahns <kevin.jahns@rwth-aachen.de>"
],
"description": "A Framework that enables Real-Time Collaboration on arbitrary data structures.",
"description": "A Framework that enables Real-Time collaboration on arbitrary data structures.",
"main": "./build/**",
"keywords": [
"OT",

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -84,7 +84,9 @@
json = {};
for (name in val) {
o = val[name];
if (o.constructor === {}.constructor) {
if (o === null) {
json[name] = o;
} else if (o.constructor === {}.constructor) {
json[name] = this.val(name).toJson();
} else if (o instanceof types.Operation) {
while (o instanceof types.Operation) {
@ -131,7 +133,7 @@
this.val(o_name, o, content);
}
return this;
} else if ((name != null) && (content != null)) {
} else if ((name != null) && ((content != null) || content === null)) {
if (mutable != null) {
if (mutable === true || mutable === 'mutable') {
mutable = true;
@ -143,7 +145,7 @@
}
if (typeof content === 'function') {
return this;
} else if (((!mutable) || typeof content === 'number') && content.constructor !== Object) {
} else if (content === null || (((!mutable) || typeof content === 'number') && content.constructor !== Object)) {
obj = HB.addOperation(new types.ImmutableObject(void 0, content)).execute();
return JsonType.__super__.val.call(this, name, obj);
} else {

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
{"version":3,"sources":["Types/XmlTypes.coffee"],"names":[],"mappings":"AAoGwC;AAAA;AAAA","file":"Types/XmlTypes.js","sourceRoot":"/source/","sourcesContent":[""]}
{"version":3,"sources":["Types/XmlTypes.coffee"],"names":[],"mappings":"AAyGwC;AAAA;AAAA","file":"Types/XmlTypes.js","sourceRoot":"/source/","sourcesContent":[""]}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -248,7 +248,7 @@
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -302,7 +302,7 @@ data from the received intent.</p>
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -335,7 +335,7 @@ JsonFramework was initialized (Depending on the HistoryBuffer implementation).</
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -426,7 +426,7 @@ if (x.type === &quot;JsonType&quot;) {
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -139,7 +139,7 @@ console.log(w.newProperty == &quot;Awesome&quot;) # true!</code></pre>
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -222,7 +222,7 @@ on how to do that with urls.</p>
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -356,7 +356,7 @@ JsonFramework was initialized (Depending on the HistoryBuffer implementation).</
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -375,7 +375,7 @@ yatta.bind(textbox);</code></pre>
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -38,7 +38,7 @@
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -70,7 +70,7 @@ But I would become really motivated if you gave me some feedback :) (<a href="ht
<li>Garbage Collection</li>
<li>XML support</li>
</ul>
<h2 id="support">Support</h2><p>Please report any issues to the <a href="https://github.com/DadaMonad/Yatta/issues">Github issue page</a>!</p><h2 id="license">License</h2><p>Yatta! is licensed under the <a href="./LICENSE.txt">MIT License</a>.</p><a href="&#109;&#x61;&#105;&#108;&#116;&#111;&#x3a;&#x6b;&#101;&#118;&#x69;&#110;&#x2e;&#106;&#97;&#104;&#110;&#115;&#64;&#x72;&#x77;&#116;&#104;&#x2d;&#x61;&#97;&#99;&#x68;&#x65;&#x6e;&#46;&#100;&#101;">&#x6b;&#101;&#118;&#x69;&#110;&#x2e;&#106;&#97;&#104;&#110;&#115;&#64;&#x72;&#x77;&#116;&#104;&#x2d;&#x61;&#97;&#99;&#x68;&#x65;&#x6e;&#46;&#100;&#101;</a>
<h2 id="support">Support</h2><p>Please report any issues to the <a href="https://github.com/DadaMonad/Yatta/issues">Github issue page</a>!</p><h2 id="license">License</h2><p>Yatta! is licensed under the <a href="./LICENSE.txt">MIT License</a>.</p><a href="&#x6d;&#x61;&#x69;&#108;&#x74;&#111;&#58;&#107;&#x65;&#118;&#105;&#110;&#x2e;&#106;&#x61;&#104;&#x6e;&#115;&#x40;&#114;&#x77;&#116;&#104;&#x2d;&#x61;&#x61;&#x63;&#x68;&#x65;&#x6e;&#46;&#x64;&#x65;">&#107;&#x65;&#118;&#105;&#110;&#x2e;&#106;&#x61;&#104;&#x6e;&#115;&#x40;&#114;&#x77;&#116;&#104;&#x2d;&#x61;&#x61;&#x63;&#x68;&#x65;&#x6e;&#46;&#x64;&#x65;</a>
@ -79,7 +79,7 @@ But I would become really motivated if you gave me some feedback :) (<a href="ht
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -100,7 +100,7 @@
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -158,7 +158,7 @@
</div>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -48,7 +48,7 @@
</dl>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -60,7 +60,7 @@
</dl>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -60,7 +60,7 @@
</dl>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -48,7 +48,7 @@
</dl>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -39,7 +39,7 @@
</table>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -37,7 +37,7 @@
</table>
</div>
<div id='footer'>
August 24, 14 01:51:08 by
August 26, 14 03:04:10 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -1,6 +1,6 @@
## PeerJs + JSON Tutorial
## PeerJs + JSON Example
Here, I will give a short overview on how to enable collaborative json with the
[PeerJs](http://peerjs.com/) Connector and the JsonYatta Framework. Open
[PeerJs](http://peerjs.com/) Connector and the Json Framework. Open
[index.html](http://dadamonad.github.io/Yatta/examples/PeerJs-Json/index.html) in your Browser and
use the console to explore Yatta!
@ -29,11 +29,9 @@ Y.createPeerJsConnector({key: 'h7nlefbgavh1tt9'}, function(Connector, user_id){
You can also specify your own user_id with peerjs.
But you have to make sure that no other client associated to your API-key has the same user_id.
```js
// Y.createPeerJsConnector("unique_id", {key: 'h7nlefbgavh1tt9'}, function(Connector, user_id){
But then you have to make sure that no other client associated to your API-key has the same user_id.
```
Y.createPeerJsConnector("unique_id", {key: 'h7nlefbgavh1tt9'}, function(Connector, user_id){
```
@ -57,7 +55,7 @@ on how to do that with urls.
```js
console.log("This is your user-id: "+user_id);
console.log("Copy your user-id: " + user_id);
// yatta.connector.connectToPeer(peer_user_id);
```
@ -93,13 +91,13 @@ A string property can be either mutable or immutable.
```
Did you recognize that we have to use anoter `.val()` for mutable strings?
Thats because yatta.val('mutable_string') is of type WordType.
Since we implemented `toString` in this for WordType's, you can use it like a string:
Did you recognize that we use anoter `.val()` for mutable strings?
Thats because `yatta.val('mutable_string')` is of type *WordType*.
Since WordType implements `toString`, you can use it like a string:
```js
console.log(""+yatta.val("mutable_string") === "eXXXxt") // true, concatenating it with a string will implicitly invoke toString()
console.log("" + yatta.val("mutable_string") === "eXXXxt") // true, concatenating it with a string will implicitly invoke toString()
```
@ -117,7 +115,7 @@ Initially the default is 'mutable'. You can set it like this:
```
yatta is chainable:
Yatta is [chainable](http://schier.co/post/method-chaining-in-javascript):
```js
@ -140,13 +138,14 @@ Lists are always immutable.
```js
yatta.val('list', [1,2,3]);
console.log(yatta.val('list')[2] === 3); // true
yatta.val('list', [0,1,2]);
console.log(yatta.val('list')[2] === 2); // true
```
### Check Types
Certainly you want to check types!
You get the type of an YattaType with the `.type` property.
Here, we create a function that parses a Yatta type to a string.
@ -224,7 +223,7 @@ Apply 'insert' and 'delete' - listeners to Words.
### Experimental method
But there is a much more convenient way!
Nah.. this is only for the cool kids.
```js
@ -236,6 +235,10 @@ But there is a much more convenient way!
```
How did I do that? ^^
In Javascript it is possible set setter- and getter- for properties. This is
why this method feels much more natural.
The downside is that you are only allowed to overwrite existing properties.
@ -254,7 +257,7 @@ So, how do we create new properties?
```
This is stupid! I need to create new properties!
This is stupid! I don'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:
@ -292,7 +295,8 @@ Yatta can't observe if you overwrite object references `yatta = "Awesome"`.
```
Please also read [JsonWrapper](https://rawgit.com/DadaMonad/Yatta/master/doc/class/JsonWrapper.html)
Please also read [JsonWrapper](https://rawgit.com/DadaMonad/Yatta/master/doc/class/JsonWrapper.html).
I really want to hear what you think about this method :)
```js

View File

@ -131,7 +131,9 @@ module.exports = (HB)->
val = @val()
json = {}
for name, o of val
if o.constructor is {}.constructor
if o is null
json[name] = o
else if o.constructor is {}.constructor
json[name] = @val(name).toJson()
else if o instanceof types.Operation
while o instanceof types.Operation
@ -197,7 +199,7 @@ module.exports = (HB)->
for o_name,o of name
@val(o_name,o,content)
@
else if name? and content?
else if name? and (content? or content is null)
if mutable?
if mutable is true or mutable is 'mutable'
mutable = true
@ -207,7 +209,7 @@ module.exports = (HB)->
mutable = @mutable_default
if typeof content is 'function'
@ # Just do nothing
else if ((not mutable) or typeof content is 'number') and content.constructor isnt Object
else if content is null or (((not mutable) or typeof content is 'number') and content.constructor isnt Object)
obj = HB.addOperation(new types.ImmutableObject undefined, content).execute()
super name, obj
else

View File

@ -121,8 +121,6 @@ describe "JsonFramework", ->
u2.engine.applyOps ops1
expect(u2.value.name.val()).to.equal(u2.value.name.val())
it "can handle creaton of complex json", ->
@yTest.getSomeUser().val('x', {'a':'b'})
@yTest.getSomeUser().val('a', {'a':{q:"dtrndtrtdrntdrnrtdnrtdnrtdnrtdnrdnrdt"}})
@ -135,14 +133,16 @@ describe "JsonFramework", ->
expect(@yTest.getSomeUser().value.a.a.q.val()).to.equal("AAAdtrndtrtdrntdrnrtdnrtdnrtdnrtdnrdnrdt")
it "handles some immutable tests", ->
it "handles immutables and primitive data types", ->
@yTest.getSomeUser().val('string', "text", "immutable")
@yTest.getSomeUser().val('number', 4, "immutable")
@yTest.getSomeUser().val('object', {q:"rr"}, "immutable")
@yTest.getSomeUser().val('null', null)
@yTest.compareAll()
expect(@yTest.getSomeUser().val('string')).to.equal "text"
expect(@yTest.getSomeUser().val('number')).to.equal 4
expect(@yTest.getSomeUser().val('object').val('q')).to.equal "rr"
expect(@yTest.getSomeUser().val('null') is null).to.be.ok
it "converges t1", ->
op0 = {"type":"Delimiter","uid":{"creator":0,"op_number":0},"next":{"creator":0,"op_number":1}}