Skip to content

Instantly share code, notes, and snippets.

@blimmer
Created February 1, 2016 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blimmer/cdb725d7fedcf56fa4f3 to your computer and use it in GitHub Desktop.
Save blimmer/cdb725d7fedcf56fa4f3 to your computer and use it in GitHub Desktop.
when setting goes wrong
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
<h1> when 'set'-ing goes wrong </h1>
<p>
Bar is a computed property based on foo.
<ol>
<li>click on 'set foo' & see the property change</li>
<li>click on 'set bar' & see the property change</li>
<li>click on 'set foo' again. notice that after setting the property, the computed property is now overwritten</li>
</ol>
</p>
{{my-component}}
import Ember from 'ember';
export default Ember.Component.extend({
foo: 'original foo',
bar: Ember.computed('foo', function() {
return this.get('foo') + 'computed';
}),
actions: {
setBar: function() {
this.set('bar', 'bar set');
},
setFoo: function() {
this.set('foo', 'new foo');
}
}
});
<h2> bar reads: {{bar}} </h2>
<button {{action 'setBar'}}> set bar </button>
<button {{action 'setFoo'}}> set foo </button>
{
"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