[server/plugin] do not leak server.register() implemenation detail
This commit is contained in:
parent
b77486ba75
commit
dcd7bee8cc
|
@ -4,7 +4,7 @@ import Bluebird, { attempt, fromNode } from 'bluebird';
|
|||
import { basename, resolve } from 'path';
|
||||
import { inherits } from 'util';
|
||||
|
||||
const extendRegisterFns = Symbol('extend register');
|
||||
const extendInitFns = Symbol('extend plugin initialization');
|
||||
|
||||
const defaultConfigSchema = Joi.object({
|
||||
enabled: Joi.boolean().default(true)
|
||||
|
@ -59,7 +59,7 @@ module.exports = class Plugin {
|
|||
this.externalInit = opts.init || _.noop;
|
||||
this.getConfigSchema = opts.config || _.noop;
|
||||
this.init = _.once(this.init);
|
||||
this[extendRegisterFns] = [];
|
||||
this[extendInitFns] = [];
|
||||
|
||||
if (opts.publicDir === false) {
|
||||
this.publicDir = null;
|
||||
|
@ -104,7 +104,7 @@ module.exports = class Plugin {
|
|||
const asyncRegister = async (server, options) => {
|
||||
this.server = server;
|
||||
|
||||
await Promise.all(this[extendRegisterFns].map(async fn => {
|
||||
await Promise.all(this[extendInitFns].map(async fn => {
|
||||
await fn.call(this, server, options);
|
||||
}));
|
||||
|
||||
|
@ -143,8 +143,8 @@ module.exports = class Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
extendRegister(fn) {
|
||||
this[extendRegisterFns].push(fn);
|
||||
extendInit(fn) {
|
||||
this[extendInitFns].push(fn);
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
|
|
|
@ -55,7 +55,7 @@ class UiExports {
|
|||
urlBasePath: this.urlBasePath
|
||||
}));
|
||||
|
||||
plugin.extendRegister((server, options) => { // eslint-disable-line no-loop-func
|
||||
plugin.extendInit((server, options) => { // eslint-disable-line no-loop-func
|
||||
const wrapped = app.getInjectedVars;
|
||||
app.getInjectedVars = () => wrapped.call(plugin, server, options);
|
||||
});
|
||||
|
@ -90,7 +90,7 @@ class UiExports {
|
|||
|
||||
case 'injectDefaultVars':
|
||||
return (plugin, injector) => {
|
||||
plugin.extendRegister(async (server, options) => {
|
||||
plugin.extendInit(async (server, options) => {
|
||||
_.merge(this.defaultInjectedVars, await injector.call(plugin, server, options));
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue