Initial Commit -> Text collaboration works
This commit is contained in:
1
dest/browser/Yatta.js
Normal file
1
dest/browser/Yatta.js
Normal file
@@ -0,0 +1 @@
|
||||
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({},{},[])
|
||||
17
dest/browser/Yatta_test.html
Normal file
17
dest/browser/Yatta_test.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test GOTOjs</title>
|
||||
<link rel="stylesheet" href="../../node_modules/mocha/mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="../../node_modules/mocha/mocha.js"></script>
|
||||
<script>mocha.setup('bdd')</script>
|
||||
<script src="Yatta_test.js"></script>
|
||||
<script>
|
||||
mocha.checkLeaks();
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
13099
dest/browser/Yatta_test.js
Normal file
13099
dest/browser/Yatta_test.js
Normal file
File diff suppressed because one or more lines are too long
94
dest/lib/lib/Connectors/TestConnector.js
Normal file
94
dest/lib/lib/Connectors/TestConnector.js
Normal file
@@ -0,0 +1,94 @@
|
||||
var _;
|
||||
|
||||
_ = require("underscore");
|
||||
|
||||
module.exports = function(user_list) {
|
||||
var TestConnector;
|
||||
return TestConnector = (function() {
|
||||
function TestConnector(engine, HB, execution_listener) {
|
||||
var appliedOperationsListener, send_;
|
||||
this.engine = engine;
|
||||
this.HB = HB;
|
||||
this.execution_listener = execution_listener;
|
||||
send_ = (function(_this) {
|
||||
return function(o) {
|
||||
return _this.send(o);
|
||||
};
|
||||
})(this);
|
||||
this.execution_listener.push(send_);
|
||||
if (!((user_list != null ? user_list.length : void 0) === 0)) {
|
||||
this.engine.applyOps(user_list[0].getHistoryBuffer().toJson());
|
||||
}
|
||||
this.unexecuted = {};
|
||||
this.applied_operations = [];
|
||||
appliedOperationsListener = (function(_this) {
|
||||
return function(o) {
|
||||
return _this.applied_operations.push(o);
|
||||
};
|
||||
})(this);
|
||||
this.execution_listener.push(appliedOperationsListener);
|
||||
}
|
||||
|
||||
TestConnector.prototype.getOpsInExecutionOrder = function() {
|
||||
return this.applied_operations;
|
||||
};
|
||||
|
||||
TestConnector.prototype.getRootElement = function() {
|
||||
if (user_list.length > 0) {
|
||||
return user_list[0].getRootElement();
|
||||
}
|
||||
};
|
||||
|
||||
TestConnector.prototype.send = function(o) {
|
||||
var user, _i, _len, _results;
|
||||
if (o.creator === this.HB.getUserId()) {
|
||||
_results = [];
|
||||
for (_i = 0, _len = user_list.length; _i < _len; _i++) {
|
||||
user = user_list[_i];
|
||||
if (!user.getUserId() === this.HB.getUserId()) {
|
||||
_results.push(user.getConnector().receive(o));
|
||||
} else {
|
||||
_results.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
};
|
||||
|
||||
TestConnector.prototype.receive = function(o) {
|
||||
var _base, _name;
|
||||
if ((_base = this.unexecuted)[_name = o.creator] == null) {
|
||||
_base[_name] = [];
|
||||
}
|
||||
return this.unexecuted[o.creator].push(o);
|
||||
};
|
||||
|
||||
TestConnector.prototype.flushOne = function(user) {
|
||||
var _ref;
|
||||
if (((_ref = this.unexecuted[user]) != null ? _ref.length : void 0) > 0) {
|
||||
return this.engine.applyOp(this.unexecuted[user].shift());
|
||||
}
|
||||
};
|
||||
|
||||
TestConnector.prototype.flushOneRandom = function() {
|
||||
return this.flushOne(_.random(0, user_list.length - 1));
|
||||
};
|
||||
|
||||
TestConnector.prototype.flushAll = function() {
|
||||
var ops;
|
||||
for (ops in this.unexecuted) {
|
||||
this.engine.applyOps(ops);
|
||||
}
|
||||
return this.unexecuted = {};
|
||||
};
|
||||
|
||||
TestConnector.prototype.sync = function() {
|
||||
throw new Error("Can't use this a.t.m.");
|
||||
};
|
||||
|
||||
return TestConnector;
|
||||
|
||||
})();
|
||||
};
|
||||
|
||||
//# sourceMappingURL=TestConnector.js.map
|
||||
10
dest/lib/lib/Connectors/TestConnector.js.map
Normal file
10
dest/lib/lib/Connectors/TestConnector.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "TestConnector.js",
|
||||
"sourceRoot": "../../../../lib/Connectors/",
|
||||
"sources": [
|
||||
"TestConnector.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AACA,IAAA,CAAA;;AAAA,CAAA,GAAI,OAAA,CAAQ,YAAR,CAAJ,CAAA;;AAAA,MAEM,CAAC,OAAP,GAAiB,SAAC,SAAD,GAAA;AACf,MAAA,aAAA;SAAM;AACS,IAAA,uBAAE,MAAF,EAAW,EAAX,EAAgB,kBAAhB,GAAA;AACX,UAAA,gCAAA;AAAA,MADY,IAAC,CAAA,SAAA,MACb,CAAA;AAAA,MADqB,IAAC,CAAA,KAAA,EACtB,CAAA;AAAA,MAD0B,IAAC,CAAA,qBAAA,kBAC3B,CAAA;AAAA,MAAA,KAAA,GAAQ,CAAA,SAAA,KAAA,GAAA;eAAA,SAAC,CAAD,GAAA;iBACN,KAAC,CAAA,IAAD,CAAM,CAAN,EADM;QAAA,EAAA;MAAA,CAAA,CAAA,CAAA,IAAA,CAAR,CAAA;AAAA,MAEA,IAAC,CAAA,kBAAkB,CAAC,IAApB,CAAyB,KAAzB,CAFA,CAAA;AAIA,MAAA,IAAG,CAAA,sBAAK,SAAS,CAAE,gBAAX,KAAqB,CAAtB,CAAP;AACE,QAAA,IAAC,CAAA,MAAM,CAAC,QAAR,CAAiB,SAAU,CAAA,CAAA,CAAE,CAAC,gBAAb,CAAA,CAA+B,CAAC,MAAhC,CAAA,CAAjB,CAAA,CADF;OAJA;AAAA,MAOA,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A,GAAU,SAAC,IAAD,GAAA;AACR,UAAA,IAAA;AAAA,MAAA,kDAAoB,CAAE,gBAAnB,GAA4B,CAA/B;eACE,IAAC,CAAA,MAAM,CAAC,OAAR,CAAgB,IAAC,CAAA,UAAW,CAAA,IAAA,CAAK,CAAC,KAAlB,CAAA,CAAhB,EADF;OADQ;IAAA,CAhCV,CAAA;;AAAA,4BAoCA,cAAA,GAAgB,SAAA,GAAA;aACd,IAAC,CAAA,QAAD,CAAW,CAAC,CAAC,MAAF,CAAS,CAAT,EAAa,SAAS,CAAC,MAAV,GAAiB,CAA9B,CAAX,EADc;IAAA,CApChB,CAAA;;AAAA,4BAuCA,QAAA,GAAU,SAAA,GAAA;AACR,UAAA,GAAA;AAAA,WAAA,sBAAA,GAAA;AACE,QAAA,IAAC,CAAA,MAAM,CAAC,QAAR,CAAiB,GAAjB,CAAA,CADF;AAAA,OAAA;aAEA,IAAC,CAAA,UAAD,GAAc,GAHN;IAAA,CAvCV,CAAA;;AAAA,4BA4CA,IAAA,GAAM,SAAA,GAAA;AACJ,YAAU,IAAA,KAAA,CAAM,uBAAN,CAAV,CADI;IAAA,CA5CN,CAAA;;yBAAA;;OAFa;AAAA,CAFjB,CAAA"
|
||||
}
|
||||
56
dest/lib/lib/Engine.js
Normal file
56
dest/lib/lib/Engine.js
Normal file
@@ -0,0 +1,56 @@
|
||||
var Engine, _;
|
||||
|
||||
_ = require("underscore");
|
||||
|
||||
Engine = (function() {
|
||||
function Engine(HB, parser) {
|
||||
this.HB = HB;
|
||||
this.parser = parser;
|
||||
this.unprocessed_ops = [];
|
||||
}
|
||||
|
||||
Engine.prototype.parseOperation = function(json) {
|
||||
var typeParser;
|
||||
typeParser = this.parser[json.type];
|
||||
if (typeParser != null) {
|
||||
return typeParser(json);
|
||||
} else {
|
||||
throw new Error("You forgot to specify a parser for type " + json.type + ". The message is " + (JSON.stringify(json)) + ".");
|
||||
}
|
||||
};
|
||||
|
||||
Engine.prototype.applyOps = function(ops) {
|
||||
var o, _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = ops.length; _i < _len; _i++) {
|
||||
o = ops[_i];
|
||||
_results.push(this.applyOp(o));
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Engine.prototype.applyOp = function(op_json) {
|
||||
var o, op, unprocessed, _i, _len, _ref;
|
||||
o = this.parseOperation(o_json);
|
||||
this.HB.addOperation(o);
|
||||
if (!o.execute()) {
|
||||
this.unprocessed_ops.push(o);
|
||||
}
|
||||
unprocessed = [];
|
||||
_ref = this.unprocessed_ops;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
op = _ref[_i];
|
||||
if (!op.execute()) {
|
||||
unprocessed.push(op);
|
||||
}
|
||||
}
|
||||
return this.unprocessed_ops = unprocessed;
|
||||
};
|
||||
|
||||
return Engine;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = Engine;
|
||||
|
||||
//# sourceMappingURL=Engine.js.map
|
||||
10
dest/lib/lib/Engine.js.map
Normal file
10
dest/lib/lib/Engine.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "Engine.js",
|
||||
"sourceRoot": "../../../lib/",
|
||||
"sources": [
|
||||
"Engine.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AAAA,IAAA,SAAA;;AAAA,CAAA,GAAI,OAAA,CAAQ,YAAR,CAAJ,CAAA;;AAAA;AAGe,EAAA,gBAAE,EAAF,EAAO,MAAP,GAAA;AACX,IADY,IAAC,CAAA,KAAA,EACb,CAAA;AAAA,IADiB,IAAC,CAAA,SAAA,MAClB,CAAA;AAAA,IAAA,IAAC,CAAA,eAAD,GAAmB,EAAnB,CADW;EAAA,CAAb;;AAAA,mBAGA,cAAA,GAAgB,SAAC,IAAD,GAAA;AACd,QAAA,UAAA;AAAA,IAAA,UAAA,GAAa,IAAC,CAAA,MAAO,CAAA,IAAI,CAAC,IAAL,CAArB,CAAA;AACA,IAAA,IAAG,kBAAH;aACE,UAAA,CAAW,IAAX,EADF;KAAA,MAAA;AAGE,YAAU,IAAA,KAAA,CAAO,0CAAA,GAAyC,IAAI,CAAC,IAA9C,GAAoD,mBAApD,GAAsE,CAAA,IAAI,CAAC,SAAL,CAAe,IAAf,CAAA,CAAtE,GAA2F,GAAlG,CAAV,CAHF;KAFc;EAAA,CAHhB,CAAA;;AAAA,mBAWA,QAAA,GAAU,SAAC,GAAD,GAAA;AACR,QAAA,qBAAA;AAAA;SAAA,0CAAA;kBAAA;AACE,oBAAA,IAAC,CAAA,OAAD,CAAS,CAAT,EAAA,CADF;AAAA;oBADQ;EAAA,CAXV,CAAA;;AAAA,mBAeA,OAAA,GAAS,SAAC,OAAD,GAAA;AAEP,QAAA,kCAAA;AAAA,IAAA,CAAA,GAAI,IAAC,CAAA,cAAD,CAAgB,MAAhB,CAAJ,CAAA;AAAA,IACA,IAAC,CAAA,EAAE,CAAC,YAAJ,CAAiB,CAAjB,CADA,CAAA;AAEA,IAAA,IAAG,CAAA,CAAK,CAAC,OAAF,CAAA,CAAP;AACE,MAAA,IAAC,CAAA,eAAe,CAAC,IAAjB,CAAsB,CAAtB,CAAA,CADF;KAFA;AAAA,IAIA,WAAA,GAAc,EAJd,CAAA;AAKA;AAAA,SAAA,2CAAA;oBAAA;AACE,MAAA,IAAG,CAAA,EAAM,CAAC,OAAH,CAAA,CAAP;AACE,QAAA,WAAW,CAAC,IAAZ,CAAiB,EAAjB,CAAA,CADF;OADF;AAAA,KALA;WAQA,IAAC,CAAA,eAAD,GAAmB,YAVZ;EAAA,CAfT,CAAA;;gBAAA;;IAHF,CAAA;;AAAA,MA+BM,CAAC,OAAP,GAAiB,MA/BjB,CAAA"
|
||||
}
|
||||
67
dest/lib/lib/Frameworks/TextYatta.js
Normal file
67
dest/lib/lib/Frameworks/TextYatta.js
Normal file
@@ -0,0 +1,67 @@
|
||||
var Engine, HistoryBuffer, TextYatta, text_types_uninitialized;
|
||||
|
||||
text_types_uninitialized = require("../Types/TextTypes.coffee");
|
||||
|
||||
HistoryBuffer = require("../HistoryBuffer.coffee");
|
||||
|
||||
Engine = require("../Engine.coffee");
|
||||
|
||||
TextYatta = (function() {
|
||||
function TextYatta(user_id, Connector) {
|
||||
var first_word, text_types;
|
||||
this.HB = new HistoryBuffer(user_id);
|
||||
text_types = text_types_uninitialized(this.HB);
|
||||
this.engine = new Engine(this.HB, text_types.parser);
|
||||
this.connector = new Connector(this.engine, this.HB, text_types.execution_listener);
|
||||
this.root_element = this.connector.getRootElement();
|
||||
if (this.root_element == null) {
|
||||
first_word = new text_types.types.Word(this.HB.getNextOperationIdentifier());
|
||||
this.HB.addOperation(first_word);
|
||||
first_word.execute();
|
||||
this.root_element = this.HB.addOperation(new text_types.types.ReplaceManager(first_word, this.HB.getNextOperationIdentifier())).execute();
|
||||
}
|
||||
}
|
||||
|
||||
TextYatta.prototype.getRootElement = function() {
|
||||
return this.root_element;
|
||||
};
|
||||
|
||||
TextYatta.prototype.getEngine = function() {
|
||||
return this.engine;
|
||||
};
|
||||
|
||||
TextYatta.prototype.getConnector = function() {
|
||||
return this.connector;
|
||||
};
|
||||
|
||||
TextYatta.prototype.getHistoryBuffer = function() {
|
||||
return this.HB;
|
||||
};
|
||||
|
||||
TextYatta.prototype.getUserId = function() {
|
||||
return this.HB.getUserId();
|
||||
};
|
||||
|
||||
TextYatta.prototype.val = function() {
|
||||
return this.root_element.val().val();
|
||||
};
|
||||
|
||||
TextYatta.prototype.insertText = function(pos, content) {
|
||||
return this.root_element.val().insertText(pos, content);
|
||||
};
|
||||
|
||||
TextYatta.prototype.deleteText = function(pos, length) {
|
||||
return this.root_element.val().deleteText(pos, length);
|
||||
};
|
||||
|
||||
TextYatta.prototype.replaceText = function(text) {
|
||||
return this.root_element.val().replaceText(text);
|
||||
};
|
||||
|
||||
return TextYatta;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = TextYatta;
|
||||
|
||||
//# sourceMappingURL=TextYatta.js.map
|
||||
10
dest/lib/lib/Frameworks/TextYatta.js.map
Normal file
10
dest/lib/lib/Frameworks/TextYatta.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "TextYatta.js",
|
||||
"sourceRoot": "../../../../lib/Frameworks/",
|
||||
"sources": [
|
||||
"TextYatta.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AACA,IAAA,0DAAA;;AAAA,wBAAA,GAA2B,OAAA,CAAQ,2BAAR,CAA3B,CAAA;;AAAA,aACA,GAAgB,OAAA,CAAQ,yBAAR,CADhB,CAAA;;AAAA,MAEA,GAAS,OAAA,CAAQ,kBAAR,CAFT,CAAA;;AAAA;AAKe,EAAA,mBAAC,OAAD,EAAU,SAAV,GAAA;AACX,QAAA,sBAAA;AAAA,IAAA,IAAC,CAAA,EAAD,GAAU,IAAA,aAAA,CAAc,OAAd,CAAV,CAAA;AAAA,IACA,UAAA,GAAa,wBAAA,CAAyB,IAAC,CAAA,EAA1B,CADb,CAAA;AAAA,IAEA,IAAC,CAAA,MAAD,GAAc,IAAA,MAAA,CAAO,IAAC,CAAA,EAAR,EAAY,UAAU,CAAC,MAAvB,CAFd,CAAA;AAAA,IAGA,IAAC,CAAA,SAAD,GAAiB,IAAA,SAAA,CAAU,IAAC,CAAA,MAAX,EAAmB,IAAC,CAAA,EAApB,EAAwB,UAAU,CAAC,kBAAnC,CAHjB,CAAA;AAAA,IAIA,IAAC,CAAA,YAAD,GAAgB,IAAC,CAAA,SAAS,CAAC,cAAX,CAAA,CAJhB,CAAA;AAKA,IAAA,IAAO,yBAAP;AACE,MAAA,UAAA,GAAiB,IAAA,UAAU,CAAC,KAAK,CAAC,IAAjB,CAAsB,IAAC,CAAA,EAAE,CAAC,0BAAJ,CAAA,CAAtB,CAAjB,CAAA;AAAA,MACA,IAAC,CAAA,EAAE,CAAC,YAAJ,CAAiB,UAAjB,CADA,CAAA;AAAA,MAEA,UAAU,CAAC,OAAX,CAAA,CAFA,CAAA;AAAA,MA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AAC,WAApB,CAAgC,IAAhC,EADW;EAAA,CApCb,CAAA;;mBAAA;;IALF,CAAA;;AAAA,MA6CM,CAAC,OAAP,GAAiB,SA7CjB,CAAA"
|
||||
}
|
||||
82
dest/lib/lib/HistoryBuffer.js
Normal file
82
dest/lib/lib/HistoryBuffer.js
Normal file
@@ -0,0 +1,82 @@
|
||||
var HistoryBuffer, _;
|
||||
|
||||
_ = require("underscore");
|
||||
|
||||
HistoryBuffer = (function() {
|
||||
function HistoryBuffer(user_id) {
|
||||
this.user_id = user_id;
|
||||
this.operation_counter = {};
|
||||
this.buffer = {};
|
||||
this.change_listeners = [];
|
||||
}
|
||||
|
||||
HistoryBuffer.prototype.getUserId = function() {
|
||||
return this.user_id;
|
||||
};
|
||||
|
||||
HistoryBuffer.prototype.getOperationCounter = function() {
|
||||
return _.clone(this.operation_counter);
|
||||
};
|
||||
|
||||
HistoryBuffer.prototype.toJson = function() {
|
||||
var json, o, user, _i, _len, _ref;
|
||||
json = [];
|
||||
_ref = this.buffer;
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
user = _ref[_i];
|
||||
for (o in user) {
|
||||
json.push(o.toJson());
|
||||
}
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
||||
HistoryBuffer.prototype.getNextOperationIdentifier = function(user_id) {
|
||||
var uid;
|
||||
if (user_id == null) {
|
||||
user_id = this.user_id;
|
||||
}
|
||||
if (this.operation_counter[user_id] == null) {
|
||||
this.operation_counter[user_id] = 0;
|
||||
}
|
||||
uid = {
|
||||
'creator': user_id,
|
||||
'op_number': this.operation_counter[user_id]
|
||||
};
|
||||
this.operation_counter[user_id]++;
|
||||
return uid;
|
||||
};
|
||||
|
||||
HistoryBuffer.prototype.getOperation = function(uid) {
|
||||
var _ref;
|
||||
if (uid instanceof Object) {
|
||||
return (_ref = this.buffer[uid.creator]) != null ? _ref[uid.op_number] : void 0;
|
||||
} else {
|
||||
throw new Error("This type of uid is not defined!");
|
||||
}
|
||||
};
|
||||
|
||||
HistoryBuffer.prototype.addOperation = function(o) {
|
||||
if (this.buffer[o.creator] == null) {
|
||||
this.buffer[o.creator] = {};
|
||||
}
|
||||
if (this.operation_counter[o.creator] == null) {
|
||||
this.operation_counter[o.creator] = 0;
|
||||
}
|
||||
if (this.buffer[o.creator][o.op_number] != null) {
|
||||
throw new Error("You must not overwrite operations!");
|
||||
}
|
||||
this.buffer[o.creator][o.op_number] = o;
|
||||
if (typeof o.op_number === 'number' && o.creator !== this.getUserId()) {
|
||||
this.operation_counter[o.creator]++;
|
||||
}
|
||||
return o;
|
||||
};
|
||||
|
||||
return HistoryBuffer;
|
||||
|
||||
})();
|
||||
|
||||
module.exports = HistoryBuffer;
|
||||
|
||||
//# sourceMappingURL=HistoryBuffer.js.map
|
||||
10
dest/lib/lib/HistoryBuffer.js.map
Normal file
10
dest/lib/lib/HistoryBuffer.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "HistoryBuffer.js",
|
||||
"sourceRoot": "../../../lib/",
|
||||
"sources": [
|
||||
"HistoryBuffer.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AAAA,IAAA,gBAAA;;AAAA,CAAA,GAAI,OAAA,CAAQ,YAAR,CAAJ,CAAA;;AAAA;AAee,EAAA,uBAAE,OAAF,GAAA;AACX,IADY,IAAC,CAAA,UAAA,OACb,CAAA;AAAA,IAAA,IAAC,CAAA,iBAAD,GAAqB,EAArB,CAAA;AAAA,IACA,IAAC,CAAA,MAAD,GAAU,EADV,CAAA;AAAA,IAEA,IAAC,CAAA,gBAAD,GAAoB,EAFpB,CADW;EAAA,CAAb;;AAAA,0BAKA,SAAA,GAAW,SAAA,GAAA;WACT,IAAC,CAAA,QADQ;EAAA,CALX,CAAA;;AAAA,0BAQA,mBAAA,GAAqB,SAAA,GAAA;WACnB,CAAC,CAAC,KAAF,CAAQ,IAAC,CAAA,iBAAT,EADmB;EAAA,CARrB,CAAA;;AAAA,0BAW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,IAAG,2CAAH;AACE,YAAU,IAAA,KAAA,CAAM,oCAAN,CAAV,CADF;KANA;AAAA,IAQA,IAAC,CAAA,MAAO,CAAA,CAAC,CAAC,OAAF,CAAW,CAAA,CAAC,CAAC,SAAF,CAAnB,GAAkC,CARlC,CAAA;AASA,IAAA,IAAG,MAAA,CAAA,CAAQ,CAAC,SAAT,KAAsB,QAAtB,IAAmC,CAAC,CAAC,OAAF,KAAe,IAAC,CAAA,SAAD,CAAA,CAArD;AACE,MAAA,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAAnB,EAAA,CADF;KATA;WAWA,EAZY;EAAA,CA3Cd,CAAA;;uBAAA;;IAfF,CAAA;;AAAA,MA0EM,CAAC,OAAP,GAAiB,aA1EjB,CAAA"
|
||||
}
|
||||
33
dest/lib/lib/ReplaceType.js
Normal file
33
dest/lib/lib/ReplaceType.js
Normal file
@@ -0,0 +1,33 @@
|
||||
var Replaceable, y, _,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
y = require("Engine");
|
||||
|
||||
_ = require("underscore");
|
||||
|
||||
Replaceable = (function(_super) {
|
||||
__extends(Replaceable, _super);
|
||||
|
||||
function Replaceable(user_id, content) {
|
||||
Replaceable.__super__.constructor.call(this, user_id, []);
|
||||
this.replace(content);
|
||||
}
|
||||
|
||||
Replaceable.prototype.replace = function(content) {
|
||||
var o, op;
|
||||
o = this.HB.getLastOperation();
|
||||
op = new I(content, this.user_id, this.HB.getOperationCounter(this.user_id), o, o.next_cl);
|
||||
this.HB.addOperation(op).IT();
|
||||
return op.toJson();
|
||||
};
|
||||
|
||||
Replaceable.prototype.getContent = function() {
|
||||
return this.HB.getLastOperation().execute();
|
||||
};
|
||||
|
||||
return Replaceable;
|
||||
|
||||
})(y.Engine);
|
||||
|
||||
//# sourceMappingURL=ReplaceType.js.map
|
||||
10
dest/lib/lib/ReplaceType.js.map
Normal file
10
dest/lib/lib/ReplaceType.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "ReplaceType.js",
|
||||
"sourceRoot": "../../../lib/",
|
||||
"sources": [
|
||||
"ReplaceType.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AACA,IAAA,iBAAA;EAAA;iSAAA;;AAAA,CAAA,GAAI,OAAA,CAAQ,QAAR,CAAJ,CAAA;;AAAA,CACA,GAAI,OAAA,CAAQ,YAAR,CADJ,CAAA;;AAAA;AAIE,gCAAA,CAAA;;AAAa,EAAA,qBAAC,OAAD,EAAU,OAAV,GAAA;AACX,IAAA,6CAAM,OAAN,EAAe,EAAf,CAAA,CAAA;AAAA,IACA,IAAC,CAAA,OAAD,CAAS,OAAT,CADA,CADW;EAAA,CAAb;;AAAA,wBAIA,OAAA,GAAS,SAAC,OAAD,GAAA;AACP,QAAA,KAAA;AAAA,IAAA,CAAA,GAAI,IAAC,CAAA,EAAE,CAAC,gBAAJ,CAAA,CAAJ,CAAA;AAAA,IACA,EAAA,GAAS,IAAA,CAAA,CAAE,OAAF,EAAW,IAAC,CAAA,OAAZ,EAAqB,IAAC,CAAA,EAAE,CAAC,mBAAJ,CAAwB,IAAC,CAAA,OAAzB,CAArB,EAAwD,CAAxD,EAA2D,CAAC,CAAC,OAA7D,CADT,CAAA;AAAA,IAEA,IAAC,CAAA,EAAE,CAAC,YAAJ,CAAiB,EAAjB,CAAoB,CAAC,EAArB,CAAA,CAFA,CAAA;WAGA,EAAE,CAAC,MAAH,CAAA,EAJO;EAAA,CAJT,CAAA;;AAAA,wBAUA,UAAA,GAAY,SAAA,GAAA;WACV,IAAC,CAAA,EAAE,CAAC,gBAAJ,CAAA,CAAsB,CAAC,OAAvB,CAAA,EADU;EAAA,CAVZ,CAAA;;qBAAA;;GADwB,CAAC,CAAC,OAH5B,CAAA"
|
||||
}
|
||||
269
dest/lib/lib/Types/BasicTypes.js
Normal file
269
dest/lib/lib/Types/BasicTypes.js
Normal file
@@ -0,0 +1,269 @@
|
||||
var __hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
module.exports = function(HB) {
|
||||
var Delete, Delimiter, Insert, Operation, execution_listener, parser;
|
||||
parser = {};
|
||||
execution_listener = [];
|
||||
Operation = (function() {
|
||||
function Operation(_arg) {
|
||||
this.creator = _arg['creator'], this.op_number = _arg['op_number'];
|
||||
}
|
||||
|
||||
Operation.prototype.getUid = function() {
|
||||
return {
|
||||
'creator': this.creator,
|
||||
'op_number': this.op_number
|
||||
};
|
||||
};
|
||||
|
||||
Operation.prototype.execute = function() {
|
||||
var l, _i, _len;
|
||||
for (_i = 0, _len = execution_listener.length; _i < _len; _i++) {
|
||||
l = execution_listener[_i];
|
||||
l(this.toJson());
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Operation.prototype.saveOperation = function(name, op) {
|
||||
if ((op != null ? op.execute : void 0) != null) {
|
||||
return this[name] = op;
|
||||
} else if (op != null) {
|
||||
if (this.unchecked == null) {
|
||||
this.unchecked = {};
|
||||
}
|
||||
return this.unchecked[name] = op;
|
||||
}
|
||||
};
|
||||
|
||||
Operation.prototype.validateSavedOperations = function() {
|
||||
var name, op, op_uid, success, uninstantiated, _ref;
|
||||
uninstantiated = {};
|
||||
success = this;
|
||||
_ref = this.unchecked;
|
||||
for (name in _ref) {
|
||||
op_uid = _ref[name];
|
||||
op = HB.getOperation(op_uid);
|
||||
if (op) {
|
||||
this[name] = op;
|
||||
} else {
|
||||
uninstantiated[name] = op;
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
delete this.unchecked;
|
||||
if (!success) {
|
||||
this.unchecked = uninstantiated;
|
||||
}
|
||||
return success;
|
||||
};
|
||||
|
||||
return Operation;
|
||||
|
||||
})();
|
||||
Delete = (function(_super) {
|
||||
__extends(Delete, _super);
|
||||
|
||||
function Delete(uid, deletes) {
|
||||
this.saveOperation('deletes', deletes);
|
||||
Delete.__super__.constructor.call(this, uid);
|
||||
}
|
||||
|
||||
Delete.prototype.toJson = function() {
|
||||
return {
|
||||
'type': "Delete",
|
||||
'uid': this.getUid(),
|
||||
'deletes': this.deletes.getUid()
|
||||
};
|
||||
};
|
||||
|
||||
Delete.prototype.execute = function() {
|
||||
if (this.validateSavedOperations()) {
|
||||
this.deletes.applyDelete(this);
|
||||
Delete.__super__.execute.apply(this, arguments);
|
||||
return this;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
return Delete;
|
||||
|
||||
})(Operation);
|
||||
parser['Delete'] = function(_arg) {
|
||||
var deletes_uid, uid;
|
||||
uid = _arg['uid'], deletes_uid = _arg['deletes'];
|
||||
return new D(uid, deletes_uid);
|
||||
};
|
||||
Insert = (function(_super) {
|
||||
__extends(Insert, _super);
|
||||
|
||||
function Insert(uid, prev_cl, next_cl, origin) {
|
||||
this.saveOperation('prev_cl', prev_cl);
|
||||
this.saveOperation('next_cl', next_cl);
|
||||
if (origin != null) {
|
||||
this.saveOperation('origin', origin);
|
||||
} else {
|
||||
this.saveOperation('origin', prev_cl);
|
||||
}
|
||||
Insert.__super__.constructor.call(this, uid);
|
||||
}
|
||||
|
||||
Insert.prototype.applyDelete = function(o) {
|
||||
if (this.deleted_by == null) {
|
||||
this.deleted_by = [];
|
||||
}
|
||||
return this.deleted_by.push(o);
|
||||
};
|
||||
|
||||
Insert.prototype.isDeleted = function() {
|
||||
var _ref;
|
||||
return ((_ref = this.deleted_by) != null ? _ref.length : void 0) > 0;
|
||||
};
|
||||
|
||||
Insert.prototype.getDistanceToOrigin = function() {
|
||||
var d, o;
|
||||
d = 0;
|
||||
o = this.prev_cl;
|
||||
while (true) {
|
||||
if (this.origin === o) {
|
||||
break;
|
||||
}
|
||||
d++;
|
||||
o = o.prev_cl;
|
||||
}
|
||||
return d;
|
||||
};
|
||||
|
||||
Insert.prototype.update_sl = function() {
|
||||
var o;
|
||||
o = this.prev_cl;
|
||||
({
|
||||
update: function(dest_cl, dest_sl) {
|
||||
var _results;
|
||||
_results = [];
|
||||
while (true) {
|
||||
if (o.isDeleted()) {
|
||||
_results.push(o = o[dest_cl]);
|
||||
} else {
|
||||
this[dest_sl] = o;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
});
|
||||
update("prev_cl", "prev_sl");
|
||||
return update("next_cl", "prev_sl");
|
||||
};
|
||||
|
||||
Insert.prototype.execute = function() {
|
||||
var distance_to_origin, i, o;
|
||||
if (!this.validateSavedOperations()) {
|
||||
return false;
|
||||
} else {
|
||||
if ((this.prev_cl != null) && (this.next_cl != null)) {
|
||||
distance_to_origin = 0;
|
||||
o = this.prev_cl.next_cl;
|
||||
i = 0;
|
||||
while (true) {
|
||||
if (o == null) {
|
||||
console.log(JSON.stringify(this.prev_cl.getUid()));
|
||||
console.log(JSON.stringify(this.next_cl.getUid()));
|
||||
}
|
||||
if (o !== this.next_cl) {
|
||||
if (o.getDistanceToOrigin() === i) {
|
||||
if (o.creator < this.creator) {
|
||||
this.prev_cl = o;
|
||||
distance_to_origin = i + 1;
|
||||
} else {
|
||||
|
||||
}
|
||||
} else if (o.getDistanceToOrigin() < i) {
|
||||
if (i - distance_to_origin <= o.getDistanceToOrigin()) {
|
||||
this.prev_cl = o;
|
||||
distance_to_origin = i + 1;
|
||||
} else {
|
||||
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
o = o.next_cl;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.next_cl = this.prev_cl.next_cl;
|
||||
this.prev_cl.next_cl = this;
|
||||
this.next_cl.prev_cl = this;
|
||||
}
|
||||
Insert.__super__.execute.apply(this, arguments);
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
Insert.prototype.val = function() {
|
||||
throw new Error("Implement this function!");
|
||||
};
|
||||
|
||||
return Insert;
|
||||
|
||||
})(Operation);
|
||||
Delimiter = (function(_super) {
|
||||
__extends(Delimiter, _super);
|
||||
|
||||
function Delimiter() {
|
||||
return Delimiter.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
Delimiter.prototype.isDeleted = function() {
|
||||
return false;
|
||||
};
|
||||
|
||||
Delimiter.prototype.getDistanceToOrigin = function() {
|
||||
return 0;
|
||||
};
|
||||
|
||||
Delimiter.prototype.execute = function() {
|
||||
var a, l, _i, _len;
|
||||
a = this.validateSavedOperations();
|
||||
for (_i = 0, _len = execution_listener.length; _i < _len; _i++) {
|
||||
l = execution_listener[_i];
|
||||
l(this.toJson());
|
||||
}
|
||||
return a;
|
||||
};
|
||||
|
||||
Delimiter.prototype.toJson = function() {
|
||||
return {
|
||||
'type': "Delimiter",
|
||||
'uid': this.getUid(),
|
||||
'prev': this.prev_cl.getUid(),
|
||||
'next': this.next_cl.getUid()
|
||||
};
|
||||
};
|
||||
|
||||
return Delimiter;
|
||||
|
||||
})(Insert);
|
||||
parser['Delimiter'] = function(json) {
|
||||
var next, prev, uid;
|
||||
uid = json['uid'], prev = json['prev'], next = json['next'];
|
||||
return new Delimiter(uid, prev, next);
|
||||
};
|
||||
return {
|
||||
'types': {
|
||||
'Delete': Delete,
|
||||
'Insert': Insert,
|
||||
'Delimiter': Delimiter,
|
||||
'Operation': Operation
|
||||
},
|
||||
'parser': parser,
|
||||
'execution_listener': execution_listener
|
||||
};
|
||||
};
|
||||
|
||||
//# sourceMappingURL=BasicTypes.js.map
|
||||
10
dest/lib/lib/Types/BasicTypes.js.map
Normal file
10
dest/lib/lib/Types/BasicTypes.js.map
Normal file
File diff suppressed because one or more lines are too long
197
dest/lib/lib/Types/StructuredTypes.js
Normal file
197
dest/lib/lib/Types/StructuredTypes.js
Normal file
@@ -0,0 +1,197 @@
|
||||
var basic_types_uninitialized, _,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
_ = require("underscore");
|
||||
|
||||
basic_types_uninitialized = require("./BasicTypes.coffee");
|
||||
|
||||
module.exports = function(HB) {
|
||||
var ListManager, MapManager, ReplaceManager, Replaceable, basic_types, parser, types;
|
||||
basic_types = basic_types_uninitialized(HB);
|
||||
types = basic_types.types;
|
||||
parser = basic_types.parser;
|
||||
MapManager = (function() {
|
||||
function MapManager() {
|
||||
this.map = {};
|
||||
}
|
||||
|
||||
MapManager.prototype.set = function(name, content) {
|
||||
if (this.map[name] == null) {
|
||||
return this.map[name] = new Replaceable(HB, this.map[name].replace(content));
|
||||
}
|
||||
};
|
||||
|
||||
return MapManager;
|
||||
|
||||
})();
|
||||
ListManager = (function(_super) {
|
||||
__extends(ListManager, _super);
|
||||
|
||||
function ListManager(uid, beginning, end, prev, next, origin) {
|
||||
if ((beginning != null) && (end != null)) {
|
||||
saveOperation("beginning", beginning);
|
||||
saveOperation("end", end);
|
||||
} else {
|
||||
this.beginning = HB.addOperation(new types.Delimiter(HB.getNextOperationIdentifier(), void 0, void 0));
|
||||
this.end = HB.addOperation(new types.Delimiter(HB.getNextOperationIdentifier(), this.beginning, void 0));
|
||||
this.beginning.next_cl = this.end;
|
||||
}
|
||||
ListManager.__super__.constructor.call(this, uid, prev, next, origin);
|
||||
}
|
||||
|
||||
ListManager.prototype.getLastOperation = function() {
|
||||
return this.end.prev_cl;
|
||||
};
|
||||
|
||||
ListManager.prototype.getFirstOperation = function() {
|
||||
return this.beginning.next_cl;
|
||||
};
|
||||
|
||||
ListManager.prototype.toArray = function() {
|
||||
var o, result;
|
||||
o = this.beginning.next_cl;
|
||||
result = [];
|
||||
while (o !== this.end) {
|
||||
result.push(o);
|
||||
o = o.next_cl;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
ListManager.prototype.getOperationByPosition = function(position) {
|
||||
var o;
|
||||
o = this.beginning.next_cl;
|
||||
if (position > 0) {
|
||||
while (true) {
|
||||
o = o.next_cl;
|
||||
if (!o.isDeleted()) {
|
||||
position -= 1;
|
||||
}
|
||||
if (position === 0) {
|
||||
break;
|
||||
}
|
||||
if (o instanceof types.Delimiter) {
|
||||
throw new Error("position parameter exceeded the length of the document!");
|
||||
}
|
||||
}
|
||||
}
|
||||
return o;
|
||||
};
|
||||
|
||||
return ListManager;
|
||||
|
||||
})(types.Insert);
|
||||
ReplaceManager = (function(_super) {
|
||||
__extends(ReplaceManager, _super);
|
||||
|
||||
function ReplaceManager(initial_content, uid, beginning, end, prev, next, origin) {
|
||||
ReplaceManager.__super__.constructor.call(this, uid, beginning, end, prev, next, origin);
|
||||
if (initial_content != null) {
|
||||
this.replace(initial_content);
|
||||
}
|
||||
}
|
||||
|
||||
ReplaceManager.prototype.replace = function(content) {
|
||||
var o, op;
|
||||
o = this.getLastOperation();
|
||||
op = new Replaceable(content, this, HB.getNextOperationIdentifier(), o, o.next_cl);
|
||||
return HB.addOperation(op).execute();
|
||||
};
|
||||
|
||||
ReplaceManager.prototype.val = function() {
|
||||
var o;
|
||||
o = this.getLastOperation();
|
||||
if (o instanceof types.Delimiter) {
|
||||
throw new Error("dtrn");
|
||||
}
|
||||
return o.val();
|
||||
};
|
||||
|
||||
ReplaceManager.prototype.toJson = function() {
|
||||
var json;
|
||||
json = {
|
||||
'type': "ReplaceManager",
|
||||
'uid': this.getUid(),
|
||||
'beginning': this.beginning,
|
||||
'end': this.end
|
||||
};
|
||||
if ((this.prev_cl != null) && (this.next_cl != null)) {
|
||||
json['prev'] = this.prev_cl.getUid();
|
||||
json['next'] = this.next_cl.getUid();
|
||||
}
|
||||
if ((this.origin != null) && this.origin !== this.prev_cl) {
|
||||
json["origin"] = this.origin.getUid();
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
||||
return ReplaceManager;
|
||||
|
||||
})(ListManager);
|
||||
parser["ReplaceManager"] = function(json) {
|
||||
var beginning, content, end, next, origin, prev, uid;
|
||||
content = json['content'], uid = json['uid'], prev = json['prev'], next = json['next'], origin = json['origin'], beginning = json['beginning'], end = json['end'];
|
||||
return new ReplaceManager(content, uid, beginning, end, prev, next, origin);
|
||||
};
|
||||
Replaceable = (function(_super) {
|
||||
__extends(Replaceable, _super);
|
||||
|
||||
function Replaceable(content, parent, uid, prev, next, origin) {
|
||||
this.saveOperation('content', content);
|
||||
this.saveOperation('parent', parent);
|
||||
if (!((prev != null) && (next != null))) {
|
||||
throw new Error("You must define prev, and next for Replaceable-types!");
|
||||
}
|
||||
Replaceable.__super__.constructor.call(this, uid, prev, next, origin);
|
||||
}
|
||||
|
||||
Replaceable.prototype.val = function() {
|
||||
return this.content;
|
||||
};
|
||||
|
||||
Replaceable.prototype.replace = function(content) {
|
||||
return this.parent.replace(content);
|
||||
};
|
||||
|
||||
Replaceable.prototype.execute = function() {
|
||||
var _base;
|
||||
Replaceable.__super__.execute.apply(this, arguments);
|
||||
if (typeof (_base = this.content).setReplaceManager === "function") {
|
||||
_base.setReplaceManager(this.parent);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
Replaceable.prototype.toJson = function() {
|
||||
var json;
|
||||
json = {
|
||||
'type': "Replaceable",
|
||||
'content': this.content.getUid(),
|
||||
'ReplaceManager': this.parent,
|
||||
'prev': this.prev_cl.getUid(),
|
||||
'next': this.next_cl.getUid(),
|
||||
'uid': this.getUid()
|
||||
};
|
||||
if ((this.origin != null) && this.origin !== this.prev_cl) {
|
||||
json["origin"] = this.origin.getUid();
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
||||
return Replaceable;
|
||||
|
||||
})(types.Insert);
|
||||
parser["Replaceable"] = function(json) {
|
||||
var content, next, origin, parent, prev, uid;
|
||||
content = json['content'], parent = json['ReplaceManager'], uid = json['uid'], prev = json['prev'], next = json['next'], origin = json['origin'];
|
||||
return new Replaceable(content, parent, uid, prev, next, origin);
|
||||
};
|
||||
types['ListManager'] = ListManager;
|
||||
types['MapManager'] = MapManager;
|
||||
types['ReplaceManager'] = ReplaceManager;
|
||||
types['Replaceable'] = Replaceable;
|
||||
return basic_types;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=StructuredTypes.js.map
|
||||
10
dest/lib/lib/Types/StructuredTypes.js.map
Normal file
10
dest/lib/lib/Types/StructuredTypes.js.map
Normal file
File diff suppressed because one or more lines are too long
180
dest/lib/lib/Types/TextTypes.js
Normal file
180
dest/lib/lib/Types/TextTypes.js
Normal file
@@ -0,0 +1,180 @@
|
||||
var structured_types_uninitialized, _,
|
||||
__hasProp = {}.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||
|
||||
_ = require("underscore");
|
||||
|
||||
structured_types_uninitialized = require("./StructuredTypes.coffee");
|
||||
|
||||
module.exports = function(HB) {
|
||||
var TextDelete, TextInsert, Word, parser, structured_types, types;
|
||||
structured_types = structured_types_uninitialized(HB);
|
||||
types = structured_types.types;
|
||||
parser = structured_types.parser;
|
||||
TextDelete = (function(_super) {
|
||||
__extends(TextDelete, _super);
|
||||
|
||||
function TextDelete() {
|
||||
return TextDelete.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
return TextDelete;
|
||||
|
||||
})(types.Delete);
|
||||
parser["TextDelete"] = parser["Delete"];
|
||||
TextInsert = (function(_super) {
|
||||
__extends(TextInsert, _super);
|
||||
|
||||
function TextInsert(content, uid, prev, next, origin) {
|
||||
this.content = content;
|
||||
if (!((prev != null) && (next != null))) {
|
||||
throw new Error("You must define prev, and next for TextInsert-types!");
|
||||
}
|
||||
TextInsert.__super__.constructor.call(this, uid, prev, next, origin);
|
||||
}
|
||||
|
||||
TextInsert.prototype.getLength = function() {
|
||||
if (this.isDeleted()) {
|
||||
return 0;
|
||||
} else {
|
||||
return this.content.length;
|
||||
}
|
||||
};
|
||||
|
||||
TextInsert.prototype.val = function(current_position) {
|
||||
if (this.isDeleted()) {
|
||||
return "";
|
||||
} else {
|
||||
return this.content;
|
||||
}
|
||||
};
|
||||
|
||||
TextInsert.prototype.toJson = function() {
|
||||
var json;
|
||||
json = {
|
||||
'type': "TextInsert",
|
||||
'content': this.content,
|
||||
'uid': this.getUid(),
|
||||
'prev': this.prev_cl.getUid(),
|
||||
'next': this.next_cl.getUid()
|
||||
};
|
||||
if ((this.origin != null) && this.origin !== this.prev_cl) {
|
||||
json["origin"] = this.origin.getUid();
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
||||
return TextInsert;
|
||||
|
||||
})(types.Insert);
|
||||
parser["TextInsert"] = function(json) {
|
||||
var content, next, origin, prev, uid;
|
||||
content = json['content'], uid = json['uid'], prev = json['prev'], next = json['next'], origin = json['origin'];
|
||||
return new TextInsert(content, uid, prev, next, origin);
|
||||
};
|
||||
Word = (function(_super) {
|
||||
__extends(Word, _super);
|
||||
|
||||
function Word(uid, prev, next, origin) {
|
||||
Word.__super__.constructor.call(this, uid, prev, next, origin);
|
||||
}
|
||||
|
||||
Word.prototype.insertText = function(position, content) {
|
||||
var c, o, op, _i, _len, _results;
|
||||
o = this.getOperationByPosition(position);
|
||||
_results = [];
|
||||
for (_i = 0, _len = content.length; _i < _len; _i++) {
|
||||
c = content[_i];
|
||||
op = new TextInsert(c, HB.getNextOperationIdentifier(), o.prev_cl, o);
|
||||
_results.push(HB.addOperation(op).execute());
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Word.prototype.deleteText = function(position, length) {
|
||||
var d, i, o, _i, _results;
|
||||
o = this.getOperationByPosition(position);
|
||||
_results = [];
|
||||
for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) {
|
||||
d = HB.addOperation(new TextDelete(HB.getNextOperationIdentifier(), o)).execute();
|
||||
o = o.next_cl;
|
||||
while (o.isDeleted()) {
|
||||
if (o instanceof types.Delimiter) {
|
||||
throw new Error("You can't delete more than there is..");
|
||||
}
|
||||
o = o.next_cl;
|
||||
}
|
||||
_results.push(d.toJson());
|
||||
}
|
||||
return _results;
|
||||
};
|
||||
|
||||
Word.prototype.replaceText = function(text) {
|
||||
var word;
|
||||
if (this.replace_manager != null) {
|
||||
word = HB.addOperation(new Word(HB.getNextOperationIdentifier())).execute();
|
||||
word.insertText(0, text);
|
||||
return this.replace_manager.replace(word);
|
||||
} else {
|
||||
throw new Error("This type is currently not maintained by a ReplaceManager!");
|
||||
}
|
||||
};
|
||||
|
||||
Word.prototype.val = function() {
|
||||
var c, o;
|
||||
c = (function() {
|
||||
var _i, _len, _ref, _results;
|
||||
_ref = this.toArray();
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
o = _ref[_i];
|
||||
if (o.val != null) {
|
||||
_results.push(o.val());
|
||||
} else {
|
||||
_results.push("");
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
}).call(this);
|
||||
return c.join('');
|
||||
};
|
||||
|
||||
Word.prototype.setReplaceManager = function(op) {
|
||||
this.saveOperation('replace_manager', op);
|
||||
return this.validateSavedOperations;
|
||||
};
|
||||
|
||||
Word.prototype.toJson = function() {
|
||||
var json;
|
||||
json = {
|
||||
'type': "TextInsert",
|
||||
'content': this.content,
|
||||
'uid': this.getUid()
|
||||
};
|
||||
if (this.prev_cl != null) {
|
||||
json['prev'] = this.prev_cl.getUid();
|
||||
}
|
||||
if (this.next_cl != null) {
|
||||
json['next'] = this.next_cl.getUid();
|
||||
}
|
||||
if ((this.origin != null) && this.origin !== this.prev_cl) {
|
||||
json["origin"] = this.origin.getUid();
|
||||
}
|
||||
return json;
|
||||
};
|
||||
|
||||
return Word;
|
||||
|
||||
})(types.ListManager);
|
||||
parser['Word'] = function(json) {
|
||||
var content, next, origin, prev, uid;
|
||||
content = json['content'], uid = json['uid'], prev = json['prev'], next = json['next'], origin = json['origin'];
|
||||
return new Word(uid, prev, next, origin);
|
||||
};
|
||||
types['TextInsert'] = TextInsert;
|
||||
types['TextDelete'] = TextDelete;
|
||||
types['Word'] = Word;
|
||||
return structured_types;
|
||||
};
|
||||
|
||||
//# sourceMappingURL=TextTypes.js.map
|
||||
10
dest/lib/lib/Types/TextTypes.js.map
Normal file
10
dest/lib/lib/Types/TextTypes.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "TextTypes.js",
|
||||
"sourceRoot": "../../../../lib/Types/",
|
||||
"sources": [
|
||||
"TextTypes.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AAAA,IAAA,iCAAA;EAAA;iSAAA;;AAAA,CAAA,GAAI,OAAA,CAAQ,YAAR,CAAJ,CAAA;;AAAA,8BACA,GAAiC,OAAA,CAAQ,0BAAR,CADjC,CAAA;;AAAA,MAGM,CAAC,OAAP,GAAiB,SAAC,EAAD,GAAA;AACf,MAAA,6DAAA;AAAA,EAAA,gBAAA,GAAmB,8BAAA,CAA+B,EAA/B,CAAnB,CAAA;AAAA,EACA,KAAA,GAAQ,gBAAgB,CAAC,KADzB,CAAA;AAAA,EAEA,MAAA,GAAS,gBAAgB,CAAC,MAF1B,CAAA;AAAA,EAQM;AAAN,iCAAA,CAAA;;;;KAAA;;sBAAA;;KAAyB,KAAK,CAAC,OAR/B,CAAA;AAAA,EASA,MAAO,CAAA,YAAA,CAAP,GAAuB,MAAO,CAAA,QAAA,CAT9B,CAAA;AAAA,EAcM;AACJ,iCAAA,CAAA;;AAAa,IAAA,oBAAE,OAAF,EAAW,GAAX,EAAgB,IAAhB,EAAsB,IAAtB,EAA4B,MAA5B,GAAA;AACX,MADY,IAAC,CAAA,UAAA,OACb,CAAA;AAAA,MAAA,IAAG,CAAA,CAAK,cAAA,IAAU,cAAX,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,IAAC,CAAA,MAAD,CAAA,CAHH;OAAP,CAAA;AAKA,MAAA,IAAG,oBAAH;AACE,QAAA,IAAK,CAAA,MAAA,CAAL,GAAe,IAAC,CAAA,OAAO,CAAC,MAAT,CAAA,CAAf,CADF;OALA;AAOA,MAAA,IAAG,oBAAH;AACE,QAAA,IAAK,CAAA,MAAA,CAAL,GAAe,IAAC,CAAA,OAAO,CAAC,MAAT,CAAA,CAAf,CADF;OAPA;AASA,MAAA,IAAG,qBAAA,IAAa,IAAC,CAAA,MAAD,KAAa,IAAC,CAAA,OAA9B;AACE,QAAA,IAAK,CAAA,QAAA,CAAL,GAAiB,IAAC,CAAA,MAAM,CAAC,MAAR,CAAA,CAAjB,CADF;OATA;aAWA,KAZM;IAAA,CA3CR,CAAA;;gBAAA;;KADiB,KAAK,CAAC,YAlEzB,CAAA;AAAA,EA4HA,MAAO,CAAA,MAAA,CAAP,GAAiB,SAAC,IAAD,GAAA;AACf,QAAA,gCAAA;AAAA,IACc,eAAZ,UADF,EAEU,WAAR,MAFF,EAGU,YAAR,OAHF,EAIU,YAAR,OAJF,EAKa,cAAX,SALF,CAAA;WAOI,IAAA,IAAA,CAAK,GAAL,EAAU,IAAV,EAAgB,IAAhB,EAAsB,MAAtB,EARW;EAAA,CA5HjB,CAAA;AAAA,EAsIA,KAAM,CAAA,YAAA,CAAN,GAAsB,UAtItB,CAAA;AAAA,EAuIA,KAAM,CAAA,YAAA,CAAN,GAAsB,UAvItB,CAAA;AAAA,EAwIA,KAAM,CAAA,MAAA,CAAN,GAAgB,IAxIhB,CAAA;SA0IA,iBA3Ie;AAAA,CAHjB,CAAA"
|
||||
}
|
||||
5
dest/lib/lib/Types/XmlTypes.js
Normal file
5
dest/lib/lib/Types/XmlTypes.js
Normal file
@@ -0,0 +1,5 @@
|
||||
var _;
|
||||
|
||||
_ = require("underscore");
|
||||
|
||||
//# sourceMappingURL=XmlTypes.js.map
|
||||
10
dest/lib/lib/Types/XmlTypes.js.map
Normal file
10
dest/lib/lib/Types/XmlTypes.js.map
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 3,
|
||||
"file": "XmlTypes.js",
|
||||
"sourceRoot": "../../../../lib/Types/",
|
||||
"sources": [
|
||||
"XmlTypes.coffee"
|
||||
],
|
||||
"names": [],
|
||||
"mappings": "AAAA,IAAA,CAAA;;AAAA,CAAA,GAAI,OAAA,CAAQ,YAAR,CAAJ,CAAA"
|
||||
}
|
||||
177
dest/test/test/TextYatta_test.js
Normal file
177
dest/test/test/TextYatta_test.js
Normal file
@@ -0,0 +1,177 @@
|
||||
(function() {
|
||||
var Connector_uninitialized, Yatta, chai, expect, should, sinon, sinonChai, _;
|
||||
|
||||
chai = require('chai');
|
||||
|
||||
expect = chai.expect;
|
||||
|
||||
should = chai.should();
|
||||
|
||||
sinon = require('sinon');
|
||||
|
||||
sinonChai = require('sinon-chai');
|
||||
|
||||
_ = require("underscore");
|
||||
|
||||
chai.use(sinonChai);
|
||||
|
||||
Yatta = require("../lib/Frameworks/TextYatta.coffee");
|
||||
|
||||
Connector_uninitialized = require("../lib/Connectors/TestConnector.coffee");
|
||||
|
||||
describe("TextYatta", function() {
|
||||
beforeEach(function(done) {
|
||||
var i, _i, _ref;
|
||||
this.last_user = 10;
|
||||
this.users = [];
|
||||
this.Connector = Connector_uninitialized(this.users);
|
||||
for (i = _i = 0, _ref = this.last_user + 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
|
||||
this.users.push(new Yatta(i, this.Connector));
|
||||
}
|
||||
return done();
|
||||
});
|
||||
return it("can handle many engines, many operations, concurrently (random)", function() {
|
||||
var Connector, applyRandomOp, doSomething, doSomething_amount, found_error, generateDeleteOp, generateInsertOp, generateRandomOp, generateReplaceOp, i, j, maximum_ops_per_engine, number_of_created_operations, number_of_engines, number_of_test_cases_multiplier, ops, ops_per_msek, printOpsInExecutionOrder, repeat_this, time_now, times, u, user, user_number, users, _i, _j, _k, _l, _len, _m, _ref, _results;
|
||||
number_of_test_cases_multiplier = 1;
|
||||
repeat_this = 1000 * number_of_test_cases_multiplier;
|
||||
doSomething_amount = 1000 * number_of_test_cases_multiplier;
|
||||
number_of_engines = 300 + number_of_test_cases_multiplier - 1;
|
||||
maximum_ops_per_engine = 20 * number_of_test_cases_multiplier;
|
||||
this.time = 0;
|
||||
this.ops = 0;
|
||||
generateInsertOp = function(user_num) {
|
||||
var chars, length, nextchar, pos, text;
|
||||
chars = "1234567890";
|
||||
pos = _.random(0, users[user_num].val().length - 1);
|
||||
length = 1;
|
||||
nextchar = chars[_.random(0, chars.length - 1)];
|
||||
text = "";
|
||||
_(length).times(function() {
|
||||
return text += nextchar;
|
||||
});
|
||||
users[user_num].insertText(pos, text);
|
||||
return null;
|
||||
};
|
||||
generateReplaceOp = function(user_num) {
|
||||
var chars, length, nextchar, text;
|
||||
chars = "abcdefghijklmnopqrstuvwxyz";
|
||||
length = _.random(0, 10);
|
||||
nextchar = chars[_.random(0, chars.length - 1)];
|
||||
text = "";
|
||||
_(length).times(function() {
|
||||
return text += nextchar;
|
||||
});
|
||||
return users[user_num].replaceText(text);
|
||||
};
|
||||
generateDeleteOp = function(user_num) {
|
||||
var length, ops1, pos;
|
||||
if (users[user_num].val().length > 0) {
|
||||
pos = _.random(0, users[user_num].val().length - 1);
|
||||
length = 1;
|
||||
ops1 = users[user_num].deleteText(pos, length);
|
||||
}
|
||||
return void 0;
|
||||
};
|
||||
generateRandomOp = function(user_num) {
|
||||
var i, op, op_gen;
|
||||
op_gen = [generateDeleteOp, generateInsertOp, generateReplaceOp];
|
||||
i = _.random(op_gen.length - 1);
|
||||
return op = op_gen[i](user_num);
|
||||
};
|
||||
applyRandomOp = function(user_num) {
|
||||
var user;
|
||||
user = users[user_num];
|
||||
return user.getConnector().flushOneRandom();
|
||||
};
|
||||
doSomething = (function() {
|
||||
return function() {
|
||||
var choice, choices, user_num;
|
||||
user_num = _.random(number_of_engines - 1);
|
||||
choices = [applyRandomOp, generateRandomOp];
|
||||
choice = _.random(choices.length - 1);
|
||||
return choices[choice](user_num);
|
||||
};
|
||||
})();
|
||||
console.log("");
|
||||
_results = [];
|
||||
for (times = _i = 1; 1 <= repeat_this ? _i <= repeat_this : _i >= repeat_this; times = 1 <= repeat_this ? ++_i : --_i) {
|
||||
users = [];
|
||||
Connector = Connector_uninitialized(users);
|
||||
for (i = _j = 0; 0 <= number_of_engines ? _j < number_of_engines : _j > number_of_engines; i = 0 <= number_of_engines ? ++_j : --_j) {
|
||||
users.push(new Yatta(i, Connector));
|
||||
}
|
||||
found_error = false;
|
||||
time_now = (new Date).getTime();
|
||||
for (i = _k = 1; 1 <= doSomething_amount ? _k <= doSomething_amount : _k >= doSomething_amount; i = 1 <= doSomething_amount ? ++_k : --_k) {
|
||||
doSomething();
|
||||
}
|
||||
for (user_number = _l = 0, _len = users.length; _l < _len; user_number = ++_l) {
|
||||
user = users[user_number];
|
||||
user.getConnector().flushAll();
|
||||
}
|
||||
this.time += (new Date()).getTime() - time_now;
|
||||
|
||||
/*catch error
|
||||
found_error = true
|
||||
console.log "Just found some error!!! :-)"
|
||||
console.log error
|
||||
*/
|
||||
number_of_created_operations = 0;
|
||||
for (i = _m = 0, _ref = users.length; 0 <= _ref ? _m < _ref : _m > _ref; i = 0 <= _ref ? ++_m : --_m) {
|
||||
number_of_created_operations += users[i].getConnector().getOpsInExecutionOrder().length;
|
||||
}
|
||||
this.ops += number_of_created_operations * users.length;
|
||||
ops_per_msek = Math.floor(this.ops / this.time);
|
||||
console.log(("" + times + "/" + repeat_this + ": Every collaborator (" + users.length + ") applied " + number_of_created_operations + " ops in a different order.") + (" Over all we consumed " + this.ops + " operations in " + (this.time / 1000) + " seconds (" + ops_per_msek + " ops/msek)."));
|
||||
console.log(users[0].val());
|
||||
_results.push((function() {
|
||||
var _len1, _n, _o, _ref1, _results1;
|
||||
_results1 = [];
|
||||
for (i = _n = 0, _ref1 = users.length - 1; 0 <= _ref1 ? _n < _ref1 : _n > _ref1; i = 0 <= _ref1 ? ++_n : --_n) {
|
||||
if (users[i].val() !== users[i + 1].val()) {
|
||||
printOpsInExecutionOrder = function(otnumber, otherotnumber) {
|
||||
var j, o, ops, s, _len1, _len2, _o, _p;
|
||||
ops = users[otnumber].getConnector().getOpsInExecutionOrder();
|
||||
for (_o = 0, _len1 = ops.length; _o < _len1; _o++) {
|
||||
s = ops[_o];
|
||||
console.log(JSON.stringify(s));
|
||||
}
|
||||
console.log("");
|
||||
s = "ops = [";
|
||||
for (j = _p = 0, _len2 = ops.length; _p < _len2; j = ++_p) {
|
||||
o = ops[j];
|
||||
if (j !== 0) {
|
||||
s += ", ";
|
||||
}
|
||||
s += "op" + j;
|
||||
}
|
||||
s += "]";
|
||||
console.log(s);
|
||||
console.log("@users[@last_user].ot.applyOps ops");
|
||||
console.log("expect(@users[@last_user].ot.val()).to.equal(\"" + (users[otherotnumber].val()) + "\")");
|
||||
return ops;
|
||||
};
|
||||
console.log("");
|
||||
console.log("Found an OT Puzzle!");
|
||||
console.log("OT states:");
|
||||
for (j = _o = 0, _len1 = users.length; _o < _len1; j = ++_o) {
|
||||
u = users[j];
|
||||
console.log(("OT" + j + ": ") + u.val());
|
||||
}
|
||||
console.log("\nOT execution order (" + i + "," + (i + 1) + "):");
|
||||
printOpsInExecutionOrder(i, i + 1);
|
||||
console.log("");
|
||||
ops = printOpsInExecutionOrder(i + 1, i);
|
||||
_results1.push(console.log(""));
|
||||
} else {
|
||||
_results1.push(void 0);
|
||||
}
|
||||
}
|
||||
return _results1;
|
||||
})());
|
||||
}
|
||||
return _results;
|
||||
});
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
Reference in New Issue
Block a user