const VnObject = require('./object'); const kebabToCamel = require('./string-util').kebabToCamel; module.exports = new Class({ Extends: VnObject ,initialize: function(builder, objects, thisArg, parentScope) { this.builder = builder; this.objects = objects; this.thisArg = thisArg; this.parentScope = parentScope; if (!thisArg && parentScope) this.thisArg = parentScope.thisArg; } ,link: function(exprScope, extraObjects) { var contextMap = this.builder._contextMap; var objectMap = this.parentScope ? Object.create(this.parentScope._$) : {}; this._$ = objectMap; for (var id in extraObjects) objectMap[id] = extraObjects[id]; for (var id in contextMap) objectMap[id] = this.objects[contextMap[id]]; this.builder.link(this, exprScope); } ,getMain: function() { return this.builder.getMain(this); } ,$: function(objectId) { if (!objectId) return null; return this._$[kebabToCamel(objectId)]; } ,getById: function(objectId) { return this.$(objectId); } ,getByTagName: function(tagName) { return this.builder.getByTagName(this, tagName); } ,getHtmlId: function(nodeId) { return 'vn-'+ this.uid +'-'+ nodeId; } ,_destroy: function() { var objects = this.objects; for (var i = 0; i < objects.length; i++) if (objects[i] instanceof VnObject) objects[i].unref(); this.parent(); } });