forked from verdnatura/hedera-web
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
const VnObject = require('./object');
|
|
const kebabToCamel = require('./string-util').kebabToCamel;
|
|
|
|
module.exports = new Class({
|
|
Extends: VnObject
|
|
|
|
,initialize: function(builder, objects, thisArg, parent) {
|
|
this.builder = builder;
|
|
this.objects = objects;
|
|
this.thisArg = thisArg;
|
|
this.parentScope = parent;
|
|
this.$ = parent ? Object.create(parent.$) : {};
|
|
|
|
if (!thisArg && parent)
|
|
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.builder.link(this, exprScope);
|
|
}
|
|
|
|
,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() {
|
|
var objects = this.objects;
|
|
|
|
for (var i = 0; i < objects.length; i++)
|
|
if (objects[i] instanceof VnObject)
|
|
objects[i].unref();
|
|
|
|
this.parent();
|
|
}
|
|
});
|