2022-05-24 21:11:12 +00:00
|
|
|
const VnObject = require('./object');
|
|
|
|
const kebabToCamel = require('./string-util').kebabToCamel;
|
|
|
|
|
2022-05-28 19:27:36 +00:00
|
|
|
let scopeUid = 0;
|
|
|
|
|
2022-05-24 21:11:12 +00:00
|
|
|
module.exports = new Class({
|
|
|
|
Extends: VnObject
|
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
,initialize: function(builder, objects, thisArg, parent) {
|
2022-05-24 21:11:12 +00:00
|
|
|
this.builder = builder;
|
|
|
|
this.objects = objects;
|
|
|
|
this.thisArg = thisArg;
|
2022-06-07 08:19:29 +00:00
|
|
|
this.parent = parent;
|
2022-05-28 19:27:36 +00:00
|
|
|
this.uid = ++scopeUid;
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$ = parent ? Object.create(parent.$) : {};
|
2022-05-24 21:11:12 +00:00
|
|
|
|
2022-06-07 08:19:29 +00:00
|
|
|
if (parent) {
|
|
|
|
parent.on('lot-change', this.onLotChange, this);
|
|
|
|
if (!thisArg) this.thisArg = parent.thisArg;
|
|
|
|
}
|
2022-05-24 21:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,link: function(exprScope, extraObjects) {
|
|
|
|
var contextMap = this.builder._contextMap;
|
|
|
|
|
|
|
|
for (var id in extraObjects)
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$[id] = extraObjects[id];
|
2022-05-24 21:11:12 +00:00
|
|
|
for (var id in contextMap)
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$[id] = this.objects[contextMap[id]];
|
2022-05-24 21:11:12 +00:00
|
|
|
|
2022-06-07 08:19:29 +00:00
|
|
|
this.exprScope = [
|
|
|
|
_,
|
|
|
|
this.$
|
|
|
|
].concat(exprScope);
|
|
|
|
|
|
|
|
this.builder.link(this);
|
|
|
|
this.builder.digest(this);
|
|
|
|
|
|
|
|
for (const object of this.objects)
|
|
|
|
if (object.assignLot)
|
|
|
|
object.on('change', this.onLotChange, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
,onLotChange() {
|
|
|
|
this.emit('lot-change');
|
|
|
|
this.builder.digest(this);
|
2022-05-24 21:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,getMain: function() {
|
|
|
|
return this.builder.getMain(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
,getById: function(objectId) {
|
2022-05-28 01:18:06 +00:00
|
|
|
if (!objectId) return null;
|
|
|
|
return this.$[kebabToCamel(objectId)];
|
2022-05-24 21:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,getByTagName: function(tagName) {
|
|
|
|
return this.builder.getByTagName(this, tagName);
|
|
|
|
}
|
|
|
|
|
|
|
|
,getHtmlId: function(nodeId) {
|
|
|
|
return 'vn-'+ this.uid +'-'+ nodeId;
|
|
|
|
}
|
|
|
|
|
|
|
|
,_destroy: function() {
|
2022-06-07 08:19:29 +00:00
|
|
|
for (const object of this.objects)
|
|
|
|
if (object instanceof VnObject) {
|
|
|
|
object.disconnectByInstance(this);
|
|
|
|
object.unref();
|
|
|
|
}
|
|
|
|
if (this.parent) {
|
|
|
|
this.parent.disconnectByInstance(this);
|
|
|
|
this.parent.unref();
|
|
|
|
}
|
2022-05-24 21:11:12 +00:00
|
|
|
|
2022-06-06 16:02:17 +00:00
|
|
|
VnObject.prototype._destroy.call(this);
|
2022-05-24 21:11:12 +00:00
|
|
|
}
|
|
|
|
});
|