I’m very new to ember as my last post shows. But I’m getting more and more familiar with it.
We are using Ember-Cli and I’m wondering what is the best way to store functionality which is needed throughout the whole app.
Specifically I have an object which calculates all the permissions in our app. Right now I just do an ES6 import at every file which needs this permission object. But somehow it does not feel super smart. Is it better to use some kind of dependency injection? (I’m not very familiar with Ember dependency injection).
What makes this quite tricky is, that I have to fetch the roles asynchronously from the backend and then store this roles in the permissions object. Right now I initialize this permission object in the application route. I’m also not sure if this is the best place.
Nevertheless this solution is working right now but I think I should refactor it to accomplish a more “Ember”-way of accomplishing this. I’m looking forward to here some design advices from you guys
Sounds like dependency injection is definitely the way to go. It’s quite easy. Although the Ember guides are outdated (just as the documentation), this article explains it quite well:
import Ember from 'ember';
import config from './config/environment';
export default Ember.ObjectController.extend({
...
var hello = config.APP.MY_GLOBAL;
...
});
Thanks for the hints and links I think the service-solution is more what I’m looking for. @kgish: I want to share whole functionallity across my app. So I think storing it on the ENV variable isn’t the best place. What I want to do is something like this (just super quick pseudo-code to get the idea):