Skip to content

Instantly share code, notes, and snippets.

@pzuraq
Last active January 13, 2018 03:12
Show Gist options
  • Save pzuraq/5afc0a43536565ee772fa03ecbed39d3 to your computer and use it in GitHub Desktop.
Save pzuraq/5afc0a43536565ee772fa03ecbed39d3 to your computer and use it in GitHub Desktop.
Volatile Computed Bug
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
init() {
this.set('prop', 1);
this.set('computedProp', 1);
},
get prop() {
return this._cachedValue;
},
set prop(value) {
this._cachedValue = value;
},
computedProp: Ember.computed({
get() {
return this._computedCachedValue;
},
set(key, value) {
return this._computedCachedValue = value;
}
}).volatile(),
actions: {
incrementProp() {
this.incrementProperty('prop');
},
incrementComputedProp() {
this.incrementProperty('computedProp');
}
}
});
{{outlet}}
<div>
<button {{action 'incrementProp'}}>ES5 Getter</button>{{prop}}
</div>
<div>
<button {{action 'incrementComputedProp'}}>Computed</button> {{computedProp}}
</div>
{
"version": "0.13.0",
"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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment