Skip to content

Instantly share code, notes, and snippets.

@kumkanillam
Created June 19, 2017 05:27
Show Gist options
  • Save kumkanillam/b380d95208cf65256635cd956b4f5dc4 to your computer and use it in GitHub Desktop.
Save kumkanillam/b380d95208cf65256635cd956b4f5dc4 to your computer and use it in GitHub Desktop.
Ember parent child component, how to avoid unnecessary life cycle hook from triggering?
import Ember from 'ember';
export default Ember.Component.extend({
name:'mycomp',
init(){
this._super(...arguments);
console.log(' init mycomponent');
},
didReceiveAttrs(){
console.log('didReceiveAttrs mycomponent');
},
didUpdateAttrs(){
console.log('didUpdateAttrs mycomponent');
},
willUpdate(){
console.log('willUpdate mycomponent');
},
didInsertElement(){
console.log('didInsertElement mycomponent');
},
didUpdate(){
console.log('didUpdate mycomponent');
},
willRender(){
console.log('willRender mycomponent');
},
didRender(){
console.log('didrender mycomponent');
},
actions:{
toChange(){
this.set('name','ChangedInMyComp '+new Date().toISOString());
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
name:'mycomp2',
init(){
this._super(...arguments);
console.log(' init mycomponent2');
},
didReceiveAttrs(){
console.log('didReceiveAttrs mycomponent2');
},
didUpdateAttrs(){
console.log('didUpdateAttrs mycomponent2');
},
willUpdate(){
console.log('willUpdate mycomponent2');
},
willRender(){
console.log('willRender mycomponent2');
},
didUpdate(){
console.log('didUpdate mycomponent2');
},
didInsertElement(){
console.log('didInsertElement mycomponent2');
},
didRender(){
console.log('didrender mycomponent2');
},
actions:{
toChange(){
this.set('name','ChangedInMyComp '+new Date().toISOString());
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
});
<br>
{{#my-component as |name toChange|}}
<button {{action toChange}}> 1 - {{name}}</button>
{{#my-component2 as |name toChange|}}
<button {{action toChange}}> 2 - {{name}}</button>
{{/my-component2}}
{{/my-component}}
<br>
{{outlet}}
<br>
{{yield name (action 'toChange')}}
{{yield name (action 'toChange')}}
{
"version": "0.12.1",
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {
"ember-data": "2.12.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment