hedera-web/js/vn/scope.js

56 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-05-24 21:11:12 +00:00
const VnObject = require('./object');
const kebabToCamel = require('./string-util').kebabToCamel;
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-05-28 01:18:06 +00:00
this.parentScope = parent;
this.$ = parent ? Object.create(parent.$) : {};
2022-05-24 21:11:12 +00:00
2022-05-28 01:18:06 +00:00
if (!thisArg && parent)
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
this.builder.link(this, exprScope);
}
,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() {
var objects = this.objects;
for (var i = 0; i < objects.length; i++)
if (objects[i] instanceof VnObject)
objects[i].unref();
this.parent();
}
});