initial commit
This commit is contained in:
commit
4b60ece582
327 changed files with 28286 additions and 0 deletions
51
libjs/wModel/list.js
Normal file
51
libjs/wModel/list.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
"use strict";
|
||||
|
||||
var Model = require("./model");
|
||||
var Vector = require("../wType/vector");
|
||||
var Vocabulary = require("../wType/vocabulary");
|
||||
var Object = require("../wType/object")
|
||||
|
||||
var List = Model.inherit({
|
||||
"className": "List",
|
||||
"constructor": function(address) {
|
||||
Model.fn.constructor.call(this, address);
|
||||
|
||||
this._data = new Vector();
|
||||
|
||||
this.addHandler("get");
|
||||
},
|
||||
"destructor": function() {
|
||||
this._data.destructor();
|
||||
|
||||
Model.fn.destructor.call(this);
|
||||
},
|
||||
"clear": function() {
|
||||
this._data.clear();
|
||||
|
||||
this.broadcast(new Vocabulary(), "clear");
|
||||
},
|
||||
"_h_subscribe": function(ev) {
|
||||
Model.fn._h_subscribe.call(this, ev);
|
||||
|
||||
this._h_get(ev);
|
||||
},
|
||||
"_h_get": function(ev) {
|
||||
var vc = new Vocabulary();
|
||||
|
||||
vc.insert("data", this._data.clone());
|
||||
this.response(vc, "get", ev);
|
||||
},
|
||||
"push": function(obj) {
|
||||
if (!(obj instanceof Object)) {
|
||||
throw new Error("An attempt to push into list unserializable value");
|
||||
}
|
||||
this._data.push(obj);
|
||||
|
||||
var vc = new Vocabulary();
|
||||
vc.insert("data", obj.clone());
|
||||
|
||||
this.broadcast(vc, "push");
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = List;
|
Loading…
Add table
Add a link
Reference in a new issue