コード例 #1
0
ファイル: watch_test.js プロジェクト: mjc/ngular
QUnit.test('when watching another object, destroy should remove chain watchers from the other object', function() {
  var objA = {};
  var objB = { foo: 'bar' };
  objA.b = objB;
  addListeners(objA, 'b.foo');

  watch(objA, 'b.foo');

  var meta_objB = Ngular.meta(objB);
  var chainNode = Ngular.meta(objA).chains._chains.b._chains.foo;
  var index = indexOf(meta_objB.chainWatchers.foo, chainNode);

  equal(meta_objB.watching.foo, 1, 'should be watching foo');
  strictEqual(meta_objB.chainWatchers.foo[index], chainNode, 'should have chain watcher');

  destroy(objA);

  index = indexOf(meta_objB.chainWatchers.foo, chainNode);
  equal(meta_objB.watching.foo, 0, 'should not be watching foo');
  equal(index, -1, 'should not have chain watcher');
});
コード例 #2
0
ファイル: watch_test.js プロジェクト: mjc/ngular
QUnit.test('when watching a global object, destroy should remove chain watchers from the global object', function() {
  lookup['Global'] = Global = { foo: 'bar' };
  var obj = {};
  addListeners(obj, 'Global.foo');

  watch(obj, 'Global.foo');

  var meta_Global = Ngular.meta(Global);
  var chainNode = Ngular.meta(obj).chains._chains.Global._chains.foo;
  var index = indexOf(meta_Global.chainWatchers.foo, chainNode);

  equal(meta_Global.watching.foo, 1, 'should be watching foo');
  strictEqual(meta_Global.chainWatchers.foo[index], chainNode, 'should have chain watcher');

  destroy(obj);

  index = indexOf(meta_Global.chainWatchers.foo, chainNode);
  equal(meta_Global.watching.foo, 0, 'should not be watching foo');
  equal(index, -1, 'should not have chain watcher');

  lookup['Global'] = Global = null; // reset
});
コード例 #3
0
ファイル: core_object.js プロジェクト: mjc/ngular
    Override to implement teardown.

    @method willDestroy
   */
  willDestroy: K,

  /**
    Invoked by the run loop to actually destroy the object. This is
    scheduled for execution by the `destroy` method.

    @private
    @method _scheduledDestroy
  */
  _scheduledDestroy() {
    if (this.isDestroyed) { return; }
    destroy(this);
    this.isDestroyed = true;
  },

  bind(to, from) {
    if (!(from instanceof Binding)) { from = Binding.from(from); }
    from.to(to).connect(this);
    return from;
  },

  /**
    Returns a string representation which attempts to provide more information
    than Javascript's `toString` typically does, in a generic way for all Ngular
    objects.

    ```javascript