Last active
August 29, 2015 14:03
-
-
Save elisechant/8c982e80350848510d82 to your computer and use it in GitHub Desktop.
Ember Model decorator for decoupling computed properties
This file contains hidden or 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
var UserDecorator = Ember.ObjectProxy.extend({ | |
fullName: function() { | |
return [this.get('firstName'), this.get('lastName')].join(' '); | |
}.property('firstName', 'lastName') | |
}); | |
This file contains hidden or 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
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 | |
}) | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.