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

Statements: 16.67% (4 / 24)      Branches: 0% (0 / 6)      Functions: 0% (0 / 5)      Lines: 17.39% (4 / 23)      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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 601 1         1                   1                                                                                      
var protoclass = require("protoclass");
var 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.watch && v.evaluate) {
        this._bindAttr(k, v);
      } else {
        this.attributes[k] = v;
      }
    }
  },
 
  /**
   */
 
  _bindAttr: function(k, v) {
    var self = this;
 
    this.bindings.push(v.watch(this.view, function(nv, ov) {
      self.attributes[k] = nv;
      self.view.runloop.deferOnce(self.component);
    }));
 
    self.attributes[k] = v.evaluate(this.view);
 
  },
 
  /**
   */
 
  unbind: function() {
    if (!this.bindings) return;
    for (var i = this.bindings.length; i--;) {
      this.bindings[i].dispose();
    }
    this.bindings = [];
  }
});