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

## Statements: 96% (24 / 25) Branches: 90% (9 / 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
    5

    5

    5
    10

    1

    9

    9
    4

    5
    9
    9
    5
    5

    9
    8
    8
    8
    8
    8
    8

     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();
        Iif (!currentTpl) return;
        this.currentView = currentTpl.view(this.view.context);
        this.currentTemplate = currentTpl;
        this.section.appendChild(this.currentView.render());
      }
    });