singleton-module-registry
v1.0.1
Published
Implementation of the Registry Pattern to have loosely-coupled modules
Downloads
8
Readme
Singleton Module Registry
Description
Implementation of the Registry Pattern to have loosely-coupled modules in your app. You can either use the singleton provided to just import the library or create as many Registry as you want and pass them to your different modules.
Breaking change notes
- We don't provide event emitter anymore because event emission is meant to decouple modules. But we use dependency injdection for this purpose so event emission is not needed anymore.
- We do not support module interdependency anymore (via the required property) because modules are meant to be decoupled units.
Installation
npm i --save singleton-module-registry
Usage
Using the singleton
import { getRegistrySingleton } from 'singleton-module-registry';
const registry = getRegistrySingleton();
const { moduleA, moduleB } = registry.getModules(['moduleA', 'moduleB']);
Instantiating a new registry
import { ModuleRegistry } from 'singleton-module-registry';
const registry1 = new ModuleRegistry();
registry1.registerModule('moduleA', {
sum: (a, b) => a + b,
product: (a, b) => a * b,
});
const { moduleA } = registry.getModules(['moduleA']);
console.log(moduleA.sum(1, 2)); // prints 3