Code coverage report for lib/components/stack.js

Statements: 11.54% (3 / 26)      Branches: 0% (0 / 10)      Functions: 0% (0 / 3)      Lines: 13.04% (3 / 23)      Ignored: none     

All files » lib/components/ » stack.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 541         1                         1                                                                      
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());
  }
});