singleton-module-registry
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Singleton Module Registry

CircleCI

Codacy Badge

Codacy Badge

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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    8
    • latest

Version History

Package Sidebar

Install

npm i singleton-module-registry

Weekly Downloads

8

Version

1.0.1

License

MIT

Unpacked Size

105 kB

Total Files

38

Last publish

Collaborators

  • chipp972