# Code coverage report for lib/template/component.js

## Statements: 75% (12 / 16) Branches: 33.33% (2 / 6) Functions: 75% (3 / 4) Lines: 78.57% (11 / 14) Ignored: none

All files » lib/template/ » component.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
    7

    1

    7

    7

    7
    7

    7

    7

    1

     var BaseComponent    = require("../components/base"),
    _bind                = require("../utils/bind"),
    _extend              = require("../utils/extend");

    /**
     */

    function TemplateComponent(options) {
      BaseComponent.call(this, options);
    }

    /**
     */

    module.exports = BaseComponent.extend(TemplateComponent, {

      /**
       */

      bind: function() {
        this._bindings = [];

        this.childContext = new this.contextClass(this.attributes);

        Eif (!this.childView) {
          this.childView = this.template.view(this.childContext, {
            parent: this.view
          });
          this.section.appendChild(this.childView.render());
        } else {
          this.childView.setOptions({ parent: this.view });
          this.childView.bind(this.childContext);
        }

        BaseComponent.prototype.bind.call(this);
      },

      /**
       */

      unbind: function() {
        Eif (this.childView) this.childView.unbind();
      },

      /**
       */

      _onAttrsChange: function(key, value) {
        if (this.childView) this.childView.set(key, value);
      }
    });