Skip to content

Instantly share code, notes, and snippets.

@arthur5005
Last active November 3, 2016 20:38
Show Gist options
  • Save arthur5005/05c8a8bab8f1cacd7c57253db43f612a to your computer and use it in GitHub Desktop.
Save arthur5005/05c8a8bab8f1cacd7c57253db43f612a to your computer and use it in GitHub Desktop.
Computed Property Cache Test
import Ember from 'ember';
export default Ember.Controller.extend({
_prop: 0,
prop: Ember.computed(function() {
return this.get('_prop');
}).volatile(),
propView: null,
actions: {
increase() {
this.incrementProperty('_prop');
this.set('propView', this.get('prop'));
}
}
});
<h1>Computed Property Cache Test</h1>
<p>
This illustrates that computed properties without dependant keys cache just like computed properties with dependent keys but are only ever computed on first get, UNLESS you call .volatile() on the computed object.
</p>
<p>This also demonstrates that the template can't update volatile properties</p>
<br>_prop: {{_prop}}
<br>propView: {{propView}}
<br>prop: {{prop}}
<br><br>
<button {{action "increase"}}>Increase _prop and set propView from prop</button>
{
"version": "0.10.6",
"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.9.0",
"ember-data": "2.9.0",
"ember-template-compiler": "2.9.0",
"ember-testing": "2.9.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment