UNPKG

redux-providers

Version:

Minimalist dependency injection system for redux. Create providers to be injected and used in redux reducers.

22 lines (17 loc) 552 B
import "reflect-metadata"; export class InstanceContainer { private container: Map<string, any>; constructor() { this.container = new Map<string, any>(); } get<T>(instanceIdentifier: string): T { const instance = this.container.get(instanceIdentifier); if (!instance) { throw new Error("Could not find instance (" + instanceIdentifier + ") in the container! Did you provide it in the module?"); } return instance; } add<T>(instanceIdentifier: string, instance: T): void { this.container.set(instanceIdentifier, instance); } }