Skip to content

Instantly share code, notes, and snippets.

@ankushdharkar
Created March 11, 2016 04:51
Show Gist options
  • Save ankushdharkar/4ebdae05dfafc6986ef2 to your computer and use it in GitHub Desktop.
Save ankushdharkar/4ebdae05dfafc6986ef2 to your computer and use it in GitHub Desktop.
Computed vs Observer
import Ember from 'ember';
export default Ember.Controller.extend({
vehicleType:"Car",
numWheels: Ember.on('init',Ember.computed('vehicleType',function(){
if(this.get('vehicleType') === 'Car'){
this.set('numWheels',4);
}
else{
this.set('numWheels',0);
}
})),
observerForNumWheels: Ember.on('init', Ember.observer('vehicleType',function(){
this.set('numWheels', 8);
}))
});
The type of vehicle is an {{vehicleType}} and it has {{numWheels}} wheels.
{
"version": "0.6.3",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.4.1",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.0/ember-data.js",
"ember-template-compiler": "2.4.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment