45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
"use strict";
|
|
var counter = 0;
|
|
var Subscribable = require("../utils/subscribable");
|
|
|
|
var LocalModel = Subscribable.inherit({
|
|
"className": "LocalModel",
|
|
"constructor": function(properties, data) {
|
|
Subscribable.fn.constructor.call(this);
|
|
|
|
this.properties = [];
|
|
this._controllers = [];
|
|
|
|
if (properties) {
|
|
for (var key in properties) {
|
|
if (properties.hasOwnProperty(key)) {
|
|
var pair = {p: key, k: properties[key]};
|
|
this.properties.push(pair);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (data !== undefined) {
|
|
this.data = data;
|
|
this.initialized = true;
|
|
}
|
|
},
|
|
"destructor": function() {
|
|
for (var i = 0; i < this._controllers.length; ++i) {
|
|
this._controllers[i].destructor();
|
|
}
|
|
|
|
Subscribable.fn.destructor.call(this);
|
|
},
|
|
"addController": function(ctrl) {
|
|
this._controllers.push(ctrl);
|
|
},
|
|
"setData": function(data) {
|
|
this.data = data;
|
|
this.initialized = true;
|
|
this.trigger("data");
|
|
}
|
|
});
|
|
|
|
module.exports = LocalModel;
|