# Code coverage report for lib/template/vnode/element/attributesBinding.js

## Statements: 95.65% (22 / 23) Branches: 75% (3 / 4) Functions: 100% (5 / 5) Lines: 100% (22 / 22) Ignored: none

All files » lib/template/vnode/element/ » attributesBinding.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
    441

    1
    52
    52
    52
    52

    1

    56
    56
    60
    60
    39

    21

    39

    39
    1432
    1432

    39

    10
    10
    5

    10

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

    function AttributesBinding(attributes, rawAttributes, component, view) {
      this.attributes    = attributes;
      this.rawAttributes = rawAttributes;
      this.component     = component;
      this.view          = view;
    }

    module.exports = protoclass(AttributesBinding, {
      bind: function() {
        this.bindings = [];
        for (var k in this.rawAttributes) {
          var v = this.rawAttributes[k];
          if (v.bind) {
            this._bindAttr(k, v);
          } else {
            this.attributes[k] = v;
          }
        }
      },
      _bindAttr: function(k, v) {
        var self = this;

        // TODO: remove now()
        this.bindings.push(v.bind(this.view, function(nv, ov) {
          self.attributes[k] = nv;
          self.view.runloop.deferOnce(self.component);
        }));

        self.attributes[k] = v.evaluate(this.view);

      },
      unbind: function() {
        Iif (!this.bindings) return;
        for (var i = this.bindings.length; i--;) {
          this.bindings[i].dispose();
        }
        this.bindings = [];
      }
    });