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

## Statements: 100% (17 / 17) Branches: 75% (3 / 4) Functions: 100% (6 / 6) Lines: 100% (15 / 15) Ignored: none

All files » lib/components/ » base.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
    54
    55
    56
    57
    58
    59
    60
    61
    621

    1

    50
    50
    50
    50
    50

    50

    1

    53
    53
    53
    53

    24

    4

     var protoclass = require("protoclass"),
    _bind          = require("../utils/bind");

    /**
     */

    function Component (options) {

      this.attributes    = options.attributes;
      this.childTemplate = options.childTemplate;
      this.view          = options.view;
      this.section       = options.section;
      this.nodeFactory   = this.view.template.nodeFactory;

      // initialize the DOM elements
      this.initialize();
    }

    /**
     */

    module.exports = protoclass(Component, {

      /**
       */

      initialize: function () {
        // override me - this is where the DOM elements should be added to the
        // section
      },

      /**
       */

      bind: function (context) {
        if (this._changeListener) this._changeListener.dispose();
        this._changeListener = this.attributes.on("change", _bind(this._onChange, this));
        this.context = context;
        this.update();
      },

      /**
       */

      _onChange: function (key, value) {
        this.view.runner.run(this);
      },

      /**
       */

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

      /**
       */

      update: function () {
        // apply DOM changes here
      }
    });