Last active
January 31, 2016 17:55
-
-
Save ivanvanderbyl/4560416 to your computer and use it in GitHub Desktop.
Using Ember initializers and injections to setup the `currentUser` within your app.
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.AccountEditRoute = Ember.Route.extend({ | |
setupController: function(controller) { | |
controller.set('content', this.get('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
%noscript | |
.container | |
.alert | |
%strong | |
Javascript is disabled! | |
The AppName UI is built entirely in Javascript, as such you need to enable | |
Javascript in your browser to continue. | |
:javascript | |
var currentUser = jQuery.parseJSON('#{current_user_json}'); |
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
Ember.Application.initializer({ | |
name: "currentUser", | |
initialize: function(container, application) { | |
var store = container.lookup('store:main'); | |
var obj = store.load(CrashLog.User, currentUser); | |
container.optionsForType('user', { instantiate: false, singleton: true }); | |
container.register('user', 'current', CrashLog.User.find(obj.id)); | |
} | |
}); | |
Ember.Application.initializer({ | |
name: "injectCurrentUser", | |
after: 'currentUser', | |
initialize: function(container) { | |
container.injection('controller:application', 'currentUser', 'user:current'); | |
container.typeInjection('route', 'currentUser', 'user:current'); | |
} | |
}); |
@amaanr @AlexanderZaytsev I use the readiness calls that @listrophy suggests.
Remember to tell currentUser Initializer to fire up after loading store, otherwise store will be undefined
Ember.Application.initializer({
name: 'currentUser',
after: 'store',
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a non-private alternative to
typeInjection
?