I am currently trying to access my ember-engines wherever I am. I want to have the name of each engines, because I want to display every engines in my main application.
The problem here is that I can't find a way to catch there name, because the engines are loaded only if we navigate to a page related to the engines.
This is the services that is normally catching every name of each engines, call it engines-manager:
import Ember from 'ember';
import App from '../app';
/**
* This service will help us manage every engines that are in our application,
*/
export default Ember.Service.extend({
availableEngines: [],
addEngines(engines)
{
this.get('availableEngines').push(engines);
console.log(this.get('availableEngines'));
}
});
And then in every engine, more precisely, in every anEngines/addon/engine.js of every engine, I put :
import Engine from 'ember-engines/engine';
import loadInitializers from 'ember-load-initializers';
import Resolver from './resolver';
import config from './config/environment';
import Ember from 'ember';
const { modulePrefix } = config;
const Eng = Engine.extend({
modulePrefix,
Resolver,
dependencies: {
services: [
'engines-manager'
]
},
enginesManager: Ember.inject.service('engines-manager'),
init() {
this._super(...arguments);
this.get('enginesManager').addEngines('nameOfMyEngines');
}
});
loadInitializers(Eng, modulePrefix);
export default Eng;
This method is working if we go on the engines related page, but I dont want to go to every page to load them, so here is my question: how to always load an ember-engines?
PS: setting my lazy-loading
to true
or false
doesn't change anything.
Thanks to the slack community, we found a workaround. The engine are not means to load if we don't enter it.
So here is a workaround that don't really respond to the answer, but at least you can access to the data present in the engine, like the name, or the services.
First
You have to create a container in a services, in your app:
That's it, if you know how to use this data, you have the capacity to fetch the name of the engines for example.
Secondly
You have now a container, but the data cannot be use like this, container here is not a JSON object for example.
Here
newObject
is an array with the name of every engines that are present in your app.js in it. Hope that help some people. I will not accept this response, because this is not what the question ask, but this is a beginning.