Skip to content

Instantly share code, notes, and snippets.

@amk221
Forked from grayt0r/components.my-component.js
Last active October 6, 2017 08:35
Show Gist options
  • Save amk221/fb3502e96650dab5b86261bf1362eb71 to your computer and use it in GitHub Desktop.
Save amk221/fb3502e96650dab5b86261bf1362eb71 to your computer and use it in GitHub Desktop.
Computed Oddity
import Component from 'ember-component';
import computed from 'ember-computed';
export default Component.extend({
didReceiveAttrs() {
this._super(...arguments);
// Comment this line to fix
this.get('sum');
this.set('number', this.get('my-attr'));
},
sum: computed('number', function() {
console.log('computing', this.get('number'));
return this.get('number') + 10;
})
});
import Controller from 'ember-controller';
export default Controller.extend({
number: 0,
actions: {
inc() {
this.incrementProperty('number');
}
}
});
div { display: inline }
Controller incoming attr:
{{number}}
<button onclick={{action 'inc'}}>Change attr</button>
<br><br>
<hr>
<br>
Component computed property (should be 10):
{{my-component my-attr=number}}
<br><br>
{
"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": "release",
"ember-template-compiler": "release",
"ember-testing": "release"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment