Skip to content

Instantly share code, notes, and snippets.

@rondale-sc
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save rondale-sc/2552a03941aef895f375 to your computer and use it in GitHub Desktop.

Select an option

Save rondale-sc/2552a03941aef895f375 to your computer and use it in GitHub Desktop.
export default Ember.Route.extend({
beforeModel() {
this.get('currentUser').fetchCurrentUser().then(()=>{
// do stuff
});
}
})
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);
});
}
});
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