Plugin config should support promises.
JoshMcCullough opened this issue · 0 comments
JoshMcCullough commented
Current behavior:
Plugin configuration callbacks are expected run synchronously.
Expected/desired behavior:
- What is the expected behavior?
The callback passed intoaurelia.use.plugin
to configure the plugin should allow for the return of aPromise
. Configuration of Aurelia should not be considered "done" until all plugin configuration callbacks have been resolved or rejected. - What is the motivation / use case for changing the behavior?
To allow for more complex/async configuration of plugins, before Aurelia is loaded.
Example
aurelia.use
.standardConfiguration()
.plugin('aurelia-configuration', config => {
config.setDirectory(System.baseURL + '/config');
config.setConfig('application.json');
config.setEnvironment('development');
// Returns a promise.
return config.mergeConfigFile(`${config.directory}/application-overrides.json`);
});
return aurelia.start().then(a => a.setRoot());
Workaround
let promises = [];
aurelia.use
.standardConfiguration()
.plugin('aurelia-configuration', (config) => {
config.setDirectory(System.baseURL + '/config');
config.setConfig('application.json');
config.setEnvironment('development');
promises.push(config.mergeConfigFile(`${config.directory}/application-overrides.json`));
});
// Allow any async configuration to complete before starting Aurelia.
return Promise
.all(promises)
.then(() => {
return aurelia.start().then(a => a.setRoot());
});