Skip to content

Instantly share code, notes, and snippets.

@wycats
Created March 13, 2012 04:03
Show Gist options
  • Select an option

  • Save wycats/2026659 to your computer and use it in GitHub Desktop.

Select an option

Save wycats/2026659 to your computer and use it in GitHub Desktop.
PhoneNumber = Ember.Object.extend({
areaCode: null,
number: null
});
Person = Ember.Object.extend({
areaCode: function() {
var areaCodes = {}, phoneNumbers = this.get('phoneNumber');
for (var i=0, l=phoneNumbers.length; i<l; i++) {
areaCodes[phoneNumbers[i]] = true;
}
return Object.keys(areaCodes);
}.property('phoneNumbers.@each.areaCode'),
wifeName: function() {
// how do you tell the difference between this and a call to `name`
// from inside of `wife`
return this.get('wife').get('name');
}.property('wife.name')
});
// The reason this matters is that Ember manages memory in chained
// property observers automatically, which means that, for example,
// if a view is re-rendered, all chained observers, including
// across computed properties, are torn down.
//
// Failing to do this will cause objects to be held onto indefinitely,
// which practically causes significant memory leaks.
@elight
Copy link
Copy Markdown

elight commented Mar 13, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment