Issue #6: Events carry creator information

This commit is contained in:
Kevin Jahns 2014-09-17 18:13:05 +02:00
parent 68c17f1876
commit b750d95b98
41 changed files with 219 additions and 187 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,6 +11,7 @@
function Operation(uid) {
this.is_deleted = false;
this.doSync = true;
this.garbage_collected = false;
if (uid != null) {
this.doSync = !isNaN(parseInt(uid.op_number));
} else {
@ -85,9 +86,10 @@
if (garbagecollect == null) {
garbagecollect = true;
}
if (!this.isDeleted()) {
if (!this.garbage_collected) {
this.is_deleted = true;
if (garbagecollect) {
this.garbage_collected = true;
return HB.addToGarbageCollector(this);
}
}
@ -220,7 +222,7 @@
this.deleted_by = [];
}
if ((this.parent != null) && !this.isDeleted()) {
this.parent.callEvent("delete", this);
this.parent.callEvent("delete", this, o);
}
if (o != null) {
this.deleted_by.push(o);
@ -228,10 +230,11 @@
garbagecollect = false;
if (this.prev_cl.isDeleted()) {
garbagecollect = true;
} else if (this.next_cl.isDeleted()) {
this.next_cl.applyDelete();
}
return Insert.__super__.applyDelete.call(this, garbagecollect);
Insert.__super__.applyDelete.call(this, garbagecollect);
if (this.next_cl.isDeleted()) {
return this.next_cl.applyDelete();
}
};
Insert.prototype.cleanup = function() {

File diff suppressed because one or more lines are too long

View File

@ -242,27 +242,24 @@
};
ReplaceManager.prototype.setParent = function(parent, property_name) {
var addPropertyListener;
this.on('insert', (function(_this) {
return function(event, op) {
if (op.next_cl instanceof types.Delimiter) {
return _this.parent.callEvent('change', property_name);
}
};
})(this));
this.on('change', (function(_this) {
return function(event) {
return _this.parent.callEvent('change', property_name);
};
})(this));
addPropertyListener = (function(_this) {
return function(event, op) {
if (op.next_cl instanceof types.Delimiter && op.prev_cl instanceof types.Delimiter) {
_this.parent.callEvent('addProperty', property_name);
}
return _this.deleteListener('addProperty', addPropertyListener);
};
})(this);
var addPropertyListener, repl_manager;
repl_manager = this;
this.on('insert', function(event, op) {
if (op.next_cl instanceof types.Delimiter) {
return repl_manager.parent.callEvent('change', property_name, op);
}
});
this.on('change', function(event, op) {
if (repl_manager !== this) {
return repl_manager.parent.callEvent('change', property_name, op);
}
});
addPropertyListener = function(event, op) {
if (op.next_cl instanceof types.Delimiter && op.prev_cl instanceof types.Delimiter) {
repl_manager.parent.callEvent('addProperty', property_name, op);
}
return repl_manager.deleteListener('addProperty', addPropertyListener);
};
this.on('insert', addPropertyListener);
return ReplaceManager.__super__.setParent.call(this, parent);
};

File diff suppressed because one or more lines are too long

View File

@ -174,10 +174,16 @@
WordType.prototype.setReplaceManager = function(op) {
this.saveOperation('replace_manager', op);
this.validateSavedOperations();
return this.on(['insert', 'delete'], (function(_this) {
return function() {
this.on('insert', (function(_this) {
return function(event, ins) {
var _ref;
return (_ref = _this.replace_manager) != null ? _ref.callEvent('change') : void 0;
return (_ref = _this.replace_manager) != null ? _ref.forwardEvent(_this, 'change', ins) : void 0;
};
})(this));
return this.on('delete', (function(_this) {
return function(event, ins, del) {
var _ref;
return (_ref = _this.replace_manager) != null ? _ref.forwardEvent(_this, 'change', del) : void 0;
};
})(this));
};

File diff suppressed because one or more lines are too long

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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -466,7 +466,7 @@ if (x.type === &quot;JsonType&quot;) {
</div>
</div>
<div id='footer'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -415,7 +415,7 @@ yatta.bind(textbox);</code></pre>
</div>
</div>
<div id='footer'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -66,11 +66,11 @@ on which the operation was created. This is not necessary in Yata.</p><p>The dow
In contrast, an OT algorithm can have an empty History Buffer while the document size is very big.</p><p>Eventually (after my thesis), I will publish more information about Yata.</p><p>So, how did I come up with the name for the implementation (Yatta! is not Yata)?
Yatta! means &quot;I did it!&quot; in Japanese. You scream it when you accomplish something (for proper application I refer to the Yatta-man in <a href="http://heroeswiki.com/Yatta!">Heroes</a>).
There is also this awesome video on the Internet that will change your life <a href="https://www.youtube.com/watch?v=kL5DDSglM_s">Yatta</a>.</p><h2 id="status">Status</h2><p>Yatta! is still in an early development phase. Don&#39;t expect that everything is working fine.
But I would become really motivated if you gave me some feedback :) (<a href="https://github.com/DadaMonad/Yatta/issues">github</a>).</p><h3 id="current-issues">Current Issues</h3><p>Currently, I don&#39;t perform Garbage Collection. Therefore, the space requirement will never decrease.</p><ul>
<li>Garbage Collection</li>
But I would become really motivated if you gave me some feedback :) (<a href="https://github.com/DadaMonad/Yatta/issues">github</a>).</p><h3 id="current-issues">Current Issues</h3>
<ul>
<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;&#97;&#105;&#x6c;&#116;&#x6f;&#58;&#x6b;&#x65;&#118;&#105;&#110;&#x2e;&#x6a;&#97;&#104;&#x6e;&#115;&#64;&#x72;&#x77;&#116;&#104;&#45;&#x61;&#x61;&#99;&#x68;&#101;&#110;&#x2e;&#x64;&#x65;">&#x6b;&#x65;&#118;&#105;&#110;&#x2e;&#x6a;&#97;&#104;&#x6e;&#115;&#64;&#x72;&#x77;&#116;&#104;&#45;&#x61;&#x61;&#99;&#x68;&#101;&#110;&#x2e;&#x64;&#x65;</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;&#97;&#x69;&#108;&#116;&#x6f;&#58;&#x6b;&#x65;&#118;&#x69;&#110;&#46;&#106;&#x61;&#104;&#110;&#x73;&#64;&#114;&#119;&#116;&#x68;&#45;&#x61;&#97;&#x63;&#x68;&#x65;&#x6e;&#46;&#x64;&#x65;">&#x6b;&#x65;&#118;&#x69;&#110;&#46;&#106;&#x61;&#104;&#110;&#x73;&#64;&#114;&#119;&#116;&#x68;&#45;&#x61;&#97;&#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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 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'>
September 17, 14 16:00:52 by
September 17, 14 18:11:46 by
<a href='https://github.com/coffeedoc/codo' title='CoffeeScript API documentation generator'>
Codo
</a>

View File

@ -170,8 +170,9 @@ Apply a 'addProperty' - listener to a JsonType.
```js
function addProperty(event_name, property_name){
console.log("Property '" + property_name + "' was created!");
function addProperty(event_name, property_name, op){
// op is the operation that changed the objects value. In addProperty it is most likely to be a 'Replaceable' (see doc).
console.log("Property '" + property_name + "' was created by '"+op.creator+"'!");
console.log("Value: " + show(this.val(property_name))); // 'this' is the object on which the property was created.
};
yatta.on('addProperty', addProperty);
@ -183,8 +184,13 @@ Apply a 'change' - listener to a JsonType.
```js
function change(event_name, property_name){
console.log("Value of property '" + property_name + "' changed!");
function change(event_name, property_name, op){
// Check who made this property change!
if(op.creator == yatta.getUserId()){
console.log("You changed the value of property '" + property_name + "'!");
}else{
console.log("User '"+op.creator+"' changed the value of property '" + property_name + "'!");
}
console.log("New value: " + show(this.val(property_name)) + ""); // 'this' is the object on which the property changed.
};
yatta.on('change', change);

View File

@ -40,7 +40,7 @@ Y.createPeerJsConnector("unique_id", {key: 'h7nlefbgavh1tt9'}, function(Connecto
it will be instantly shared with all the other collaborators.
*/
yatta = new Y.JsonFramework(user_id, Connector);
/**
Next, you may want to connect to another peer. Therefore you have to receive his
user_id. If the other peer is connected to other peers, the PeerJsConnector
@ -135,8 +135,9 @@ Y.createPeerJsConnector("unique_id", {key: 'h7nlefbgavh1tt9'}, function(Connecto
### Add listeners
Apply a 'addProperty' - listener to a JsonType.
*/
function addProperty(event_name, property_name){
console.log("Property '" + property_name + "' was created!");
function addProperty(event_name, property_name, op){
// op is the operation that changed the objects value. In addProperty it is most likely to be a 'Replaceable' (see doc).
console.log("Property '" + property_name + "' was created by '"+op.creator+"'!");
console.log("Value: " + show(this.val(property_name))); // 'this' is the object on which the property was created.
};
yatta.on('addProperty', addProperty);
@ -145,8 +146,13 @@ Y.createPeerJsConnector("unique_id", {key: 'h7nlefbgavh1tt9'}, function(Connecto
/**
Apply a 'change' - listener to a JsonType.
*/
function change(event_name, property_name){
console.log("Value of property '" + property_name + "' changed!");
function change(event_name, property_name, op){
// Check who made this property change!
if(op.creator == yatta.getUserId()){
console.log("You changed the value of property '" + property_name + "'!");
}else{
console.log("User '"+op.creator+"' changed the value of property '" + property_name + "'!");
}
console.log("New value: " + show(this.val(property_name)) + ""); // 'this' is the object on which the property changed.
};
yatta.on('change', change);

View File

@ -272,7 +272,7 @@ module.exports = (HB)->
@deleted_by ?= []
if @parent? and not @isDeleted()
# call iff wasn't deleted earlyer
@parent.callEvent "delete", @
@parent.callEvent "delete", @, o
if o?
@deleted_by.push o
garbagecollect = false

View File

@ -248,16 +248,18 @@ module.exports = (HB)->
# Add change listeners for parent.
#
setParent: (parent, property_name)->
@on 'insert', (event, op)=>
repl_manager = this
@on 'insert', (event, op)->
if op.next_cl instanceof types.Delimiter
@parent.callEvent 'change', property_name
@on 'change', (event)=>
@parent.callEvent 'change', property_name
repl_manager.parent.callEvent 'change', property_name, op
@on 'change', (event, op)->
if repl_manager isnt this
repl_manager.parent.callEvent 'change', property_name, op
# Call this, when the first element is inserted. Then delete the listener.
addPropertyListener = (event, op)=>
addPropertyListener = (event, op)->
if op.next_cl instanceof types.Delimiter and op.prev_cl instanceof types.Delimiter
@parent.callEvent 'addProperty', property_name
@deleteListener 'addProperty', addPropertyListener
repl_manager.parent.callEvent 'addProperty', property_name, op
repl_manager.deleteListener 'addProperty', addPropertyListener
@on 'insert', addPropertyListener
super parent

View File

@ -196,9 +196,10 @@ module.exports = (HB)->
setReplaceManager: (op)->
@saveOperation 'replace_manager', op
@validateSavedOperations()
@on ['insert', 'delete'], ()=>
@replace_manager?.callEvent 'change'
@on 'insert', (event, ins)=>
@replace_manager?.forwardEvent @, 'change', ins
@on 'delete', (event, ins, del)=>
@replace_manager?.forwardEvent @, 'change', del
#
# Bind this WordType to a textfield or input field.
#

View File

@ -1,6 +1,6 @@
{
"name": "yatta",
"version": "0.0.5",
"version": "0.1.0",
"description": "A Framework that enables Real-Time Collaboration on arbitrary data structures.",
"main": "./build/node/index",
"directories": {