The RudderStack Plugin Engine uses a plugin-based architecture to decouple business logic and allow for extensible modules.
Core Concepts:
- Extension Point: A string representing a path in a plugin object (e.g.,
menu.processMenuItems). It acts as a hook that modules can call to allow plugins to contribute logic or data. - Plugin: A JavaScript object that contributes to one or more extension points. Every plugin must have a unique
name. - Provider/Consumer Relationship: An extensible module (the provider) calls
plugin.invoke(extPoint) or plugin.getPlugins(extPoint). A plugin (the consumer) defines a structure that matches that extension point path.
Example Workflow:
- A component defines an extension point:
const menuItems = [];
plugin.invoke('menu.processMenuItems', menuItems);
- A plugin contributes to it:
plugin.register({
name: 'samplePlugin',
menu: {
processMenuItems(items) {
items.push({ label: 'label', link: 'hello/sample' });
},
},
});
const menuItems = [];
plugin.invoke('menu.processMenuItems', menuItems);
plugin.register({
name: 'samplePlugin',
menu: {
processMenuItems(items) {
items.push({ label: 'label', link: 'hello/sample' });
},
},
});