From 9a3063377af82a363aa311dcd7a9636ff8dfcaab Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 7 Feb 2023 11:34:06 +0100 Subject: [PATCH] backend-plugin-api: simplify feature factory implementations Signed-off-by: Patrik Oldsberg --- .../src/wiring/factories.ts | 43 ++++++------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/packages/backend-plugin-api/src/wiring/factories.ts b/packages/backend-plugin-api/src/wiring/factories.ts index 26a65c292a..be55474904 100644 --- a/packages/backend-plugin-api/src/wiring/factories.ts +++ b/packages/backend-plugin-api/src/wiring/factories.ts @@ -17,7 +17,6 @@ import { BackendModuleRegistrationPoints, BackendPluginRegistrationPoints, - BackendRegistrationPoints, BackendFeature, ExtensionPoint, } from './types'; @@ -86,19 +85,14 @@ export interface BackendPluginConfig { export function createBackendPlugin( config: BackendPluginConfig | ((...params: TOptions) => BackendPluginConfig), ): (...params: TOptions) => BackendFeature { - if (typeof config === 'function') { - return (...options: TOptions) => { - const c = config(...options); - return { - ...c, - id: c.pluginId, - }; + const configCallback = typeof config === 'function' ? config : () => config; + return (...options: TOptions) => { + const c = configCallback(...options); + return { + ...c, + id: c.pluginId, }; - } - return () => ({ - ...config, - id: config.pluginId, - }); + }; } /** @@ -132,21 +126,12 @@ export interface BackendModuleConfig { export function createBackendModule( config: BackendModuleConfig | ((...params: TOptions) => BackendModuleConfig), ): (...params: TOptions) => BackendFeature { - if (typeof config === 'function') { - return (...options: TOptions) => { - const c = config(...options); - return { - id: `${c.pluginId}.${c.moduleId}`, - register: c.register, - }; + const configCallback = typeof config === 'function' ? config : () => config; + return (...options: TOptions) => { + const c = configCallback(...options); + return { + id: `${c.pluginId}.${c.moduleId}`, + register: c.register, }; - } - return () => ({ - id: `${config.pluginId}.${config.moduleId}`, - register(register: BackendRegistrationPoints) { - return config.register({ - registerInit: register.registerInit.bind(register), - }); - }, - }); + }; }