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

## Statements: 95.24% (20 / 21) Branches: 75% (3 / 4) Functions: 100% (5 / 5) Lines: 100% (19 / 19) 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
    341

    1
    53
    53
    53
    53

    1

    56
    56
    63
    63
    41

    22

    41
    41
    68

    8
    8
    8

     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 (context) {
        this.bindings = [];
        for (var k in this.rawAttributes) {
          var v = this.rawAttributes[k];
          if (v.bind) {
            this._bindAttr(context, k, v);
          } else {
            this.attributes.set(k, v);
          }
        }
      },
      _bindAttr: function (context, k, v) {
        var self = this;
        this.bindings.push(v.bind(this.view, context, function (nv, ov) {
          self.attributes.set(k, nv);
        }).now());
      },
      unbind: function () {
        Iif (!this.bindings) return;
        for (var i = this.bindings.length; i--;)  this.bindings[i].dispose();
        this.bindings = [];
      }
    });