Skip to content

Instantly share code, notes, and snippets.

@ErikCH
Last active September 21, 2015 19:13
Show Gist options
  • Save ErikCH/26b48e5c605e7d0a7b6f to your computer and use it in GitHub Desktop.
Save ErikCH/26b48e5c605e7d0a7b6f to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
var Light = Ember.Object.extend({
isOn: false,
color: 'yellow',
age: null,
description: Ember.computed('isOn','color',function() {
return 'The ' + this.get('color') + ' light is ' + (this.get('isOn') ? 'on' : 'off');
}),
// fullDescription: Ember.computed('description','age',function() {
// return this.get('description') + ' and the age is ' + //this.get('age')
// }),
// desc: Ember.computed.alias('description'),
// isOnChanged: Ember.observer('isOn','color',function() {
// })
});
Light.reopen({
checkIsOn: Ember.observer('isOn','color', function() {
Ember.run.once(this,'checkChanged');
}),
checkChanged: Ember.observer('description',function() {
console.log(this.get('description'));
})
});
var bulb1 = Light.create({age: 22});
bulb1.set('isOn', true);
bulb1.set('color', 'blue');
export default Ember.Controller.extend({
appName:'Ember Twiddle',
bulb: Light.create({age: 19}),
actions:{
buttonPressed: function() {
this.get('bulb').toggleProperty('isOn');
this.get('bulb').set('color','red');
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{bulb.description}}
<br>
{{bulb.fullDescription}}
<br>
<button {{action 'buttonPressed'}}>button</button>
<br>
<br>
{
"version": "0.4.10",
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember.debug.js",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/1.13.11/ember-data.js",
"ember-template-compiler": "https://cdnjs.cloudflare.com/ajax/libs/ember.js/1.13.9/ember-template-compiler.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment