Last active
June 1, 2016 09:12
-
-
Save hjumeau/c7097b635dd5542d2ed36d8deef2c913 to your computer and use it in GitHub Desktop.
Object Model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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