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

## Statements: 100% (15 / 15) Branches: 100% (0 / 0) Functions: 100% (5 / 5) Lines: 100% (15 / 15) 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
    291

    1
    7

    1

    7
    7
    7
    7
    7

    8
    8
    8
    8

    2

    6

     var BaseComponent    = require("../components/base"),
    _bind                = require("../utils/bind"),
    ScopedBindableObject = require("scoped-bindable-object");

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

    module.exports = BaseComponent.extend(TemplateComponent, {
      initialize: function () {
        this.context = new this.contextClass(this.attributes.toJSON());
        this.childScope = new this.template.scopeClass(this.context);
        this.view = this.template.view();
        this.section.appendChild(this.view.render());
        this.attributes.on("change", this._onAttrsChange = _bind(this._onAttrsChange, this));
      },
      bind: function (parentScope) {
        this.childScope.parent = parentScope;
        this._bindings = [];
        this.view.bind(this.childScope);
        BaseComponent.prototype.bind.call(this, parentScope);
      },
      unbind: function () {
        this.view.unbind();
      },
      _onAttrsChange: function (key, value) {
        this.childScope.set(key, value);
      }
    });