Skip to content

Instantly share code, notes, and snippets.

@manufitoussi
Created March 28, 2017 09:52
Show Gist options
  • Save manufitoussi/a9ef366fbbab8213999717ccc63feee7 to your computer and use it in GitHub Desktop.
Save manufitoussi/a9ef366fbbab8213999717ccc63feee7 to your computer and use it in GitHub Desktop.
component lifecycle
import Ember from 'ember';
export default Ember.Component.extend({
isCoco: false,
index: 0,
/* mouseEnter() {
this.set('isCoco', true);
return false;
},
mouseMove() {
this.set('isCoco', true);
},
mouseLeave() {
this.set('isCoco', false);
return false;
},*/
didUpdateAttrs() {
this._super(...arguments);
console.debug('didUpdateAttrs', arguments[0]);
},
didReceiveAttrs() {
this._super(...arguments);
console.debug('didReceiveAttrs', arguments[0]);
},
willUpdate() {
this._super(...arguments);
console.debug('willUpdate', arguments[0]);
},
willRender() {
this._super(...arguments);
console.debug('willRender', arguments[0]);
},
actions: {
changeAttr() {
//this.incrementProperty('index');
this.toggleProperty('isCoco');
}
}
});
import Ember from 'ember';
export default Ember.Component.extend({
actions: {
changeAttr() {
//this.incrementProperty('parent.index');
this.toggleProperty('parent.isCoco');
}
}
});
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
index: 0,
actions: {
changeAttr() {
this.incrementProperty('index');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
{{my-component isCoco=isCoco }}
<p>
<button {{action "changeAttr"}}>Change</button>
</p>
<h4>My Component</h4>
<p>
{{isCoco}} - {{index}}
</p>
<p>
<button {{action "changeAttr"}}>Change component</button>
</p>
<br />
{{my-sub parent=this}}
<p>SUB</p>
<p>
<button {{action "changeAttr"}}>Change parent</button>
</p>
{
"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