QUnit.test('fooBinding: should disconnect bindings when destroyed', function () { run(function() { testObject = TestObject.createWithMixins({ fooBinding: "TestNamespace.fromObject.bar" }); set(TestNamespace.fromObject, 'bar', 'BAZ'); }); equal(get(testObject, 'foo'), 'BAZ', 'binding should have synced'); destroy(testObject); run(function() { set(TestNamespace.fromObject, 'bar', 'BIFF'); }); ok(get(testObject, 'foo') !== 'bar', 'binding should not have synced'); });
QUnit.test('when watching another object, destroy should remove chain watchers from the other object', function() { let objA = {}; let objB = { foo: 'bar' }; objA.b = objB; addListeners(objA, 'b.foo'); watch(objA, 'b.foo'); let meta_objB = meta(objB); let chainNode = meta(objA).readableChains()._chains.b._chains.foo; equal(meta_objB.peekWatching('foo'), 1, 'should be watching foo'); equal(meta_objB.readableChainWatchers().has('foo', chainNode), true, 'should have chain watcher'); destroy(objA); equal(meta_objB.peekWatching('foo'), 0, 'should not be watching foo'); equal(meta_objB.readableChainWatchers().has('foo', chainNode), false, 'should not have chain watcher'); });
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 = Ember.meta(objB); var chainNode = Ember.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'); });
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 = Ember.meta(Global); var chainNode = Ember.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 });
@method willDestroy @public */ willDestroy() {}, /** 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 Ember objects. ```javascript
_scheduledDestroy: function() { if (this.isDestroyed) { return; } destroy(this); this.isDestroyed = true; },