Last active
August 29, 2015 14:07
-
-
Save lukes/af67d1dae2702b92ac8e to your computer and use it in GitHub Desktop.
Using Ember.ObjectProxy for currentUser
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
// (Rename to current-user.js and place in /initializers) | |
// Ember now complains that you can't type inject a controller into a controller | |
// so use an Ember.ObjectProxy for currentUser instead. | |
// | |
// Ember.ObjectProxy allows you to set a content value, and will delegate | |
// all getters and setters to its content. | |
import DS from "ember-data"; | |
import CurrentUser from "../models/current-user"; | |
export default { | |
name: 'currentUser', | |
after: 'store', | |
initialize: function(container, application) { | |
var store = container.lookup('store:main'); | |
var user = store.push('user', { id: 1, first_name: 'User', last_name: 'Name' }); | |
container.register('user:current', CurrentUser, { singleton: true }); | |
// .create() our singleton user and set its content | |
var currentUser = container.lookup('user:current'); | |
currentUser.set('content', user); | |
container.typeInjection('controller', 'currentUser', 'user:current'); | |
container.typeInjection('route', 'currentUser', 'user:current'); | |
container.typeInjection('view', 'currentUser', 'user:current'); | |
} | |
}; |
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
// (Rename to current-user.js and place in /models) | |
import Ember from 'ember'; | |
export default Ember.ObjectProxy.extend(Ember.PromiseProxyMixin, {}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment