[uiExports] execute default injectedVars functions early
This commit is contained in:
parent
1dcfed6597
commit
e120e449f8
|
@ -34,7 +34,7 @@ module.exports = function ({ Plugin }) {
|
|||
},
|
||||
|
||||
uiExports: {
|
||||
injectVars(server, options) {
|
||||
injectDefaultVars(server, options) {
|
||||
return {
|
||||
esRequestTimeout: options.requestTimeout,
|
||||
esShardTimeout: options.shardTimeout,
|
||||
|
|
|
@ -36,7 +36,7 @@ module.exports = function (kibana) {
|
|||
}
|
||||
},
|
||||
|
||||
injectVars(server, options) {
|
||||
injectDefaultVars(server, options) {
|
||||
return {
|
||||
kbnIndex: options.index
|
||||
};
|
||||
|
|
|
@ -59,11 +59,6 @@ module.exports = async (kbnServer, server, config) => {
|
|||
}
|
||||
});
|
||||
|
||||
const getDefaultInjectedVars = once(function createDefaultInjectedVars() {
|
||||
const injectors = uiExports.defaultVariableInjectors;
|
||||
return defaults({}, ...injectors.map(injector => (injector() || {})));
|
||||
});
|
||||
|
||||
server.decorate('reply', 'renderApp', function (app) {
|
||||
const payload = {
|
||||
app: app,
|
||||
|
@ -72,7 +67,7 @@ module.exports = async (kbnServer, server, config) => {
|
|||
buildNum: config.get('pkg.buildNum'),
|
||||
buildSha: config.get('pkg.buildSha'),
|
||||
basePath: config.get('server.basePath'),
|
||||
vars: defaults(app.getInjectedVars() || {}, getDefaultInjectedVars()),
|
||||
vars: defaults(app.getInjectedVars() || {}, uiExports.defaultInjectedVars),
|
||||
};
|
||||
|
||||
return this.view(app.templateName, {
|
||||
|
|
|
@ -11,7 +11,7 @@ class UiExports {
|
|||
this.exportConsumer = _.memoize(this.exportConsumer);
|
||||
this.consumers = [];
|
||||
this.bundleProviders = [];
|
||||
this.defaultVariableInjectors = [];
|
||||
this.defaultInjectedVars = {};
|
||||
}
|
||||
|
||||
consumePlugin(plugin) {
|
||||
|
@ -88,10 +88,10 @@ class UiExports {
|
|||
});
|
||||
};
|
||||
|
||||
case 'injectVars':
|
||||
case 'injectDefaultVars':
|
||||
return (plugin, injector) => {
|
||||
plugin.extendRegister((server, options) => {
|
||||
this.defaultVariableInjectors.push(() => injector.call(plugin, server, options));
|
||||
plugin.extendRegister(async (server, options) => {
|
||||
_.merge(this.defaultInjectedVars, await injector.call(plugin, server, options));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue