# Code coverage report for lib/components/stack.js

## Statements: 100% (25 / 25) Branches: 100% (10 / 10) Functions: 100% (3 / 3) Lines: 100% (22 / 22) 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
    521

    1
    6

    6

    6
    12

    1

    160

    160
    61

    99
    164
    164
    97
    97

    160
    14
    14
    14
    13
    13
    13

     var BaseComponent  = require("./base");

    /**
     */

    function StackComponent(options) {
      BaseComponent.call(this, options);

      var self = this;

      // TODO - this is a bit fugly
      this.childTemplates = this.childTemplate.vnode.children.map(function(vnode) {
        return self.childTemplate.child(vnode);
      });
    }

    /**
     */

    module.exports = BaseComponent.extend(StackComponent, {

      /**
       */

      update: function() {

        var currentTpl, 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);
        this.currentTemplate = currentTpl;
        this.section.appendChild(this.currentView.render());
      }
    });