# Code coverage report for lib/template/vnode/block/binding.js

## Statements: 94.74% (18 / 19) Branches: 75% (6 / 8) Functions: 100% (4 / 4) Lines: 94.44% (17 / 18) Ignored: none

All files » lib/template/vnode/block/ » binding.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
    361

    1
    116
    116
    116
    116

    1

    142

    142
    158

    145

    145
    145

    142

    30
    28
    28

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

    function BlockBinding (node, script, view) {
      this.view   = view;
      this.nodeFactory = view.template.nodeFactory;
      this.script = script;
      this.node   = node;
    }

    module.exports = protoclass(BlockBinding, {
      bind: function (context) {
        var self = this;

        // TODO - needs to update on rAF
        this.binding = this.script.bind(this.view, context, function (value, oldValue) {
          if (value === oldValue) return;

          var v = String(value == null ? "" : value);

          Eif (self.nodeFactory.name !== "dom") {
            self.node.replaceText(v, true);
          } else {
            self.node.nodeValue = String(v);
          }
        });

        this.binding.now();
      },
      unbind: function () {
        if (this.binding) {
          this.binding.dispose();
          this.binding = void 0;
        }
      }
    });