diff --git a/packages/di/di.tsx b/packages/di/di.tsx index b0369ff8..6a072341 100644 --- a/packages/di/di.tsx +++ b/packages/di/di.tsx @@ -38,28 +38,38 @@ export function withRegistry

(...registries: Registry[]) { }; } -export interface IRegistry { +export interface IRegistryOptions { id: string; - inverted?: true; + inverted?: boolean; } -export class Registry extends Map { +export class Registry { id: string; - inverted?: boolean = false; + inverted: boolean; - constructor(options: IRegistry) { - super(); - this.id = options.id; - this.inverted = options.inverted; + private components = new Map(); + + constructor({ id, inverted = false }: IRegistryOptions) { + this.id = id; + this.inverted = inverted; + } + + set(id: string, component: React.ComponentType) { + this.components.set(id, component); } - get

(id: any): React.ComponentType

{ + /** + * Get react component from registry by id. + * + * @param id component id + */ + get(id: string): React.ComponentType { if (__DEV__) { - if (!this.has(id)) { + if (!this.components.has(id)) { throw new Error(`Component with id '${id}' not found.`); } } - return this.get(id); + return this.components.get(id); } }