devided ops/types
This commit is contained in:
parent
1aacc0e967
commit
792440a71d
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -2,11 +2,11 @@ var __slice = [].slice,
|
||||
__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; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
module.exports = function(HB) {
|
||||
var execution_listener, types;
|
||||
types = {};
|
||||
module.exports = function() {
|
||||
var execution_listener, ops;
|
||||
ops = {};
|
||||
execution_listener = [];
|
||||
types.Operation = (function() {
|
||||
ops.Operation = (function() {
|
||||
function Operation(uid) {
|
||||
this.is_deleted = false;
|
||||
this.garbage_collected = false;
|
||||
@ -37,7 +37,7 @@ module.exports = function(HB) {
|
||||
};
|
||||
|
||||
Operation.prototype["delete"] = function() {
|
||||
(new types.Delete(void 0, this)).execute();
|
||||
(new ops.Delete(void 0, this)).execute();
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -69,13 +69,13 @@ module.exports = function(HB) {
|
||||
this.is_deleted = true;
|
||||
if (garbagecollect) {
|
||||
this.garbage_collected = true;
|
||||
return HB.addToGarbageCollector(this);
|
||||
return this.HB.addToGarbageCollector(this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Operation.prototype.cleanup = function() {
|
||||
HB.removeOperation(this);
|
||||
this.HB.removeOperation(this);
|
||||
return this.deleteAllObservers();
|
||||
};
|
||||
|
||||
@ -117,10 +117,10 @@ module.exports = function(HB) {
|
||||
var l, _i, _len;
|
||||
this.is_executed = true;
|
||||
if (this.uid == null) {
|
||||
this.uid = HB.getNextOperationIdentifier();
|
||||
this.uid = this.HB.getNextOperationIdentifier();
|
||||
}
|
||||
if (this.uid.noOperation == null) {
|
||||
HB.addOperation(this);
|
||||
this.HB.addOperation(this);
|
||||
for (_i = 0, _len = execution_listener.length; _i < _len; _i++) {
|
||||
l = execution_listener[_i];
|
||||
l(this._encode());
|
||||
@ -149,7 +149,7 @@ module.exports = function(HB) {
|
||||
_ref = this.unchecked;
|
||||
for (name in _ref) {
|
||||
op_uid = _ref[name];
|
||||
op = HB.getOperation(op_uid);
|
||||
op = this.HB.getOperation(op_uid);
|
||||
if (op) {
|
||||
this[name] = op;
|
||||
} else {
|
||||
@ -167,7 +167,7 @@ module.exports = function(HB) {
|
||||
return Operation;
|
||||
|
||||
})();
|
||||
types.Delete = (function(_super) {
|
||||
ops.Delete = (function(_super) {
|
||||
__extends(Delete, _super);
|
||||
|
||||
function Delete(uid, deletes) {
|
||||
@ -200,13 +200,13 @@ module.exports = function(HB) {
|
||||
|
||||
return Delete;
|
||||
|
||||
})(types.Operation);
|
||||
types.Delete.parse = function(o) {
|
||||
})(ops.Operation);
|
||||
ops.Delete.parse = function(o) {
|
||||
var deletes_uid, uid;
|
||||
uid = o['uid'], deletes_uid = o['deletes'];
|
||||
return new this(uid, deletes_uid);
|
||||
};
|
||||
types.Insert = (function(_super) {
|
||||
ops.Insert = (function(_super) {
|
||||
__extends(Insert, _super);
|
||||
|
||||
function Insert(content, uid, prev_cl, next_cl, origin, parent) {
|
||||
@ -257,7 +257,7 @@ module.exports = function(HB) {
|
||||
if ((_ref = this.prev_cl) != null ? _ref.isDeleted() : void 0) {
|
||||
this.prev_cl.applyDelete();
|
||||
}
|
||||
if (this.content instanceof types.Operation) {
|
||||
if (this.content instanceof ops.Operation) {
|
||||
this.content.applyDelete();
|
||||
}
|
||||
return delete this.content;
|
||||
@ -303,7 +303,7 @@ module.exports = function(HB) {
|
||||
if (!this.validateSavedOperations()) {
|
||||
return false;
|
||||
} else {
|
||||
if (this.content instanceof types.Operation) {
|
||||
if (this.content instanceof ops.Operation) {
|
||||
this.content.insert_parent = this;
|
||||
}
|
||||
if (this.parent != null) {
|
||||
@ -389,7 +389,7 @@ module.exports = function(HB) {
|
||||
position = 0;
|
||||
prev = this.prev_cl;
|
||||
while (true) {
|
||||
if (prev instanceof types.Delimiter) {
|
||||
if (prev instanceof ops.Delimiter) {
|
||||
break;
|
||||
}
|
||||
if (!prev.isDeleted()) {
|
||||
@ -424,8 +424,8 @@ module.exports = function(HB) {
|
||||
|
||||
return Insert;
|
||||
|
||||
})(types.Operation);
|
||||
types.Insert.parse = function(json) {
|
||||
})(ops.Operation);
|
||||
ops.Insert.parse = function(json) {
|
||||
var content, next, origin, parent, prev, uid;
|
||||
content = json['content'], uid = json['uid'], prev = json['prev'], next = json['next'], origin = json['origin'], parent = json['parent'];
|
||||
if (typeof content === "string") {
|
||||
@ -433,7 +433,7 @@ module.exports = function(HB) {
|
||||
}
|
||||
return new this(content, uid, prev, next, origin, parent);
|
||||
};
|
||||
types.ImmutableObject = (function(_super) {
|
||||
ops.ImmutableObject = (function(_super) {
|
||||
__extends(ImmutableObject, _super);
|
||||
|
||||
function ImmutableObject(uid, _at_content) {
|
||||
@ -459,13 +459,13 @@ module.exports = function(HB) {
|
||||
|
||||
return ImmutableObject;
|
||||
|
||||
})(types.Operation);
|
||||
types.ImmutableObject.parse = function(json) {
|
||||
})(ops.Operation);
|
||||
ops.ImmutableObject.parse = function(json) {
|
||||
var content, uid;
|
||||
uid = json['uid'], content = json['content'];
|
||||
return new this(uid, content);
|
||||
};
|
||||
types.Delimiter = (function(_super) {
|
||||
ops.Delimiter = (function(_super) {
|
||||
__extends(Delimiter, _super);
|
||||
|
||||
function Delimiter(prev_cl, next_cl, origin) {
|
||||
@ -529,14 +529,14 @@ module.exports = function(HB) {
|
||||
|
||||
return Delimiter;
|
||||
|
||||
})(types.Operation);
|
||||
types.Delimiter.parse = function(json) {
|
||||
})(ops.Operation);
|
||||
ops.Delimiter.parse = function(json) {
|
||||
var next, prev, uid;
|
||||
uid = json['uid'], prev = json['prev'], next = json['next'];
|
||||
return new this(uid, prev, next);
|
||||
};
|
||||
return {
|
||||
'types': types,
|
||||
'operations': ops,
|
||||
'execution_listener': execution_listener
|
||||
};
|
||||
};
|
@ -1,14 +1,14 @@
|
||||
var text_types_uninitialized,
|
||||
var text_ops_uninitialized,
|
||||
__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; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
text_types_uninitialized = require("./TextTypes");
|
||||
text_ops_uninitialized = require("./Text");
|
||||
|
||||
module.exports = function(HB) {
|
||||
var text_types, types;
|
||||
text_types = text_types_uninitialized(HB);
|
||||
types = text_types.types;
|
||||
types.Object = (function(_super) {
|
||||
module.exports = function() {
|
||||
var ops, text_ops;
|
||||
text_ops = text_ops_uninitialized();
|
||||
ops = text_ops.operations;
|
||||
ops.Object = (function(_super) {
|
||||
__extends(Object, _super);
|
||||
|
||||
function Object() {
|
||||
@ -35,11 +35,11 @@ module.exports = function(HB) {
|
||||
json = {};
|
||||
for (name in val) {
|
||||
o = val[name];
|
||||
if (o instanceof types.Object) {
|
||||
if (o instanceof ops.Object) {
|
||||
json[name] = o.toJson(transform_to_value);
|
||||
} else if (o instanceof types.ListManager) {
|
||||
} else if (o instanceof ops.ListManager) {
|
||||
json[name] = o.toJson(transform_to_value);
|
||||
} else if (transform_to_value && o instanceof types.Operation) {
|
||||
} else if (transform_to_value && o instanceof ops.Operation) {
|
||||
json[name] = o.val();
|
||||
} else {
|
||||
json[name] = o;
|
||||
@ -66,7 +66,7 @@ module.exports = function(HB) {
|
||||
_results = [];
|
||||
for (_i = 0, _len = events.length; _i < _len; _i++) {
|
||||
event = events[_i];
|
||||
if (event.created_ !== HB.getUserId()) {
|
||||
if (event.created_ !== this.HB.getUserId()) {
|
||||
notifier = Object.getNotifier(that.bound_json);
|
||||
oldVal = that.bound_json[event.name];
|
||||
if (oldVal != null) {
|
||||
@ -107,7 +107,7 @@ module.exports = function(HB) {
|
||||
var args, i, o, type, _i, _ref;
|
||||
if ((name != null) && arguments.length > 1) {
|
||||
if ((content != null) && (content.constructor != null)) {
|
||||
type = types[content.constructor.name];
|
||||
type = ops[content.constructor.name];
|
||||
if ((type != null) && (type.create != null)) {
|
||||
args = [];
|
||||
for (i = _i = 1, _ref = arguments.length; 1 <= _ref ? _i < _ref : _i > _ref; i = 1 <= _ref ? ++_i : --_i) {
|
||||
@ -135,24 +135,24 @@ module.exports = function(HB) {
|
||||
|
||||
return Object;
|
||||
|
||||
})(types.MapManager);
|
||||
types.Object.parse = function(json) {
|
||||
})(ops.MapManager);
|
||||
ops.Object.parse = function(json) {
|
||||
var uid;
|
||||
uid = json['uid'];
|
||||
return new this(uid);
|
||||
};
|
||||
types.Object.create = function(content, mutable) {
|
||||
ops.Object.create = function(content, mutable) {
|
||||
var json, n, o;
|
||||
json = new types.Object().execute();
|
||||
json = new ops.Object().execute();
|
||||
for (n in content) {
|
||||
o = content[n];
|
||||
json.val(n, o, mutable);
|
||||
}
|
||||
return json;
|
||||
};
|
||||
types.Number = {};
|
||||
types.Number.create = function(content) {
|
||||
ops.Number = {};
|
||||
ops.Number.create = function(content) {
|
||||
return content;
|
||||
};
|
||||
return text_types;
|
||||
return text_ops;
|
||||
};
|
@ -1,14 +1,14 @@
|
||||
var basic_types_uninitialized,
|
||||
var basic_ops_uninitialized,
|
||||
__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; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
basic_types_uninitialized = require("./BasicTypes");
|
||||
basic_ops_uninitialized = require("./Basic");
|
||||
|
||||
module.exports = function(HB) {
|
||||
var basic_types, types;
|
||||
basic_types = basic_types_uninitialized(HB);
|
||||
types = basic_types.types;
|
||||
types.MapManager = (function(_super) {
|
||||
module.exports = function() {
|
||||
var basic_ops, ops;
|
||||
basic_ops = basic_ops_uninitialized();
|
||||
ops = basic_ops.operations;
|
||||
ops.MapManager = (function(_super) {
|
||||
__extends(MapManager, _super);
|
||||
|
||||
function MapManager(uid) {
|
||||
@ -77,7 +77,7 @@ module.exports = function(HB) {
|
||||
sub: property_name,
|
||||
alt: this
|
||||
};
|
||||
rm = new types.ReplaceManager(event_properties, event_this, rm_uid);
|
||||
rm = new ops.ReplaceManager(event_properties, event_this, rm_uid);
|
||||
this.map[property_name] = rm;
|
||||
rm.setParent(this, property_name);
|
||||
rm.execute();
|
||||
@ -87,13 +87,13 @@ module.exports = function(HB) {
|
||||
|
||||
return MapManager;
|
||||
|
||||
})(types.Operation);
|
||||
types.ListManager = (function(_super) {
|
||||
})(ops.Operation);
|
||||
ops.ListManager = (function(_super) {
|
||||
__extends(ListManager, _super);
|
||||
|
||||
function ListManager(uid) {
|
||||
this.beginning = new types.Delimiter(void 0, void 0);
|
||||
this.end = new types.Delimiter(this.beginning, void 0);
|
||||
this.beginning = new ops.Delimiter(void 0, void 0);
|
||||
this.end = new ops.Delimiter(this.beginning, void 0);
|
||||
this.beginning.next_cl = this.end;
|
||||
this.beginning.execute();
|
||||
this.end.execute();
|
||||
@ -125,11 +125,11 @@ module.exports = function(HB) {
|
||||
_results = [];
|
||||
for (o = _i = 0, _len = val.length; _i < _len; o = ++_i) {
|
||||
i = val[o];
|
||||
if (o instanceof types.Object) {
|
||||
if (o instanceof ops.Object) {
|
||||
_results.push(o.toJson(transform_to_value));
|
||||
} else if (o instanceof types.ListManager) {
|
||||
} else if (o instanceof ops.ListManager) {
|
||||
_results.push(o.toJson(transform_to_value));
|
||||
} else if (transform_to_value && o instanceof types.Operation) {
|
||||
} else if (transform_to_value && o instanceof ops.Operation) {
|
||||
_results.push(o.val());
|
||||
} else {
|
||||
_results.push(o);
|
||||
@ -198,7 +198,7 @@ module.exports = function(HB) {
|
||||
var o;
|
||||
if (pos != null) {
|
||||
o = this.getOperationByPosition(pos + 1);
|
||||
if (!(o instanceof types.Delimiter)) {
|
||||
if (!(o instanceof ops.Delimiter)) {
|
||||
return o.val();
|
||||
} else {
|
||||
throw new Error("this position does not exist");
|
||||
@ -212,7 +212,7 @@ module.exports = function(HB) {
|
||||
var o;
|
||||
o = this.beginning;
|
||||
while (true) {
|
||||
if (o instanceof types.Delimiter && (o.prev_cl != null)) {
|
||||
if (o instanceof ops.Delimiter && (o.prev_cl != null)) {
|
||||
o = o.prev_cl;
|
||||
while (o.isDeleted() && (o.prev_cl != null)) {
|
||||
o = o.prev_cl;
|
||||
@ -239,7 +239,7 @@ module.exports = function(HB) {
|
||||
createContent = function(content, options) {
|
||||
var type;
|
||||
if ((content != null) && (content.constructor != null)) {
|
||||
type = types[content.constructor.name];
|
||||
type = ops[content.constructor.name];
|
||||
if ((type != null) && (type.create != null)) {
|
||||
return type.create(content, options);
|
||||
} else {
|
||||
@ -254,12 +254,12 @@ module.exports = function(HB) {
|
||||
right = right.next_cl;
|
||||
}
|
||||
left = right.prev_cl;
|
||||
if (content instanceof types.Operation) {
|
||||
(new types.Insert(content, void 0, left, right)).execute();
|
||||
if (content instanceof ops.Operation) {
|
||||
(new ops.Insert(content, void 0, left, right)).execute();
|
||||
} else {
|
||||
for (_i = 0, _len = content.length; _i < _len; _i++) {
|
||||
c = content[_i];
|
||||
tmp = (new types.Insert(createContent(c, options), void 0, left, right)).execute();
|
||||
tmp = (new ops.Insert(createContent(c, options), void 0, left, right)).execute();
|
||||
left = tmp;
|
||||
}
|
||||
}
|
||||
@ -277,12 +277,12 @@ module.exports = function(HB) {
|
||||
o = this.getOperationByPosition(position + 1);
|
||||
delete_ops = [];
|
||||
for (i = _i = 0; 0 <= length ? _i < length : _i > length; i = 0 <= length ? ++_i : --_i) {
|
||||
if (o instanceof types.Delimiter) {
|
||||
if (o instanceof ops.Delimiter) {
|
||||
break;
|
||||
}
|
||||
d = (new types.Delete(void 0, o)).execute();
|
||||
d = (new ops.Delete(void 0, o)).execute();
|
||||
o = o.next_cl;
|
||||
while ((!(o instanceof types.Delimiter)) && o.isDeleted()) {
|
||||
while ((!(o instanceof ops.Delimiter)) && o.isDeleted()) {
|
||||
o = o.next_cl;
|
||||
}
|
||||
delete_ops.push(d._encode());
|
||||
@ -301,17 +301,17 @@ module.exports = function(HB) {
|
||||
|
||||
return ListManager;
|
||||
|
||||
})(types.Operation);
|
||||
types.ListManager.parse = function(json) {
|
||||
})(ops.Operation);
|
||||
ops.ListManager.parse = function(json) {
|
||||
var uid;
|
||||
uid = json['uid'];
|
||||
return new this(uid);
|
||||
};
|
||||
types.Array = function() {};
|
||||
types.Array.create = function(content, mutable) {
|
||||
ops.Array = function() {};
|
||||
ops.Array.create = function(content, mutable) {
|
||||
var ith, list;
|
||||
if (mutable === "mutable") {
|
||||
list = new types.ListManager().execute();
|
||||
list = new ops.ListManager().execute();
|
||||
ith = list.getOperationByPosition(0);
|
||||
list.insertAfter(ith, content);
|
||||
return list;
|
||||
@ -321,7 +321,7 @@ module.exports = function(HB) {
|
||||
throw new Error("Specify either \"mutable\" or \"immutable\"!!");
|
||||
}
|
||||
};
|
||||
types.ReplaceManager = (function(_super) {
|
||||
ops.ReplaceManager = (function(_super) {
|
||||
__extends(ReplaceManager, _super);
|
||||
|
||||
function ReplaceManager(_at_event_properties, _at_event_this, uid, beginning, end) {
|
||||
@ -368,7 +368,7 @@ module.exports = function(HB) {
|
||||
ReplaceManager.prototype.replace = function(content, replaceable_uid) {
|
||||
var o, relp;
|
||||
o = this.getLastOperation();
|
||||
relp = (new types.Replaceable(content, this, replaceable_uid, o, o.next_cl)).execute();
|
||||
relp = (new ops.Replaceable(content, this, replaceable_uid, o, o.next_cl)).execute();
|
||||
return void 0;
|
||||
};
|
||||
|
||||
@ -377,7 +377,7 @@ module.exports = function(HB) {
|
||||
};
|
||||
|
||||
ReplaceManager.prototype.deleteContent = function() {
|
||||
(new types.Delete(void 0, this.getLastOperation().uid)).execute();
|
||||
(new ops.Delete(void 0, this.getLastOperation().uid)).execute();
|
||||
return void 0;
|
||||
};
|
||||
|
||||
@ -400,8 +400,8 @@ module.exports = function(HB) {
|
||||
|
||||
return ReplaceManager;
|
||||
|
||||
})(types.ListManager);
|
||||
types.Replaceable = (function(_super) {
|
||||
})(ops.ListManager);
|
||||
ops.Replaceable = (function(_super) {
|
||||
__extends(Replaceable, _super);
|
||||
|
||||
function Replaceable(content, parent, uid, prev, next, origin, is_deleted) {
|
||||
@ -494,7 +494,7 @@ module.exports = function(HB) {
|
||||
} else if (this.origin !== this.prev_cl) {
|
||||
json.origin = this.origin.getUid();
|
||||
}
|
||||
if (this.content instanceof types.Operation) {
|
||||
if (this.content instanceof ops.Operation) {
|
||||
json['content'] = this.content.getUid();
|
||||
} else {
|
||||
if ((this.content != null) && (this.content.creator != null)) {
|
||||
@ -507,11 +507,11 @@ module.exports = function(HB) {
|
||||
|
||||
return Replaceable;
|
||||
|
||||
})(types.Insert);
|
||||
types.Replaceable.parse = function(json) {
|
||||
})(ops.Insert);
|
||||
ops.Replaceable.parse = function(json) {
|
||||
var content, is_deleted, next, origin, parent, prev, uid;
|
||||
content = json['content'], parent = json['parent'], uid = json['uid'], prev = json['prev'], next = json['next'], origin = json['origin'], is_deleted = json['is_deleted'];
|
||||
return new this(content, parent, uid, prev, next, origin, is_deleted);
|
||||
};
|
||||
return basic_types;
|
||||
return basic_ops;
|
||||
};
|
@ -1,15 +1,14 @@
|
||||
var structured_types_uninitialized,
|
||||
var structured_ops_uninitialized,
|
||||
__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; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
|
||||
structured_types_uninitialized = require("./StructuredTypes");
|
||||
structured_ops_uninitialized = require("./Structured");
|
||||
|
||||
module.exports = function(HB) {
|
||||
var parser, structured_types, types;
|
||||
structured_types = structured_types_uninitialized(HB);
|
||||
types = structured_types.types;
|
||||
parser = structured_types.parser;
|
||||
types.String = (function(_super) {
|
||||
module.exports = function() {
|
||||
var ops, structured_ops;
|
||||
structured_ops = structured_ops_uninitialized();
|
||||
ops = structured_ops.operations;
|
||||
ops.String = (function(_super) {
|
||||
__extends(String, _super);
|
||||
|
||||
function String(uid) {
|
||||
@ -300,16 +299,16 @@ module.exports = function(HB) {
|
||||
|
||||
return String;
|
||||
|
||||
})(types.ListManager);
|
||||
types.String.parse = function(json) {
|
||||
})(ops.ListManager);
|
||||
ops.String.parse = function(json) {
|
||||
var uid;
|
||||
uid = json['uid'];
|
||||
return new this(uid);
|
||||
};
|
||||
types.String.create = function(content, mutable) {
|
||||
ops.String.create = function(content, mutable) {
|
||||
var word;
|
||||
if (mutable === "mutable") {
|
||||
word = new types.String().execute();
|
||||
word = new ops.String().execute();
|
||||
word.insert(0, content);
|
||||
return word;
|
||||
} else if ((mutable == null) || (mutable === "immutable")) {
|
||||
@ -318,5 +317,5 @@ module.exports = function(HB) {
|
||||
throw new Error("Specify either \"mutable\" or \"immutable\"!!");
|
||||
}
|
||||
};
|
||||
return structured_types;
|
||||
return structured_ops;
|
||||
};
|
@ -1,8 +1,6 @@
|
||||
var Engine, HistoryBuffer, adaptConnector, createY, json_types_uninitialized,
|
||||
__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; },
|
||||
__hasProp = {}.hasOwnProperty;
|
||||
var Engine, HistoryBuffer, adaptConnector, createY, json_ops_uninitialized;
|
||||
|
||||
json_types_uninitialized = require("./Types/JsonTypes");
|
||||
json_ops_uninitialized = require("./Operations/Json");
|
||||
|
||||
HistoryBuffer = require("./HistoryBuffer");
|
||||
|
||||
@ -11,7 +9,7 @@ Engine = require("./Engine");
|
||||
adaptConnector = require("./ConnectorAdapter");
|
||||
|
||||
createY = function(connector) {
|
||||
var HB, Y, type_manager, types, user_id;
|
||||
var HB, engine, ops, ops_manager, user_id;
|
||||
user_id = null;
|
||||
if (connector.user_id != null) {
|
||||
user_id = connector.user_id;
|
||||
@ -23,28 +21,16 @@ createY = function(connector) {
|
||||
};
|
||||
}
|
||||
HB = new HistoryBuffer(user_id);
|
||||
type_manager = json_types_uninitialized(HB);
|
||||
types = type_manager.types;
|
||||
Y = (function(_super) {
|
||||
__extends(Y, _super);
|
||||
|
||||
function Y() {
|
||||
this.connector = connector;
|
||||
this.HB = HB;
|
||||
this.types = types;
|
||||
this.engine = new Engine(this.HB, type_manager.types);
|
||||
adaptConnector(this.connector, this.engine, this.HB, type_manager.execution_listener);
|
||||
Y.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
Y.prototype.getConnector = function() {
|
||||
return this.connector;
|
||||
};
|
||||
|
||||
return Y;
|
||||
|
||||
})(types.Object);
|
||||
return new Y(HB.getReservedUniqueIdentifier()).execute();
|
||||
ops_manager = json_ops_uninitialized(HB, this.constructor);
|
||||
ops = ops_manager.operations;
|
||||
engine = new Engine(HB, ops);
|
||||
adaptConnector(connector, engine, HB, ops_manager.execution_listener);
|
||||
ops.Operation.prototype.HB = HB;
|
||||
ops.Operation.prototype.operations = ops;
|
||||
ops.Operation.prototype.engine = engine;
|
||||
ops.Operation.prototype.connector = connector;
|
||||
ops.Operation.prototype.custom_ops = this.constructor;
|
||||
return new ops.Object(HB.getReservedUniqueIdentifier()).execute();
|
||||
};
|
||||
|
||||
module.exports = createY;
|
||||
|
29204
build/test/Json_test.js
29204
build/test/Json_test.js
File diff suppressed because one or more lines are too long
29203
build/test/Text_test.js
29203
build/test/Text_test.js
File diff suppressed because one or more lines are too long
@ -1,13 +1,13 @@
|
||||
module.exports = (HB)->
|
||||
module.exports = ()->
|
||||
# @see Engine.parse
|
||||
types = {}
|
||||
ops = {}
|
||||
execution_listener = []
|
||||
|
||||
#
|
||||
# @private
|
||||
# @abstract
|
||||
# @nodoc
|
||||
# A generic interface to operations.
|
||||
# A generic interface to ops.
|
||||
#
|
||||
# An operation has the following methods:
|
||||
# * _encode: encodes an operation (needed only if instance of this operation is sent).
|
||||
@ -16,7 +16,7 @@ module.exports = (HB)->
|
||||
#
|
||||
# Furthermore an encodable operation has a parser. We extend the parser object in order to parse encoded operations.
|
||||
#
|
||||
class types.Operation
|
||||
class ops.Operation
|
||||
|
||||
#
|
||||
# @param {Object} uid A unique identifier.
|
||||
@ -60,7 +60,7 @@ module.exports = (HB)->
|
||||
@event_listeners = []
|
||||
|
||||
delete: ()->
|
||||
(new types.Delete undefined, @).execute()
|
||||
(new ops.Delete undefined, @).execute()
|
||||
null
|
||||
|
||||
#
|
||||
@ -86,11 +86,11 @@ module.exports = (HB)->
|
||||
@is_deleted = true
|
||||
if garbagecollect
|
||||
@garbage_collected = true
|
||||
HB.addToGarbageCollector @
|
||||
@HB.addToGarbageCollector @
|
||||
|
||||
cleanup: ()->
|
||||
#console.log "cleanup: #{@type}"
|
||||
HB.removeOperation @
|
||||
@HB.removeOperation @
|
||||
@deleteAllObservers()
|
||||
|
||||
#
|
||||
@ -136,9 +136,9 @@ module.exports = (HB)->
|
||||
# When this operation was created without a uid, then set it here.
|
||||
# There is only one other place, where this can be done - before an Insertion
|
||||
# is executed (because we need the creator_id)
|
||||
@uid = HB.getNextOperationIdentifier()
|
||||
@uid = @HB.getNextOperationIdentifier()
|
||||
if not @uid.noOperation?
|
||||
HB.addOperation @
|
||||
@HB.addOperation @
|
||||
for l in execution_listener
|
||||
l @_encode()
|
||||
@
|
||||
@ -190,7 +190,7 @@ module.exports = (HB)->
|
||||
uninstantiated = {}
|
||||
success = @
|
||||
for name, op_uid of @unchecked
|
||||
op = HB.getOperation op_uid
|
||||
op = @HB.getOperation op_uid
|
||||
if op
|
||||
@[name] = op
|
||||
else
|
||||
@ -205,7 +205,7 @@ module.exports = (HB)->
|
||||
# @nodoc
|
||||
# A simple Delete-type operation that deletes an operation.
|
||||
#
|
||||
class types.Delete extends types.Operation
|
||||
class ops.Delete extends ops.Operation
|
||||
|
||||
#
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
@ -245,7 +245,7 @@ module.exports = (HB)->
|
||||
#
|
||||
# Define how to parse Delete operations.
|
||||
#
|
||||
types.Delete.parse = (o)->
|
||||
ops.Delete.parse = (o)->
|
||||
{
|
||||
'uid' : uid
|
||||
'deletes': deletes_uid
|
||||
@ -262,7 +262,7 @@ module.exports = (HB)->
|
||||
# - The short-list (abbrev. sl) maintains only the operations that are not deleted
|
||||
# - The complete-list (abbrev. cl) maintains all operations
|
||||
#
|
||||
class types.Insert extends types.Operation
|
||||
class ops.Insert extends ops.Operation
|
||||
|
||||
#
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
@ -314,7 +314,7 @@ module.exports = (HB)->
|
||||
@prev_cl.applyDelete()
|
||||
|
||||
# delete content
|
||||
if @content instanceof types.Operation
|
||||
if @content instanceof ops.Operation
|
||||
@content.applyDelete()
|
||||
delete @content
|
||||
|
||||
@ -361,7 +361,7 @@ module.exports = (HB)->
|
||||
if not @validateSavedOperations()
|
||||
return false
|
||||
else
|
||||
if @content instanceof types.Operation
|
||||
if @content instanceof ops.Operation
|
||||
@content.insert_parent = @ # TODO: this is probably not necessary and only nice for debugging
|
||||
if @parent?
|
||||
if not @prev_cl?
|
||||
@ -450,7 +450,7 @@ module.exports = (HB)->
|
||||
position = 0
|
||||
prev = @prev_cl
|
||||
while true
|
||||
if prev instanceof types.Delimiter
|
||||
if prev instanceof ops.Delimiter
|
||||
break
|
||||
if not prev.isDeleted()
|
||||
position++
|
||||
@ -482,7 +482,7 @@ module.exports = (HB)->
|
||||
json['content'] = JSON.stringify @content
|
||||
json
|
||||
|
||||
types.Insert.parse = (json)->
|
||||
ops.Insert.parse = (json)->
|
||||
{
|
||||
'content' : content
|
||||
'uid' : uid
|
||||
@ -501,7 +501,7 @@ module.exports = (HB)->
|
||||
# @nodoc
|
||||
# Defines an object that is cannot be changed. You can use this to set an immutable string, or a number.
|
||||
#
|
||||
class types.ImmutableObject extends types.Operation
|
||||
class ops.ImmutableObject extends ops.Operation
|
||||
|
||||
#
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
@ -529,7 +529,7 @@ module.exports = (HB)->
|
||||
}
|
||||
json
|
||||
|
||||
types.ImmutableObject.parse = (json)->
|
||||
ops.ImmutableObject.parse = (json)->
|
||||
{
|
||||
'uid' : uid
|
||||
'content' : content
|
||||
@ -542,7 +542,7 @@ module.exports = (HB)->
|
||||
# This is necessary in order to have a beginning and an end even if the content
|
||||
# of the Engine is empty.
|
||||
#
|
||||
class types.Delimiter extends types.Operation
|
||||
class ops.Delimiter extends ops.Operation
|
||||
#
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
# @param {Operation} prev_cl The predecessor of this operation in the complete-list (cl)
|
||||
@ -601,7 +601,7 @@ module.exports = (HB)->
|
||||
'next' : @next_cl?.getUid()
|
||||
}
|
||||
|
||||
types.Delimiter.parse = (json)->
|
||||
ops.Delimiter.parse = (json)->
|
||||
{
|
||||
'uid' : uid
|
||||
'prev' : prev
|
||||
@ -611,7 +611,7 @@ module.exports = (HB)->
|
||||
|
||||
# This is what this module exports after initializing it with the HistoryBuffer
|
||||
{
|
||||
'types' : types
|
||||
'operations' : ops
|
||||
'execution_listener' : execution_listener
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
text_types_uninitialized = require "./TextTypes"
|
||||
text_ops_uninitialized = require "./Text"
|
||||
|
||||
module.exports = (HB)->
|
||||
text_types = text_types_uninitialized HB
|
||||
types = text_types.types
|
||||
module.exports = ()->
|
||||
text_ops = text_ops_uninitialized()
|
||||
ops = text_ops.operations
|
||||
|
||||
#
|
||||
# Manages Object-like values.
|
||||
#
|
||||
class types.Object extends types.MapManager
|
||||
class ops.Object extends ops.MapManager
|
||||
|
||||
#
|
||||
# Identifies this class.
|
||||
@ -40,11 +40,11 @@ module.exports = (HB)->
|
||||
val = @val()
|
||||
json = {}
|
||||
for name, o of val
|
||||
if o instanceof types.Object
|
||||
if o instanceof ops.Object
|
||||
json[name] = o.toJson(transform_to_value)
|
||||
else if o instanceof types.ListManager
|
||||
else if o instanceof ops.ListManager
|
||||
json[name] = o.toJson(transform_to_value)
|
||||
else if transform_to_value and o instanceof types.Operation
|
||||
else if transform_to_value and o instanceof ops.Operation
|
||||
json[name] = o.val()
|
||||
else
|
||||
json[name] = o
|
||||
@ -58,7 +58,7 @@ module.exports = (HB)->
|
||||
that.val(event.name, event.object[event.name])
|
||||
@observe (events)->
|
||||
for event in events
|
||||
if event.created_ isnt HB.getUserId()
|
||||
if event.created_ isnt @HB.getUserId()
|
||||
notifier = Object.getNotifier(that.bound_json)
|
||||
oldVal = that.bound_json[event.name]
|
||||
if oldVal?
|
||||
@ -102,7 +102,7 @@ module.exports = (HB)->
|
||||
val: (name, content)->
|
||||
if name? and arguments.length > 1
|
||||
if content? and content.constructor?
|
||||
type = types[content.constructor.name]
|
||||
type = ops[content.constructor.name]
|
||||
if type? and type.create?
|
||||
args = []
|
||||
for i in [1...arguments.length]
|
||||
@ -125,23 +125,23 @@ module.exports = (HB)->
|
||||
'uid' : @getUid()
|
||||
}
|
||||
|
||||
types.Object.parse = (json)->
|
||||
ops.Object.parse = (json)->
|
||||
{
|
||||
'uid' : uid
|
||||
} = json
|
||||
new this(uid)
|
||||
|
||||
types.Object.create = (content, mutable)->
|
||||
json = new types.Object().execute()
|
||||
ops.Object.create = (content, mutable)->
|
||||
json = new ops.Object().execute()
|
||||
for n,o of content
|
||||
json.val n, o, mutable
|
||||
json
|
||||
|
||||
|
||||
types.Number = {}
|
||||
types.Number.create = (content)->
|
||||
ops.Number = {}
|
||||
ops.Number.create = (content)->
|
||||
content
|
||||
|
||||
text_types
|
||||
text_ops
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
basic_types_uninitialized = require "./BasicTypes"
|
||||
basic_ops_uninitialized = require "./Basic"
|
||||
|
||||
module.exports = (HB)->
|
||||
basic_types = basic_types_uninitialized HB
|
||||
types = basic_types.types
|
||||
module.exports = ()->
|
||||
basic_ops = basic_ops_uninitialized()
|
||||
ops = basic_ops.operations
|
||||
|
||||
#
|
||||
# @nodoc
|
||||
# Manages map like objects. E.g. Json-Type and XML attributes.
|
||||
#
|
||||
class types.MapManager extends types.Operation
|
||||
class ops.MapManager extends ops.Operation
|
||||
|
||||
#
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
@ -28,7 +28,7 @@ module.exports = (HB)->
|
||||
super()
|
||||
|
||||
#
|
||||
# @see JsonTypes.val
|
||||
# @see JsonOperations.val
|
||||
#
|
||||
val: (name, content)->
|
||||
if arguments.length > 1
|
||||
@ -60,7 +60,7 @@ module.exports = (HB)->
|
||||
noOperation: true
|
||||
sub: property_name
|
||||
alt: @
|
||||
rm = new types.ReplaceManager event_properties, event_this, rm_uid # this operation shall not be saved in the HB
|
||||
rm = new ops.ReplaceManager event_properties, event_this, rm_uid # this operation shall not be saved in the HB
|
||||
@map[property_name] = rm
|
||||
rm.setParent @, property_name
|
||||
rm.execute()
|
||||
@ -70,7 +70,7 @@ module.exports = (HB)->
|
||||
# @nodoc
|
||||
# Manages a list of Insert-type operations.
|
||||
#
|
||||
class types.ListManager extends types.Operation
|
||||
class ops.ListManager extends ops.Operation
|
||||
|
||||
#
|
||||
# A ListManager maintains a non-empty list that has a beginning and an end (both Delimiters!)
|
||||
@ -78,8 +78,8 @@ module.exports = (HB)->
|
||||
# @param {Delimiter} beginning Reference or Object.
|
||||
# @param {Delimiter} end Reference or Object.
|
||||
constructor: (uid)->
|
||||
@beginning = new types.Delimiter undefined, undefined
|
||||
@end = new types.Delimiter @beginning, undefined
|
||||
@beginning = new ops.Delimiter undefined, undefined
|
||||
@end = new ops.Delimiter @beginning, undefined
|
||||
@beginning.next_cl = @end
|
||||
@beginning.execute()
|
||||
@end.execute()
|
||||
@ -100,11 +100,11 @@ module.exports = (HB)->
|
||||
toJson: (transform_to_value = false)->
|
||||
val = @val()
|
||||
for i, o in val
|
||||
if o instanceof types.Object
|
||||
if o instanceof ops.Object
|
||||
o.toJson(transform_to_value)
|
||||
else if o instanceof types.ListManager
|
||||
else if o instanceof ops.ListManager
|
||||
o.toJson(transform_to_value)
|
||||
else if transform_to_value and o instanceof types.Operation
|
||||
else if transform_to_value and o instanceof ops.Operation
|
||||
o.val()
|
||||
else
|
||||
o
|
||||
@ -160,7 +160,7 @@ module.exports = (HB)->
|
||||
val: (pos)->
|
||||
if pos?
|
||||
o = @getOperationByPosition(pos+1)
|
||||
if not (o instanceof types.Delimiter)
|
||||
if not (o instanceof ops.Delimiter)
|
||||
o.val()
|
||||
else
|
||||
throw new Error "this position does not exist"
|
||||
@ -177,7 +177,7 @@ module.exports = (HB)->
|
||||
o = @beginning
|
||||
while true
|
||||
# find the i-th op
|
||||
if o instanceof types.Delimiter and o.prev_cl?
|
||||
if o instanceof ops.Delimiter and o.prev_cl?
|
||||
# the user or you gave a position parameter that is to big
|
||||
# for the current array. Therefore we reach a Delimiter.
|
||||
# Then, we'll just return the last character.
|
||||
@ -199,7 +199,7 @@ module.exports = (HB)->
|
||||
insertAfter: (left, content, options)->
|
||||
createContent = (content, options)->
|
||||
if content? and content.constructor?
|
||||
type = types[content.constructor.name]
|
||||
type = ops[content.constructor.name]
|
||||
if type? and type.create?
|
||||
type.create content, options
|
||||
else
|
||||
@ -212,11 +212,11 @@ module.exports = (HB)->
|
||||
right = right.next_cl # find the first character to the right, that is not deleted. In the case that position is 0, its the Delimiter.
|
||||
left = right.prev_cl
|
||||
|
||||
if content instanceof types.Operation
|
||||
(new types.Insert content, undefined, left, right).execute()
|
||||
if content instanceof ops.Operation
|
||||
(new ops.Insert content, undefined, left, right).execute()
|
||||
else
|
||||
for c in content
|
||||
tmp = (new types.Insert createContent(c, options), undefined, left, right).execute()
|
||||
tmp = (new ops.Insert createContent(c, options), undefined, left, right).execute()
|
||||
left = tmp
|
||||
@
|
||||
|
||||
@ -241,11 +241,11 @@ module.exports = (HB)->
|
||||
|
||||
delete_ops = []
|
||||
for i in [0...length]
|
||||
if o instanceof types.Delimiter
|
||||
if o instanceof ops.Delimiter
|
||||
break
|
||||
d = (new types.Delete undefined, o).execute()
|
||||
d = (new ops.Delete undefined, o).execute()
|
||||
o = o.next_cl
|
||||
while (not (o instanceof types.Delimiter)) and o.isDeleted()
|
||||
while (not (o instanceof ops.Delimiter)) and o.isDeleted()
|
||||
o = o.next_cl
|
||||
delete_ops.push d._encode()
|
||||
@
|
||||
@ -261,16 +261,16 @@ module.exports = (HB)->
|
||||
}
|
||||
json
|
||||
|
||||
types.ListManager.parse = (json)->
|
||||
ops.ListManager.parse = (json)->
|
||||
{
|
||||
'uid' : uid
|
||||
} = json
|
||||
new this(uid)
|
||||
|
||||
types.Array = ()->
|
||||
types.Array.create = (content, mutable)->
|
||||
ops.Array = ()->
|
||||
ops.Array.create = (content, mutable)->
|
||||
if (mutable is "mutable")
|
||||
list = new types.ListManager().execute()
|
||||
list = new ops.ListManager().execute()
|
||||
ith = list.getOperationByPosition 0
|
||||
list.insertAfter ith, content
|
||||
list
|
||||
@ -288,7 +288,7 @@ module.exports = (HB)->
|
||||
# The TextType-type has implemented support for replace
|
||||
# @see TextType
|
||||
#
|
||||
class types.ReplaceManager extends types.ListManager
|
||||
class ops.ReplaceManager extends ops.ListManager
|
||||
#
|
||||
# @param {Object} event_properties Decorates the event that is thrown by the RM
|
||||
# @param {Object} event_this The object on which the event shall be executed
|
||||
@ -336,7 +336,7 @@ module.exports = (HB)->
|
||||
#
|
||||
replace: (content, replaceable_uid)->
|
||||
o = @getLastOperation()
|
||||
relp = (new types.Replaceable content, @, replaceable_uid, o, o.next_cl).execute()
|
||||
relp = (new ops.Replaceable content, @, replaceable_uid, o, o.next_cl).execute()
|
||||
# TODO: delete repl (for debugging)
|
||||
undefined
|
||||
|
||||
@ -344,7 +344,7 @@ module.exports = (HB)->
|
||||
@getLastOperation().isDeleted()
|
||||
|
||||
deleteContent: ()->
|
||||
(new types.Delete undefined, @getLastOperation().uid).execute()
|
||||
(new ops.Delete undefined, @getLastOperation().uid).execute()
|
||||
undefined
|
||||
|
||||
#
|
||||
@ -353,7 +353,7 @@ module.exports = (HB)->
|
||||
#
|
||||
val: ()->
|
||||
o = @getLastOperation()
|
||||
#if o instanceof types.Delimiter
|
||||
#if o instanceof ops.Delimiter
|
||||
# throw new Error "Replace Manager doesn't contain anything."
|
||||
o.val?() # ? - for the case that (currently) the RM does not contain anything (then o is a Delimiter)
|
||||
|
||||
@ -375,7 +375,7 @@ module.exports = (HB)->
|
||||
# The ReplaceManager manages Replaceables.
|
||||
# @see ReplaceManager
|
||||
#
|
||||
class types.Replaceable extends types.Insert
|
||||
class ops.Replaceable extends ops.Insert
|
||||
|
||||
#
|
||||
# @param {Operation} content The value that this Replaceable holds.
|
||||
@ -411,7 +411,7 @@ module.exports = (HB)->
|
||||
#
|
||||
# This is called, when the Insert-type was successfully executed.
|
||||
# TODO: consider doing this in a more consistent manner. This could also be
|
||||
# done with execute. But currently, there are no specital Insert-types for ListManager.
|
||||
# done with execute. But currently, there are no specital Insert-ops for ListManager.
|
||||
#
|
||||
callOperationSpecificInsertEvents: ()->
|
||||
if @next_cl.type is "Delimiter" and @prev_cl.type isnt "Delimiter"
|
||||
@ -461,7 +461,7 @@ module.exports = (HB)->
|
||||
else if @origin isnt @prev_cl
|
||||
json.origin = @origin.getUid()
|
||||
|
||||
if @content instanceof types.Operation
|
||||
if @content instanceof ops.Operation
|
||||
json['content'] = @content.getUid()
|
||||
else
|
||||
# This could be a security concern.
|
||||
@ -471,7 +471,7 @@ module.exports = (HB)->
|
||||
json['content'] = @content
|
||||
json
|
||||
|
||||
types.Replaceable.parse = (json)->
|
||||
ops.Replaceable.parse = (json)->
|
||||
{
|
||||
'content' : content
|
||||
'parent' : parent
|
||||
@ -484,7 +484,7 @@ module.exports = (HB)->
|
||||
new this(content, parent, uid, prev, next, origin, is_deleted)
|
||||
|
||||
|
||||
basic_types
|
||||
basic_ops
|
||||
|
||||
|
||||
|
@ -1,15 +1,14 @@
|
||||
structured_types_uninitialized = require "./StructuredTypes"
|
||||
structured_ops_uninitialized = require "./Structured"
|
||||
|
||||
module.exports = (HB)->
|
||||
structured_types = structured_types_uninitialized HB
|
||||
types = structured_types.types
|
||||
parser = structured_types.parser
|
||||
module.exports = ()->
|
||||
structured_ops = structured_ops_uninitialized()
|
||||
ops = structured_ops.operations
|
||||
|
||||
#
|
||||
# Handles a String-like data structures with support for insert/delete at a word-position.
|
||||
# @note Currently, only Text is supported!
|
||||
#
|
||||
class types.String extends types.ListManager
|
||||
class ops.String extends ops.ListManager
|
||||
|
||||
#
|
||||
# @private
|
||||
@ -287,15 +286,15 @@ module.exports = (HB)->
|
||||
}
|
||||
json
|
||||
|
||||
types.String.parse = (json)->
|
||||
ops.String.parse = (json)->
|
||||
{
|
||||
'uid' : uid
|
||||
} = json
|
||||
new this(uid)
|
||||
|
||||
types.String.create = (content, mutable)->
|
||||
ops.String.create = (content, mutable)->
|
||||
if (mutable is "mutable")
|
||||
word = new types.String().execute()
|
||||
word = new ops.String().execute()
|
||||
word.insert 0, content
|
||||
word
|
||||
else if (not mutable?) or (mutable is "immutable")
|
||||
@ -304,6 +303,6 @@ module.exports = (HB)->
|
||||
throw new Error "Specify either \"mutable\" or \"immutable\"!!"
|
||||
|
||||
|
||||
structured_types
|
||||
structured_ops
|
||||
|
||||
|
38
lib/y.coffee
38
lib/y.coffee
@ -1,5 +1,6 @@
|
||||
|
||||
json_types_uninitialized = require "./Types/JsonTypes"
|
||||
json_ops_uninitialized = require "./Operations/Json"
|
||||
|
||||
HistoryBuffer = require "./HistoryBuffer"
|
||||
Engine = require "./Engine"
|
||||
adaptConnector = require "./ConnectorAdapter"
|
||||
@ -14,34 +15,19 @@ createY = (connector)->
|
||||
user_id = id
|
||||
HB.resetUserId id
|
||||
HB = new HistoryBuffer user_id
|
||||
type_manager = json_types_uninitialized HB
|
||||
types = type_manager.types
|
||||
ops_manager = json_ops_uninitialized HB, this.constructor
|
||||
ops = ops_manager.operations
|
||||
|
||||
#
|
||||
# Framework for Json data-structures.
|
||||
# Known values that are supported:
|
||||
# * String
|
||||
# * Integer
|
||||
# * Array
|
||||
#
|
||||
class Y extends types.Object
|
||||
engine = new Engine HB, ops
|
||||
adaptConnector connector, engine, HB, ops_manager.execution_listener
|
||||
|
||||
#
|
||||
# @param {String} user_id Unique id of the peer.
|
||||
# @param {Connector} Connector the connector class.
|
||||
#
|
||||
constructor: ()->
|
||||
@connector = connector
|
||||
@HB = HB
|
||||
@types = types
|
||||
@engine = new Engine @HB, type_manager.types
|
||||
adaptConnector @connector, @engine, @HB, type_manager.execution_listener
|
||||
super
|
||||
ops.Operation.prototype.HB = HB
|
||||
ops.Operation.prototype.operations = ops
|
||||
ops.Operation.prototype.engine = engine
|
||||
ops.Operation.prototype.connector = connector
|
||||
ops.Operation.prototype.custom_ops = this.constructor
|
||||
|
||||
getConnector: ()->
|
||||
@connector
|
||||
|
||||
return new Y(HB.getReservedUniqueIdentifier()).execute()
|
||||
return new ops.Object(HB.getReservedUniqueIdentifier()).execute()
|
||||
|
||||
module.exports = createY
|
||||
if window? and not window.Y?
|
||||
|
@ -48,7 +48,7 @@ class JsonTest extends Test
|
||||
@users[user_num].toJson(true)
|
||||
|
||||
getGeneratingFunctions: (user_num)->
|
||||
types = @users[user_num].types
|
||||
types = @users[user_num].operations
|
||||
super(user_num).concat [
|
||||
f : (y)=> # SET PROPERTY
|
||||
l = y.val().length
|
||||
|
@ -28,7 +28,7 @@ module.exports = class Test
|
||||
for i in [0...@number_of_engines]
|
||||
u = @makeNewUser (i+@name_suffix)
|
||||
for user in @users
|
||||
u.getConnector().join(user.getConnector()) # TODO: change the test-connector to make this more convenient
|
||||
u.connector.join(user.connector) # TODO: change the test-connector to make this more convenient
|
||||
@users.push u
|
||||
@initUsers?(@users[0])
|
||||
@flushAll()
|
||||
@ -69,7 +69,7 @@ module.exports = class Test
|
||||
@getRandomText [1,2,'x','y'], 1 # only 4 keys
|
||||
|
||||
getGeneratingFunctions: (user_num)=>
|
||||
types = @users[user_num].types
|
||||
types = @users[user_num].operations
|
||||
[
|
||||
f : (y)=> # INSERT TEXT
|
||||
y
|
||||
@ -106,7 +106,7 @@ module.exports = class Test
|
||||
|
||||
applyRandomOp: (user_num)=>
|
||||
user = @users[user_num]
|
||||
user.getConnector().flushOneRandom()
|
||||
user.connector.flushOneRandom()
|
||||
|
||||
doSomething: ()->
|
||||
user_num = _.random (@number_of_engines-1)
|
||||
@ -119,10 +119,10 @@ module.exports = class Test
|
||||
final = false
|
||||
if @users.length <= 1 or not final
|
||||
for user,user_number in @users
|
||||
user.getConnector().flushAll()
|
||||
user.connector.flushAll()
|
||||
else
|
||||
for user,user_number in @users[1..]
|
||||
user.getConnector().flushAll()
|
||||
user.connector.flushAll()
|
||||
ops = @users[1].getHistoryBuffer()._encode @users[0].HB.getOperationCounter()
|
||||
@users[0].engine.applyOpsCheckDouble ops
|
||||
|
||||
@ -135,7 +135,7 @@ module.exports = class Test
|
||||
|
||||
number_of_created_operations = 0
|
||||
for i in [0...(@users.length)]
|
||||
number_of_created_operations += @users[i].getConnector().getOpsInExecutionOrder().length
|
||||
number_of_created_operations += @users[i].connector.getOpsInExecutionOrder().length
|
||||
@ops += number_of_created_operations*@users.length
|
||||
|
||||
ops_per_msek = Math.floor(@ops/@time)
|
||||
@ -146,7 +146,7 @@ module.exports = class Test
|
||||
if @debug
|
||||
if not _.isEqual @getContent(i), @getContent(i+1)
|
||||
printOpsInExecutionOrder = (otnumber, otherotnumber)=>
|
||||
ops = _.filter @users[otnumber].getConnector().getOpsInExecutionOrder(), (o)->
|
||||
ops = _.filter @users[otnumber].connector.getOpsInExecutionOrder(), (o)->
|
||||
typeof o.uid.op_name isnt 'string' and o.uid.creator isnt '_'
|
||||
for s,j in ops
|
||||
console.log "op#{j} = " + (JSON.stringify s)
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user