2016-09-26 09:28:47 +00:00
|
|
|
|
2022-06-06 16:02:17 +00:00
|
|
|
var SqlObject = require('./object');
|
2016-09-26 09:28:47 +00:00
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* List of Sql.Object
|
2022-05-26 06:08:31 +00:00
|
|
|
*/
|
2022-06-06 08:53:59 +00:00
|
|
|
module.exports = new Class({
|
2022-06-06 16:02:17 +00:00
|
|
|
Extends: SqlObject
|
2015-01-23 13:09:30 +00:00
|
|
|
|
|
|
|
,objects: []
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,add: function(object) {
|
|
|
|
this.objects.push(object.ref());
|
|
|
|
object.on('changed', this._onObjectChange, this);
|
|
|
|
this._onObjectChange();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,get: function(i) {
|
2015-01-23 13:09:30 +00:00
|
|
|
return objects[i];
|
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,getArray: function() {
|
2015-01-23 13:09:30 +00:00
|
|
|
return this.objects;
|
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,remove: function(i) {
|
|
|
|
this._unrefObject(this.objects.splice(i, 1));
|
|
|
|
this._onObjectChange();
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,_onObjectChange: function() {
|
|
|
|
this.emit('changed');
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,isReady: function() {
|
2015-01-23 13:09:30 +00:00
|
|
|
var o = this.objects;
|
|
|
|
|
|
|
|
if (o.length == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (var i = 0; i < o.length; i++)
|
2022-06-06 08:53:59 +00:00
|
|
|
if (!o[i].isReady())
|
2015-01-23 13:09:30 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2022-06-06 08:53:59 +00:00
|
|
|
|
|
|
|
,findHolders() {
|
|
|
|
let ids = [];
|
|
|
|
|
|
|
|
for (const object of this.objects){
|
|
|
|
holders = object.findHolders();
|
|
|
|
if (holders) ids = ids.concat(holders);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ids;
|
|
|
|
}
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,_unrefObject: function(object) {
|
|
|
|
object.disconnect('changed', this._onObjectChange, this);
|
|
|
|
object.unref();
|
2015-07-28 19:14:26 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 08:53:59 +00:00
|
|
|
,_destroy: function() {
|
2015-07-28 19:14:26 +00:00
|
|
|
for (var i = 0; i < this.objects.length; i++)
|
2022-06-06 08:53:59 +00:00
|
|
|
this._unrefObject(this.objects[i]);
|
2015-07-28 19:14:26 +00:00
|
|
|
|
2022-06-06 16:02:17 +00:00
|
|
|
SqlObject.prototype._destroy.call(this);
|
2015-07-28 19:14:26 +00:00
|
|
|
}
|
2015-01-23 13:09:30 +00:00
|
|
|
});
|
|
|
|
|