opp-core
v1.0.2
Published
Register and start plugins.
Readme
opp-core
Register and start plugins.
Installation
Using npm:
$ npm install --save opp-coreUsage
import { start, registerPlugin } from 'opp-core';
const parentPlugin = {
name: 'parent',
bootstrap: () => {
console.log('parent bootstrapped');
},
};
const childPlugin = {
name: 'child',
dependencies: ['parent'],
bootstrap: () => {
console.log('child bootstrapped');
},
};
registerPlugin(parentPlugin);
registerPlugin(childPlugin);
start();Documentation
Plugin Definition
name: unique for every plugin, required;
lazy:
truemeans only bootstrap this plugin when depended by other plugins, default:false;container: id of DOM, means render content under this DOM, as parameter
elementofmount;dependencies: array of
name, plugin would bootstrap after dependencies plugins have been bootstrapped;bootstrap:
asyncfunction, plugin will been marked as bootstrapped after executingbootstrapcallback;mount:
asyncfunction, with two parameters: element (formcontainer), props (fromPluginRender);update:
asyncfunction, with one parameter: props (fromPluginRender);unmount:
asyncfunction, with one parameter: props (fromPluginRender);hooks: map of
TapableHook,to export internal interfaces to other plugins.TapableHook: from opp-tapable;
type Plugin = {
name: string;
lazy?: boolean;
container?: string;
dependencies?: string[];
bootstrap?: () => Promise<void>;
mount?: (element: HTMLElement, props: any) => Promise<void>;
update?: (props: any) => Promise<void>;
unmount?: () => Promise<void>;
hooks?: { [key: string]: TapableHook };
}; registerPlugin
async function, register plugin to OPP framework, resolve after registered.
registerPlugin will not register plugins immediately, only register those after called start.
type registerPlugin = (plugin: Plugin) => Promise(void);
type registerPlugin = (plugins: Plugin[]) => Promise(void);
type registerPlugin = (fetchPlugin: () => Promise<Plugin>) => Promise(void);
type registerPlugin = (fetchPlugins: () => Promise<Plugin[]>) => Promise(void);
type registerPlugin = (exported: { default: Plugin }) => Promise(void);
type registerPlugin = (exported: { default: Plugins }) => Promise(void);replacePlugin
async function, replace same name plugin to OPP framework, resolve after replaced.
type replacePlugin = (plugin: Plugin) => Promise(void);
type replacePlugin = (plugins: Plugin[]) => Promise(void);
type replacePlugin = (fetchPlugin: () => Promise<Plugin>) => Promise(void);
type replacePlugin = (fetchPlugins: () => Promise<Plugin[]>) => Promise(void);
type replacePlugin = (exported: { default: Plugin }) => Promise(void);
type replacePlugin = (exported: { default: Plugins }) => Promise(void);unregisterPlugin
async function, unregister plugin from OPP framework, will trigger unmount.
type replacePlugin = (name: string) => Promise(void);
type replacePlugin = (plugin: Plugin) => Promise(void);start
async function, resolve after all plugins registered, will trigger bootstrap and mount.
type start = () => async(void);getPlugin
sync function, find plugin by name, and result plugin.hooks.
type getPlugin = (name: string) => Plugin['hooks'];fetchPlugin
async function, find plugin by name, and result plugin.hooks.
type fetchPlugin = (name: string) => Promise<Plugin['hooks']>;