broke the dammn thing

This commit is contained in:
DadaMonad
2015-02-19 15:55:05 +00:00
parent 792440a71d
commit 860934de06
17 changed files with 1098 additions and 1016 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -164,6 +164,17 @@ module.exports = function() {
return success;
};
Operation.prototype.getCustomType = function() {
if (this.custom_type == null) {
throw new Error("This operation was not initialized with a custom type");
}
if (this.custom_type.constructor === String) {
this.custom_type = new this.custom_types[this.custom_type]();
this.custom_type._setModel(this);
}
return this.custom_type;
};
return Operation;
})();

View File

@@ -11,8 +11,11 @@ module.exports = function() {
ops.MapManager = (function(_super) {
__extends(MapManager, _super);
function MapManager(uid) {
this.map = {};
function MapManager(custom_type, uid) {
if (custom_type != null) {
this.custom_type = custom_type;
}
this._map = {};
MapManager.__super__.constructor.call(this, uid);
}
@@ -20,7 +23,7 @@ module.exports = function() {
MapManager.prototype.applyDelete = function() {
var name, p, _ref;
_ref = this.map;
_ref = this._map;
for (name in _ref) {
p = _ref[name];
p.applyDelete();
@@ -32,25 +35,50 @@ module.exports = function() {
return MapManager.__super__.cleanup.call(this);
};
MapManager.prototype.map = function(f) {
var n, v, _ref;
_ref = this._map;
for (n in _ref) {
v = _ref[n];
f(n, v);
}
return void 0;
};
MapManager.prototype.val = function(name, content) {
var o, prop, result, _ref;
var o, prop, rep, res, result, _ref;
if (arguments.length > 1) {
this.retrieveSub(name).replace(content);
if ((content != null) && (content._model != null) && content._model instanceof ops.Operation) {
rep = content._model;
} else {
rep = content;
}
this.retrieveSub(name).replace(rep);
return this;
} else if (name != null) {
prop = this.map[name];
prop = this._map[name];
if ((prop != null) && !prop.isContentDeleted()) {
return prop.val();
res = prop.val();
if (res instanceof ops.Operation) {
return res.getCustomType();
} else {
return res;
}
} else {
return void 0;
}
} else {
result = {};
_ref = this.map;
_ref = this._map;
for (name in _ref) {
o = _ref[name];
if (!o.isContentDeleted()) {
result[name] = o.val();
res = prop.val();
if (res instanceof ops.Operation) {
result[name] = res.getCustomType();
} else {
result[name] = res;
}
}
}
return result;
@@ -59,7 +87,7 @@ module.exports = function() {
MapManager.prototype["delete"] = function(name) {
var _ref;
if ((_ref = this.map[name]) != null) {
if ((_ref = this._map[name]) != null) {
_ref.deleteContent();
}
return this;
@@ -67,7 +95,7 @@ module.exports = function() {
MapManager.prototype.retrieveSub = function(property_name) {
var event_properties, event_this, rm, rm_uid;
if (this.map[property_name] == null) {
if (this._map[property_name] == null) {
event_properties = {
name: property_name
};
@@ -78,16 +106,35 @@ module.exports = function() {
alt: this
};
rm = new ops.ReplaceManager(event_properties, event_this, rm_uid);
this.map[property_name] = rm;
this._map[property_name] = rm;
rm.setParent(this, property_name);
rm.execute();
}
return this.map[property_name];
return this._map[property_name];
};
MapManager.prototype._encode = function() {
var json;
json = {
'type': this.type,
'uid': this.getUid()
};
if (this.custom_type.constructor === String) {
json.custom_type = this.custom_type;
} else {
json.custom_type = this.custom_type._name;
}
return json;
};
return MapManager;
})(ops.Operation);
ops.MapManager.parse = function(json) {
var custom_type, uid;
uid = json['uid'], custom_type = json['custom_type'];
return new this(custom_type, uid);
};
ops.ListManager = (function(_super) {
__extends(ListManager, _super);
@@ -413,7 +460,11 @@ module.exports = function() {
Replaceable.prototype.type = "Replaceable";
Replaceable.prototype.val = function() {
return this.content;
if ((this.content != null) && (this.content.getCustomType != null)) {
return this.content.getCustomType();
} else {
return this.content;
}
};
Replaceable.prototype.applyDelete = function() {

View File

@@ -0,0 +1,80 @@
var YObject;
YObject = (function() {
function YObject(_at__object) {
var name, val, _ref;
this._object = _at__object != null ? _at__object : {};
if (this._object.constructor === Object) {
_ref = this._object;
for (name in _ref) {
val = _ref[name];
if (val.constructor === Object) {
this._object[name] = new YObject(val);
}
}
} else {
throw new Error("Y.Object accepts Json Objects only");
}
}
YObject.prototype._name = "Object";
YObject.prototype._getModel = function(types, ops) {
var n, o, _ref;
if (this._model == null) {
this._model = new ops.MapManager(this).execute();
_ref = this._object;
for (n in _ref) {
o = _ref[n];
this._model.val(n, o);
}
}
delete this._object;
return this._model;
};
YObject.prototype._setModel = function(_at__model) {
this._model = _at__model;
return delete this._object;
};
YObject.prototype.observe = function(f) {
return this._model.observe(f);
};
YObject.prototype.val = function(name, content) {
var n, res, v, _ref;
if (this._model != null) {
return this._model.val.apply(this._model, arguments);
} else {
if (content != null) {
return this._object[name] = content;
} else if (name != null) {
return this._object[name];
} else {
res = {};
_ref = this._object;
for (n in _ref) {
v = _ref[n];
res[n] = v;
}
return res;
}
}
};
return YObject;
})();
if (typeof window !== "undefined" && window !== null) {
if (window.Y != null) {
window.Y.Object = YObject;
} else {
throw new Error("You must first import Y!");
}
}
if (typeof module !== "undefined" && module !== null) {
module.exports = YObject;
}

View File

@@ -1,6 +1,6 @@
var Engine, HistoryBuffer, adaptConnector, createY, json_ops_uninitialized;
var Engine, HistoryBuffer, adaptConnector, createY, text_ops_uninitialized;
json_ops_uninitialized = require("./Operations/Json");
text_ops_uninitialized = require("./Operations/Text");
HistoryBuffer = require("./HistoryBuffer");
@@ -9,7 +9,7 @@ Engine = require("./Engine");
adaptConnector = require("./ConnectorAdapter");
createY = function(connector) {
var HB, engine, ops, ops_manager, user_id;
var HB, ct, engine, model, ops, ops_manager, user_id;
user_id = null;
if (connector.user_id != null) {
user_id = connector.user_id;
@@ -21,7 +21,7 @@ createY = function(connector) {
};
}
HB = new HistoryBuffer(user_id);
ops_manager = json_ops_uninitialized(HB, this.constructor);
ops_manager = text_ops_uninitialized(HB, this.constructor);
ops = ops_manager.operations;
engine = new Engine(HB, ops);
adaptConnector(connector, engine, HB, ops_manager.execution_listener);
@@ -30,11 +30,16 @@ createY = function(connector) {
ops.Operation.prototype.engine = engine;
ops.Operation.prototype.connector = connector;
ops.Operation.prototype.custom_ops = this.constructor;
return new ops.Object(HB.getReservedUniqueIdentifier()).execute();
ct = new createY.Object();
model = new ops.MapManager(ct, HB.getReservedUniqueIdentifier()).execute();
ct._setModel(model);
return ct;
};
module.exports = createY;
if ((typeof window !== "undefined" && window !== null) && (window.Y == null)) {
if (typeof window !== "undefined" && window !== null) {
window.Y = createY;
}
createY.Object = require("./Types/Object");

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long