Skip to content

Instantly share code, notes, and snippets.

@ahawkins
Last active December 14, 2015 21:49
Show Gist options
  • Save ahawkins/5153735 to your computer and use it in GitHub Desktop.
Save ahawkins/5153735 to your computer and use it in GitHub Desktop.
DS.Model.reopenClass({
scope: function(name, fn) {
Ember.defineProperty(this, '_'+name+'Filter', Ember.computed(function() {
return this.filter(fn);
}));
Ember.defineProperty(this, name, Ember.computed('_'+name+'Filter.@each.id', function() {
return this.get('_'+name+'Filter')
}));
this[name] = function() {
return Ember.get(this, '_'+name);
};
}
});
// Long hand
App.Page = Ember.Object.extend({
contacts: (function() {
return this.get('contactsFilter');
}).property('contactsFilter.@each.id')
contactsFilter: (function() {
return Contact.filter(function() {
// your logic
});
}).property()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment