Skip to content

Instantly share code, notes, and snippets.

@kybishop
Created January 2, 2017 04:53
Show Gist options
  • Save kybishop/d5e9133682e901b42692693c0bd81e02 to your computer and use it in GitHub Desktop.
Save kybishop/d5e9133682e901b42692693c0bd81e02 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Component.extend({
didInsertElement() {
this._super(...arguments);
console.log('in didInsertElement');
Ember.run.schedule('afterRender', () => {
console.log('in afterRender');
});
},
willDestroyElement() {
this._super(...arguments);
console.log('in willDestroyElement');
}
});
import Ember from 'ember';
export default Ember.Component.extend({
sharedService: Ember.inject.service(),
didInsertElement() {
this._super(...arguments);
console.log('mutating shared service');
this.set('sharedService.showDestroyedComponent', false);
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
sharedService: Ember.inject.service(),
actions: {
toggleTest() {
this.toggleProperty('sharedService.show');
this.toggleProperty('sharedService.showDestroyedComponent');
}
}
});
import Ember from 'ember';
export default Ember.Service.extend({
show: false,
});
<button {{action "toggleTest"}}>{{if sharedService.show "Tear down test" "Run test"}}</button>
<br>
{{#if sharedService.show}}
{{#if sharedService.showDestroyedComponent}}
{{destroyed-component}}
{{/if}}
{{service-mutating-component}}
{{/if}}
<p>destroyed component template</p>
<p>service mutating component template</p>
{
"version": "0.10.7",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.9.1",
"ember-data": "2.10.0",
"ember-template-compiler": "2.9.1",
"ember-testing": "2.9.1"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment