opp-core
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-alpha.33 • Public • Published

opp-core

Register and start plugins.

Installation

Using npm:

$ npm install --save opp-core

Usage

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: true means only bootstrap this plugin when depended by other plugins, default: false;

  • container: id of DOM, means render content under this DOM, as parameter element of mount;

  • dependencies: array of name, plugin would bootstrap after dependencies plugins have been bootstrapped;

  • bootstrap: async function, plugin will been marked as bootstrapped after executing bootstrap callback;

  • mount: async function, with two parameters: element (form container), props (from PluginRender);

  • update: async function, with one parameter: props (from PluginRender);

  • unmount: async function, with one parameter: props (from PluginRender);

  • hooks: map of TapableHook,to export internal interfaces to other plugins.

  • TapableHook: from opp-tapable;

  • PluginRender: from opp-react and opp-react;

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']>;

/opp-core/

    Package Sidebar

    Install

    npm i opp-core

    Weekly Downloads

    576

    Version

    1.0.0-alpha.33

    License

    MIT

    Unpacked Size

    87 kB

    Total Files

    20

    Last publish

    Collaborators

    • xiaoshuang