marbles
Version:
Front-end framework for routing, http, and data handling
120 lines (90 loc) • 2.24 kB
JavaScript
;
var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { "default": obj }; };
Object.defineProperty(exports, "__esModule", {
value: true
});
/* @flow weak */
var _Utils = require("./utils");
var _Utils2 = _interopRequireWildcard(_Utils);
var _Transaction = require("./transaction");
var _Transaction2 = _interopRequireWildcard(_Transaction);
var _CIDMapping = require("./id_mapping");
var _CIDMapping2 = _interopRequireWildcard(_CIDMapping);
var _Accessors = require("./accessors");
var _Accessors2 = _interopRequireWildcard(_Accessors);
var _Events = require("./events");
var _Events2 = _interopRequireWildcard(_Events);
/**
* @deprecated Use the Store instead
* @see Marbles.Store
* @memberof Marbles
* @class
*/
var Model = _Utils2["default"].createClass({
displayName: "Marbles.Model",
mixins: [
// Add some properties to ctor
{
ctor: {
modelName: "model",
cidScope: ["modelName"],
cidMappingScope: ["id"],
JSONKeys: "all"
}
},
// Make ctor and proto evented
{
ctor: _Events2["default"],
proto: _Events2["default"]
},
// Extend ptoto with accessor methods
_Accessors2["default"],
// Extend proto with transaction method
_Transaction2["default"],
// CIDMapping extends both ctor and proto
_CIDMapping2["default"]],
willInitialize: function willInitialize(attrs, options) {
if (!attrs) {
attrs = {};
}
if (!options) {
options = {};
}
if (options.cid) {
this.cid = options.cid;
}
this.initCIDMapping();
this.transaction(function () {
this.parseAttributes(attrs);
});
return this;
},
parseAttributes: function parseAttributes(attrs) {
for (var k in attrs) {
if (attrs.hasOwnProperty(k)) {
this.set(k, attrs[k], { keypath: false });
}
}
},
toJSON: function toJSON() {
var keys,
attrs = {},
i,
_len,
k;
if (this.constructor.JSONKeys === "all") {
keys = Object.keys(this);
} else {
keys = this.constructor.JSONKeys;
}
for (i = 0, _len = keys.length; i < _len; i++) {
k = keys[i];
if (this.hasOwnProperty(k)) {
attrs[k] = this[k];
}
}
return attrs;
}
});
exports["default"] = Model;
module.exports = exports["default"];