Skip to content

Instantly share code, notes, and snippets.

@givanse
Last active April 7, 2017 02:06
Show Gist options
  • Save givanse/9a505c04e139cb14a82ecdc8945e7abf to your computer and use it in GitHub Desktop.
Save givanse/9a505c04e139cb14a82ecdc8945e7abf to your computer and use it in GitHub Desktop.
Unrendered computeds
import Ember from 'ember';
// Two options:
// 1. eager load in the init hook
// for the initial render, won't re-calc after that.
// 2. another computed depending on the unrendered computed
// for property updates
export default Ember.Controller.extend({
init: function() {
this._super(...arguments);
// 1. eager load, one off
this.get('anotherUnrenderedComputed');
},
text: 'some words',
counter1: 0,
renderedComputed: Ember.computed('text', function() {
return this.counter1++ + ' ' + this.get('text');
}),
counter2: 0,
unrenderedComputed: Ember.computed('text', function() {
return this.counter2++ + ' ' + this.get('text');
}),
depsOnUnrenderedComputed: Ember.computed('unrenderedComputed', function() {
return this.get('unrenderedComputed');
}),
counter3: 0,
anotherUnrenderedComputed: Ember.computed('text', function() {
console.log('anotherUnrenderedComputed re-calc');
return this.counter3++ + ' ' + this.get('text');
})
});
<h1>Unrendered computeds</h1>
<br>
<br>
{{input value=text}}
<br>
<br>
renderedComputed: {{renderedComputed}}
<br>
<br>
depsOnUnrenderedComputed: {{depsOnUnrenderedComputed}}
{
"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.12.0",
"ember-template-compiler": "2.12.0",
"ember-testing": "2.12.0"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment