Skip to content

Instantly share code, notes, and snippets.

@iirving
Created April 15, 2016 20:00
Show Gist options
  • Save iirving/fcf9aaab418a479504f0d4ff239b35c6 to your computer and use it in GitHub Desktop.
Save iirving/fcf9aaab418a479504f0d4ff239b35c6 to your computer and use it in GitHub Desktop.
light observers
import Ember from 'ember';
//import Resolver from 'ember/resolver';
//import loadInitializers from 'ember/load-initializers';
import config from './config/environment';
import Light from './Light';
var App;
Ember.MODEL_FACTORY_INJECTIONS = true;
App = Ember.Application.extend({
modulePrefix: config.modulePrefix,
podModulePrefix: config.podModulePrefix,
// Resolver: Resolver
});
//loadInitializers(App, config.modulePrefix);
const bulb = Light.create({age: 22, color: 'yellow'});
//console.log(bulb.get('description')); //The yellow light is set to false
console.log('about to set isOn true');
bulb.set('isOn', true);
console.log('about to set isOn false');
bulb.set('isOn', false);
bulb.set('color', 'yellow');
//console.log(bulb.get('description')); //The yellow light is set to true
//console.log(bulb.get('age'));
//bulb.set('isOn', false);
//console.log(bulb.get('fullDescription')); //The yellow light is set to true and the age is 32
//console.log(bulb.get('pusdoDescription')); //The yellow light is set to true and the age is 32.
export default App;
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'more Ember Twiddle'
});
import Ember from 'ember';
export default Ember.Object.extend( {
isOn: false,
color: 'yellow',
age: null,
description: Ember.computed('isOn', function() {
return'The bulb is '+ this.get('color') + ' and the light is set to ' + this.get('isOn');
}),
fullDescription: Ember.computed('description','age', function() {
return this.get('description') + ' and the age is ' +
this.get('age');
}),
isOnChanged: Ember.observer('isOn', function() {
console.log('isOn value changed to ' + this.get('isOn'));
}),
didAnythingChange: Ember.observer('isOn', 'color', function() {
console.log('either isOn or color changed value');
}),
checkIsOn: Ember.observer('isOn', function() {
Ember.run.once(this,'checkChanged');
}),
checkChanged: Ember.observer('description', function() {
console.log(this.get('description'));
}),
pusdoDescription: Ember.computed.alias('fullDescription')
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{bulb}}
{{outlet}}
<br>
<br>
{
"version": "0.7.2",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.4.3/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/2.4.4/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment