Skip to content

Instantly share code, notes, and snippets.

@chrisseto
Last active February 29, 2016 19:39
Show Gist options
  • Save chrisseto/a97a8db3529bb5899929 to your computer and use it in GitHub Desktop.
Save chrisseto/a97a8db3529bb5899929 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
myComponent: 'will-destroy-element',
appName: 'Ember Twiddle',
actions: {
click() {
if (this.get('myComponent') !== null)
this.set('myComponent', null);
else
this.set('myComponent', 'will-destroy-element');
}
}
});
<h1>willDestroyElement and component helper bug</h1>
<br>
When a component is rendered with the <i>component</i> helper <i>willDestroyElement</i> is called after the element is removed from the DOM.<br>
The component below is rendered twice, once with the component helper and once inside an if block.<br>
The component's <i>willDestroyElement</i> hook logs to the console whether or not it's contents exist in the DOM.<br>
Pressing the button below will cause both components to be removed from the page.<br>
It is expected that <i>true, true</i> will get printed to the console, but <i>false, true</i> is printed instead.
<br>
{{component myComponent}}
{{#if myComponent}}
{{will-destroy-element}}
{{/if}}
<br>
<br>
<button {{action 'click'}}>Toggle</button>
{
"version": "0.6.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.3.1/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
import Ember from 'ember';
export default Ember.Component.extend({
willDestroyElement() {
console.log($.contains(document, this.$('#gone')[0]));
}
});
<h4 id="gone"> Will Destroy Element</h4>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment