feat: createBackend, createPreload, createRenderer

Introduced the mentioned helper methods in order to help split big plugins into manageable chunks.
This commit is contained in:
Angelos Bouklis
2023-11-28 00:06:52 +02:00
parent eaaf170cc8
commit 04d7b32d3f
4 changed files with 219 additions and 134 deletions

View File

@ -9,6 +9,8 @@ import type {
PluginConfig,
PluginLifecycleExtra,
PluginLifecycleSimple,
PluginLifecycle,
RendererPluginLifecycle,
} from '@/types/plugins';
export const createPlugin = <
@ -29,6 +31,37 @@ export const createPlugin = <
},
) => def;
export const createBackend = <
BackendProperties,
Config extends PluginConfig = PluginConfig,
>(
back: {
[Key in keyof BackendProperties]: BackendProperties[Key];
} & PluginLifecycle<Config, BackendContext<Config>, BackendProperties>,
) => back;
export const createPreload = <
PreloadProperties,
Config extends PluginConfig = PluginConfig,
>(
preload: {
[Key in keyof PreloadProperties]: PreloadProperties[Key];
} & PluginLifecycle<Config, PreloadContext<Config>, PreloadProperties>,
) => preload;
export const createRenderer = <
RendererProperties,
Config extends PluginConfig = PluginConfig,
>(
renderer: {
[Key in keyof RendererProperties]: RendererProperties[Key];
} & RendererPluginLifecycle<
Config,
RendererContext<Config>,
RendererProperties
>,
) => renderer;
type Options<Config extends PluginConfig> =
| { ctx: 'backend'; context: BackendContext<Config> }
| { ctx: 'preload'; context: PreloadContext<Config> }