Skip to content

Instantly share code, notes, and snippets.

@juggy
Forked from ofersadgat/controllers.application.js
Created November 16, 2016 21:29
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 juggy/023991717ff0f967cdb677e7d06d083e to your computer and use it in GitHub Desktop.
Save juggy/023991717ff0f967cdb677e7d06d083e to your computer and use it in GitHub Desktop.
Computed Update Count
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
counter: Ember.computed({
get(){
return 0;
},
set(k,v){
this.set("countGreater", v > 5);
return v;
}
}),
countGreater: false,
callCount: 0,
ocallCount: 0,
setCounter: Ember.on('init', function(){
setInterval(function(){
this.set('counter', this.get('counter') + 1);
}.bind(this), 1000);
}),
//countGreater: Ember.computed.gt('counter', 5),
observeCountGreater: Ember.observer('countGreater', Ember.on('init', function(){
var countGreater = this.get('countGreater');
var fixedCountGreater = this.get('fixedCountGreater');
if (fixedCountGreater != countGreater){
this.set('fixedCountGreater', countGreater);
}
})),
prop: Ember.computed('countGreater', function(){
this.set('callCount', this.get('callCount') + 1);
return 'CounterGreater is ' + this.get('countGreater');
}),
oprop: Ember.computed('fixedCountGreater', function(){
this.set('ocallCount', this.get('ocallCount') + 1);
return 'FixedCounterGreater is ' + this.get('fixedCountGreater');
})
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
Prop value: {{prop}}
<br>
OProp value: {{oprop}}
<br>
Prop callcount: {{callCount}}
<br>
Observed value callcount: {{ocallCount}}
{
"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.0.1",
"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