var BaseComponent = require("./base");
/**
*/
function StackComponent(options) {
BaseComponent.call(this, options);
var self = this;
this.childTemplates = this.childTemplate.vnode.children.map(function(vnode) {
return self.childTemplate.child(vnode);
});
}
/**
*/
module.exports = BaseComponent.extend(StackComponent, {
/**
*/
update: function() {
var currentTpl;
var show = this.attributes.state;
if (typeof show === "number") {
currentTpl = this.childTemplates[show];
} else {
// match by name
for (var i = this.childTemplates.length; i--;) {
var childTemplate = this.childTemplates[i];
if (childTemplate.vnode.attributes.name === show) {
currentTpl = childTemplate;
break;
}
}
}
if (this.currentTemplate === currentTpl) return;
this.currentTemplate = currentTpl;
if (this.currentView) this.currentView.dispose();
if (!currentTpl) return;
this.currentView = currentTpl.view(this.view.context, {
parent: this.view
});
this.currentTemplate = currentTpl;
this.section.appendChild(this.currentView.render());
}
});
|