Issue #5, handle null in json
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user