npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

opp-core

v1.0.0-alpha.46

Published

Register and start plugins.

Downloads

365

Readme

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