From 4ac8e740ff566b27aa0fc381e8e805301f4b8a5d Mon Sep 17 00:00:00 2001 From: Erik Bryn Date: Tue, 3 Feb 2015 21:15:03 -0800 Subject: [PATCH] Add internal `_willDestroyElement` hook to prevent using instance-based events --- packages/ember-views/lib/system/renderer.js | 3 +++ packages/ember-views/lib/views/view.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/ember-views/lib/system/renderer.js b/packages/ember-views/lib/system/renderer.js index 36a42a7f26d..6ed868b782b 100644 --- a/packages/ember-views/lib/system/renderer.js +++ b/packages/ember-views/lib/system/renderer.js @@ -127,6 +127,9 @@ Renderer.prototype.willRemoveElement = function (view) {}; Renderer.prototype.willDestroyElement = function (view) { if (this._destinedForDOM) { + if (view._willDestroyElement) { + view._willDestroyElement(); + } if (view.trigger) { view.trigger('willDestroyElement'); view.trigger('willClearRender'); diff --git a/packages/ember-views/lib/views/view.js b/packages/ember-views/lib/views/view.js index 54f4ffea452..bdec8e1f9cd 100644 --- a/packages/ember-views/lib/views/view.js +++ b/packages/ember-views/lib/views/view.js @@ -128,10 +128,18 @@ var ViewStreamSupport = Mixin.create({ return stream; }, + _willDestroyElement: function() { + if (this._streamBindings) { + this._destroyStreamBindings(); + } + if (this._contextStream) { + this._destroyContextStream(); + } + }, + _getBindingForStream: function(pathOrStream) { if (this._streamBindings === undefined) { this._streamBindings = create(null); - this.one('willDestroyElement', this, this._destroyStreamBindings); } var path = pathOrStream; @@ -170,7 +178,6 @@ var ViewStreamSupport = Mixin.create({ if (this._contextStream === undefined) { this._baseContext = new KeyStream(this, 'context'); this._contextStream = new ContextStream(this); - this.one('willDestroyElement', this, this._destroyContextStream); } return this._contextStream;