UNPKG

redux-providers

Version:

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

18 lines (16 loc) 785 B
import "reflect-metadata"; import { GenericClassDecorator } from "../../types/types"; import { Constructable } from "../../types/constructable"; import { METADATA_KEY } from "../../constants/metadata.keys"; import { ERRORS_MSGS } from "../../constants/error-msgs"; export class ActionHandlerType {} export function ActionHandler<T extends ActionHandlerType>(): GenericClassDecorator<Constructable<T>> { return (target: Constructable<T>) => { if (Reflect.hasOwnMetadata(METADATA_KEY.ACTION_HANDLER_PARAM_TYPES, target)) { throw new Error(ERRORS_MSGS.DUPLICATED_ACTION_HANDLER_DECORATOR); } var types = Reflect.getMetadata(METADATA_KEY.DESIGN_PARAM_TYPES, target) || []; Reflect.defineMetadata(METADATA_KEY.ACTION_HANDLER_PARAM_TYPES, types, target); return target; }; }