more examples

This commit is contained in:
Kevin Jahns 2014-08-19 21:51:23 +02:00
parent 71c01fbb9e
commit 9d871adb00
9 changed files with 49 additions and 41 deletions

View File

@ -18,12 +18,44 @@ function init(){
``` ```
You don't have to use the proposed user_id. yatta is the shared json object. If you change something on this object,
it will be instantly shared with all the other collaborators.
```js ```js
console.log("me is number 2") yatta = new Y.JsonYatta(user_id, Connector);
yatta = new Y.JsonYatta(2, Connector); ```
Add a integer-property like this
```js
yatta.val('x', 7);
```
Get the value of property x like this
```js
console.log(yatta.val('x') === 7); // true
```
A string property can be either mutable or immutable.
```js
yatta.val('mutable_string', "text", "mutable");
yatta.val('immutable_string', "text", "immutable");
console.log(yatta.val('immutable_string') === "text"); // true
yatta.val('mutable_string').insertText(2,"XXX"); // position, string
yatta.val('mutable_string').deleteText(0,1); // position, deletion length
console.log(yatta.val('mutable_string').val() === "eXXXxt"); // true
}) })
} }

View File

@ -21,6 +21,16 @@ function init(){
*/ */
yatta = new Y.JsonYatta(user_id, Connector); yatta = new Y.JsonYatta(user_id, Connector);
/**
You may want to get the created DUI client (you must not create two DUI/IWC clients!!),
or set an IwcHandler.
*/
var duiclient = yatta.getConnector().duiclient;
function iwcHandler (intent) {
console.log("Received intent: "+JSON.stringify(intent));
}
yatta.getConnector().setIwcHandler(iwcHandler);
/** /**
Add a integer-property like this Add a integer-property like this
*/ */
@ -42,8 +52,6 @@ function init(){
yatta.val('mutable_string').deleteText(0,1); // position, deletion length yatta.val('mutable_string').deleteText(0,1); // position, deletion length
console.log(yatta.val('mutable_string').val() === "eXXXxt"); // true console.log(yatta.val('mutable_string').val() === "eXXXxt"); // true
}) })
} }
window.onload = init window.onload = init

View File

@ -18,44 +18,12 @@ function init(){
``` ```
yatta is the shared json object. If you change something on this object, You don't have to use the proposed user_id.
it will be instantly shared with all the other collaborators.
```js ```js
yatta = new Y.JsonYatta(user_id, Connector); console.log("me is number 2")
``` yatta = new Y.JsonYatta(2, Connector);
Add a integer-property like this
```js
yatta.val('x', 7);
```
Get the value of property x like this
```js
console.log(yatta.val('x') === 7); // true
```
A string property can be either mutable or immutable.
```js
yatta.val('mutable_string', "text", "mutable");
yatta.val('immutable_string', "text", "immutable");
console.log(yatta.val('immutable_string') === "text"); // true
yatta.val('mutable_string').insertText(2,"XXX"); // position, string
yatta.val('mutable_string').deleteText(0,1); // position, deletion length
console.log(yatta.val('mutable_string').val() === "eXXXxt"); // true
}) })
} }

View File

@ -11,7 +11,7 @@
<body> <body>
<h1> Text Editing Demo</h1> <h1> Text Editing Demo</h1>
<p> Collaborative text editing with <a href="https://github.com/DadaMonad/Yatta/">Yatta</a> <p> Collaborative text editing with <a href="https://github.com/DadaMonad/Yatta/">Yatta</a>
and <a href="http://peerjs.com/">PeerJs</a> (WebRTC). Open this link in other browsers: <a id="peer_link" target="_blank">Drop me </a> </p> and <a href="http://peerjs.com/">PeerJs</a> (WebRTC). </p>
<p> <a href="https://github.com/DadaMonad/Yatta/">Yatta</a> is a Framework for Real-Time collaboration on arbitrary data structures. <p> <a href="https://github.com/DadaMonad/Yatta/">Yatta</a> is a Framework for Real-Time collaboration on arbitrary data structures.