92 lines
2.0 KiB
JavaScript
92 lines
2.0 KiB
JavaScript
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) {
|
|
this._model.observe(f);
|
|
return this;
|
|
};
|
|
|
|
YObject.prototype.unobserve = function(f) {
|
|
this._model.unobserve(f);
|
|
return this;
|
|
};
|
|
|
|
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;
|
|
}
|
|
}
|
|
};
|
|
|
|
YObject.prototype["delete"] = function(name) {
|
|
this._model["delete"](name);
|
|
return this;
|
|
};
|
|
|
|
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;
|
|
}
|