Last active
August 29, 2015 14:27
-
-
Save rondale-sc/2552a03941aef895f375 to your computer and use it in GitHub Desktop.
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
| export default Ember.Route.extend({ | |
| beforeModel() { | |
| this.get('currentUser').fetchCurrentUser().then(()=>{ | |
| // do stuff | |
| }); | |
| } | |
| }) |
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
| import Ember from "ember"; | |
| export default Ember.Service.extend({ | |
| store: Ember.inject.service('store:main'), | |
| _currentUser: null, | |
| unknownProperty: function(key) { | |
| return this.get('_currentUser').get(key); | |
| }, | |
| fetchCurrentUser: function() { | |
| this.get('store').find('managedUser', 'current').then((user) => { | |
| this.set('_currentUser', user); | |
| }); | |
| } | |
| }); |
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
| import Ember from "ember";; | |
| import CurrentUserService from "frontend/services/current-user"; | |
| const initialize = function(registry, app) { | |
| app.register("user:current", CurrentUserService, { instantiate: true, singleton: true }); | |
| ["route", "controller", "component"].forEach(function(item){ | |
| app.inject(item, "currentUser", "user:current") | |
| }); | |
| }; | |
| export default { name: "current-user", after: "store", initialize: initialize }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment