Skip to content

Instantly share code, notes, and snippets.

@DingoEatingFuzz
Created July 20, 2017 17:16
Show Gist options
  • Save DingoEatingFuzz/17a16fd1fdb2cee80c3b66cf5be84ff5 to your computer and use it in GitHub Desktop.
Save DingoEatingFuzz/17a16fd1fdb2cee80c3b66cf5be84ff5 to your computer and use it in GitHub Desktop.
Computed Property Caching
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
defaultItem: 'foo',
item: Ember.computed(function() {
return this.get('defaultItem')
}),
actions: {
setItem(val) {
this.set('item', val);
},
setDefaultItem(val) {
this.set('defaultItem', val);
},
}
});
<p>Default Value: {{defaultItem}}</p>
<p>Current Value: {{item}}</p>
<button {{action "setItem" "bar"}}>Set item to bar</button>
<button {{action "setItem" "wat"}}>Set item to wat</button>
<button {{action "setDefaultItem" "sloth"}}>Set default item to sloth</button>
{
"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