0.0.3 • Published 3 years ago
@whalecloud/dxp-plugins v0.0.3
@whalecloud/dxp-plugins
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 @whalecloud/dxp-plugins
Or if you prefer yarn:
yarn add @whalecloud/dxp-plugins
Usage
Adding a plugin
import { plugins } from "@whalecloud/dxp-plugins";
// Add a plugin
plugins.register({
name: "my-plugin",
type: "say-hi",
salute: () => "Hi!"
});
plugins.register({
name: "my-second-plugin",
type: "say-hi",
salute: () => "Yo!"
});
Getting plugins by type
// anywhere in your app
import { plugins } from "@whalecloud/dxp-plugins";
const pluginList = plugins.byType("say-hi");
pluginList.forEach(plugin => {
// Call "salute" function
plugin.salute();
});
Getting a single plugin by name
// anywhere in your app
import { plugins } from "@whalecloud/dxp-plugins";
const plugin = plugins.byName("my-plugin");
// Call "salute" function
plugin.salute();
Removing a plugin
// anywhere in your app
import { plugins } from "@whalecloud/dxp-plugins";
plugins.unregister("my-plugin");