Skip to content

Instantly share code, notes, and snippets.

@hjumeau
Last active January 5, 2016 14:25
Show Gist options
  • Save hjumeau/4dae8abddab27ac0da8e to your computer and use it in GitHub Desktop.
Save hjumeau/4dae8abddab27ac0da8e to your computer and use it in GitHub Desktop.
cumputedPro
import Ember from 'ember';
var Person = Ember.Object.extend({
firstName: null,
lastName: null,
age: null,
country: null,
dateOfDeath: null,
fullName: Ember.computed('firstName', 'lastName', function() {
return `${this.get('firstName')} ${this.get('lastName')}`;
}),
isDead: Ember.computed('dateOfDeath', {
get(key) {
return !!this.get('dateOfDeath');
},
set(key, value) {
if (value) {
this.set('dateOfDeath', new Date());
} else {
this.set('dateOfDeath', null);
}
return value;
}
}),
description: Ember.computed('fullName', 'age', 'country', function() {
return `${this.get('fullName')}; Age: ${this.get('age')}; Country: ${this.get('country')}`;
})
});
var captainAmerica = Person.create({
firstName: 'Steve',
lastName: 'Rogers',
age: 80,
country: 'USA'
});
//document.write(captainAmerica.get('description'));
//document.write('<br> is Dead = ' + captainAmerica.get('isDead'));
captainAmerica.set('isDead', true);
//document.write('<br> date of death ' + captainAmerica.get('dateOfDeath'));
{
"version": "0.5.0",
"EmberENV": {
"FEATURES": {}
},
"options": {
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "2.2.0",
"ember-data": "2.2.0",
"ember-template-compiler": "2.2.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment