Skip to content

Instantly share code, notes, and snippets.

@elisechant
Last active August 29, 2015 14:03
Show Gist options
  • Save elisechant/8c982e80350848510d82 to your computer and use it in GitHub Desktop.
Save elisechant/8c982e80350848510d82 to your computer and use it in GitHub Desktop.
Ember Model decorator for decoupling computed properties
var UserDecorator = Ember.ObjectProxy.extend({
fullName: function() {
return [this.get('firstName'), this.get('lastName')].join(' ');
}.property('firstName', 'lastName')
});
App.UserRoute = Ember.Route.extend({
model: function(params) {
return this.get('store').find('user', params.user_id).then(function(user) {
return UserDecorator.create({
content: user
})
});
}
});
@elisechant
Copy link
Author

This type of controller uses the Ember.ObjectProxy (http://emberjs.com/api/classes/Ember.ObjectProxy.html) mixin, which enables a proxy (in this case, the controller) to forward all requests to the properties that it has not defined.

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