# Code coverage report for lib/scope/bindableObject.js

## Statements: 96% (24 / 25) Branches: 93.75% (15 / 16) Functions: 83.33% (10 / 12) Lines: 95.45% (21 / 22) Ignored: none

All files » lib/scope/ » bindableObject.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
    62
    63
    641

    1
    265

    265

    265
    265
    265

    265
    219
    219
    59

    1

    319

    66

    222

    5

    42

    18
    5
    5

    18

     var BaseScope  = require("./base"),
    ScopedBindableObject = require("scoped-bindable-object");

    function BindableObjectScope (properties, parent) {
      if (!properties) properties = {};

      var context = properties.__isBindable ? properties : new ScopedBindableObject(properties, parent ? parent.context : void 0);

      BaseScope.call(this, context, parent);
      this.watcher = this;
      this.deserializer = this;

      if (!properties.__isBindable) {
        var self = this;
        this.context.on("change", function (k, v) {
          if (!~k.indexOf(".")) properties[k] = v;
        });
      }
    }

    module.exports = BaseScope.extend(BindableObjectScope, {
      __isScope: true,
      get: function (path) {
        return this.context.get(path);
      },
      set: function (path, value) {
        return this.context.set(path, value);
      },
      watch: function (property, listener) {
        return this.context.bind(property, listener);
      },
      setProperties: function (properties) {
        this.context.setProperties(properties);
      },
      child: function (properties) {
        return new BindableObjectScope(properties, this);
      },

      // watcher
      watchProperty: function (target, property, listener) {

      },

      watchCollection: function (target, operation, listener) {
        if (!target.__isBindableCollection) return { dispose: function(){} };
        Eif (operation === "change") {
          return target.on("update", listener);
        }
      },

      /**
       */

      deserializeObject: function (object) {
        return object.toJSON();
      },

      deserializeCollection: function (collection) {
        return collection.source || collection;
      },

    });