Skip to content

Commit

Permalink
fix(ComponentChildMixin): this.nearestOfType() is not reliable in wil…
Browse files Browse the repository at this point in the history
…lDestroyElement hook

Fixes #99
  • Loading branch information
simonihmig committed Jun 3, 2016
2 parents 00bfde3 + 47ec98a commit 44a9fa0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion addon/mixins/component-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ export default Ember.Mixin.create({
let parent = this.nearestOfType(ComponentParentMixin);
if (parent) {
parent.registerChild(this);
this.set('_parent', parent);
}
}),

// stores the parent in didInsertElement hook as a work-a-round for
// https://github.com/emberjs/ember.js/issues/12080
_parent: null,

_willDestroyElement: Ember.on('willDestroyElement', function() {
let parent = this.nearestOfType(ComponentParentMixin);
let parent = this.nearestOfType(ComponentParentMixin) || this.get('_parent');
if (parent) {
parent.removeChild(this);
}
Expand Down

0 comments on commit 44a9fa0

Please sign in to comment.