Getting startedWhy use Encodable?Contributing guidelinesAbout
Gallery
Guides
Encodable API
Submodule API
@encodable/registry
All-purpose map data structure on steroids.
- Can be used to store state as global, making a true singleton that can be used across packages.
- Can be used locally as well.
- Support asynchronous values.
Install
npm install @encodable/registry global-box
Example usage
Create registries
import { Registry, SyncRegistry, makeSingleton } from '@encodable/registry';// local registry (when globalId is not defined)const registry = new Registry<string>();// global registryconst globalRegistry = new Registry({ globalId: 'my-global-key' });// create a singleton factory functionconst getSingleton = makeSingleton(() => new Registry({ globalId: 'my-global-key' }));
Registering
// constant valueregistry.registerValue('key', 1);// sync loaderregistry.registerLoader('key', () => 1);// async loaderregistry.registerLoader('key', () => Promise.resolve(1));
Registry
can support both constant values and sync/async loaders.SyncRegistry
only support constant values and sync loaders.