Skip to content

Instantly share code, notes, and snippets.

@hjumeau
Last active June 1, 2016 09:12
Show Gist options
  • Save hjumeau/c7097b635dd5542d2ed36d8deef2c913 to your computer and use it in GitHub Desktop.
Save hjumeau/c7097b635dd5542d2ed36d8deef2c913 to your computer and use it in GitHub Desktop.
Object Model
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')}`;
}),
description: Ember.computed('fullName', 'age', 'country', function() {
return `${this.get('fullName')}; Age: ${this.get('age')}; Country: ${this.get('country')}`;
}),
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;
}
}),
fullNameChanged: Ember.observer('fullName', function() {
// deal with the change
document.write(`fullName changed to: ${this.get('fullName')}`);
})
});
var captainAmerica = Person.create({
firstName: 'Steve',
lastName: 'Rogers',
age: 80,
country: 'USA'
});
captainAmerica.set('firstName', 'Alain');
captainAmerica.get('firtName');
//document.write(captainAmerica.get('fullName'));
//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