Skip to content

Commit

Permalink
Merge pull request #10352 from ebryn/remove-willdestroyelement-events
Browse files Browse the repository at this point in the history
Add internal `_willDestroyElement` hook to prevent using instance-based events
  • Loading branch information
mmun committed Feb 4, 2015
2 parents 4966110 + 4ac8e74 commit 038f640
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions packages/ember-views/lib/system/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
11 changes: 9 additions & 2 deletions packages/ember-views/lib/views/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 038f640

Please sign in to comment.