Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
Created January 22, 2014 22:39
Show Gist options
  • Select an option

  • Save jamesarosen/8568849 to your computer and use it in GitHub Desktop.

Select an option

Save jamesarosen/8568849 to your computer and use it in GitHub Desktop.
Ember 1 and volatile properties with dependent keys

In Ember 0.9, we had properties that looked like

age: function() {
  return this.get('createdAt') - new Date();
}.property('createdAt').volatile()

The .property('createdAt') means, "recompute this every time createdAt changes".

The .volatile() means, "recompute this every time you get it."

That means that if we had a template,

Age: {{age}}

the template would be correct on render and when computedAt changes.

In Ember 1.0, this does not work. We need to do something more like

age: function() {
  return this.get('createdAt') - new Date();
}.property().volatile()

expireAge: function() {
  this.notifyPropertyChange('age');
}.observes('createdAt')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment