Skip to content

Instantly share code, notes, and snippets.

@Panman82
Created February 10, 2016 20:40
Show Gist options
  • Save Panman82/a10a94caf849da441e70 to your computer and use it in GitHub Desktop.
Save Panman82/a10a94caf849da441e70 to your computer and use it in GitHub Desktop.
.set()ing bound prop triggers didReceiveAttrs()
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
<h1>Welcome to {{appName}}</h1>
{{my-foobar baz=appName}}
import Ember from 'ember';
export default Ember.Component.extend({
init() {
this._super( ...arguments );
this.set('attrHookLog', Ember.A());
this.set('_isSettingBaz', false);
},
didReceiveAttrs() {
if (!this.get('_isSettingBaz')) {
this.get('attrHookLog').pushObject(
'baz: ' + this.get('baz')
);
}
},
actions: {
setBazWithoutFlag() {
this.set('baz', 'Amber Twiddle');
},
setBazWithFlag() {
this.set('_isSettingBaz', true);
this.set('baz', 'Ember 2 Twiddle');
Ember.run.next( this, function(){
this.set('_isSettingBaz', false);
});
}
}
});
<button {{action "setBazWithoutFlag"}}>
Without Flag
</button>
<button {{action "setBazWithFlag"}}>
With Flag
</button>
<h3><code>didReceiveAttrs()</code> Log</h3>
<ol>
{{#each attrHookLog as |entry|}}
<li>{{entry}}</li>
{{/each}}
</ol>
{
"version": "0.5.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.2.0/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.2.0/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment