2014-05-14 18:36:13 -05:00
|
|
|
export default {
|
2014-03-11 11:23:32 -05:00
|
|
|
name: 'currentUser',
|
2014-05-09 00:00:10 -05:00
|
|
|
after: 'store',
|
2014-03-11 11:23:32 -05:00
|
|
|
|
2014-05-14 18:36:13 -05:00
|
|
|
initialize: function (container, application) {
|
2014-05-09 00:00:10 -05:00
|
|
|
var store = container.lookup('store:main'),
|
|
|
|
preloadedUser = application.get('user');
|
|
|
|
|
|
|
|
// If we don't have a user, don't do the injection
|
|
|
|
if (!preloadedUser) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push the preloaded user into the data store
|
|
|
|
store.pushPayload({
|
|
|
|
users: [preloadedUser]
|
|
|
|
});
|
|
|
|
|
|
|
|
// Signal to wait until the user is loaded before continuing.
|
|
|
|
application.deferReadiness();
|
|
|
|
|
|
|
|
// Find the user (which should be fast since we just preloaded it in the store)
|
|
|
|
store.find('user', preloadedUser.id).then(function (user) {
|
|
|
|
// Register the value for injection
|
|
|
|
container.register('user:current', user, { instantiate: false });
|
2014-03-11 11:23:32 -05:00
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
// Inject into the routes and controllers as the user property.
|
|
|
|
container.injection('route', 'user', 'user:current');
|
|
|
|
container.injection('controller', 'user', 'user:current');
|
2014-03-22 21:31:45 -05:00
|
|
|
|
2014-05-09 00:00:10 -05:00
|
|
|
application.advanceReadiness();
|
|
|
|
});
|
2014-03-11 11:23:32 -05:00
|
|
|
}
|
2014-05-14 18:36:13 -05:00
|
|
|
};
|