1.0.1 • Published 3 years ago

@mete-work/plugins v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

@mete-work/plugins

npm.io npm.io code style: prettier

A simple registry that stores all plugins in a shared object. The only requirement for a plugin is to have a name and a type properties. The rest is entirely up to you.

There is nothing spectacular going on under the hood, just a simple object for storing references and a few utility functions.

Install

npm install --save @mete-work/plugins

Or if you prefer yarn:

yarn add @mete-work/plugins

Usage

Adding a plugin

import { registerPlugins } from "@mete-work/plugins";

// Add a plugin
registerPlugins({
    name: "my-plugin",
    type: "say-hi",
    render: () => "Hi!"
});

registerPlugins({
    name: "my-second-plugin",
    type: "say-hi",
    render: () => "Yo!"
});

Getting plugins by type

// anywhere in your app
import { getPlugins } from "@mete-work/plugins";

const plugins = getPlugins("say-hi");
plugins.forEach(plugin => {
    // Call "render" function
    plugin.render();
});

Getting a single plugin by name

// anywhere in your app
import { getPlugin } from "@mete-work/plugins";

const plugin = getPlugin("my-plugin");
// Call "render" function
plugin.render();

Removing a plugin

// anywhere in your app
import { unregisterPlugin } from "@mete-work/plugins";

unregisterPlugin("my-plugin");
1.0.1

3 years ago

1.0.0

3 years ago