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.
For more information, please visit the official docs.
npm install --save @webiny/plugins
Or if you prefer yarn:
yarn add @webiny/plugins
import { plugins } from "@webiny/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!"
});
// anywhere in your app
import { plugins } from "@webiny/plugins";
const pluginList = plugins.byType("say-hi");
pluginList.forEach(plugin => {
// Call "salute" function
plugin.salute();
});
// anywhere in your app
import { plugins } from "@webiny/plugins";
const plugin = plugins.byName("my-plugin");
// Call "salute" function
plugin.salute();
// anywhere in your app
import { plugins } from "@webiny/plugins";
plugins.unregister("my-plugin");