const VnObject = require('./object'); const kebabToCamel = require('./string-util').kebabToCamel; let scopeUid = 0; module.exports = new Class({ Extends: VnObject ,initialize: function(builder, objects, thisArg, parent) { this.builder = builder; this.objects = objects; this.thisArg = thisArg; this.parent = parent; this.uid = ++scopeUid; this.$ = parent ? Object.create(parent.$) : {}; if (parent) { parent.on('lot-change', this.onLotChange, this); if (!thisArg) this.thisArg = parent.thisArg; } } ,link: function(exprScope, extraObjects) { var contextMap = this.builder._contextMap; for (var id in extraObjects) this.$[id] = extraObjects[id]; for (var id in contextMap) this.$[id] = this.objects[contextMap[id]]; 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); } ,getMain: function() { return this.builder.getMain(this); } ,getById: function(objectId) { if (!objectId) return null; return this.$[kebabToCamel(objectId)]; } ,getByTagName: function(tagName) { return this.builder.getByTagName(this, tagName); } ,getHtmlId: function(nodeId) { return 'vn-'+ this.uid +'-'+ nodeId; } ,_destroy: function() { 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(); } VnObject.prototype._destroy.call(this); } });