UNPKG

ts-ioc-container

Version:

Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.

11 lines (10 loc) 851 B
import { resolveConstructor } from '../utils/basic'; export const addMethodMeta = (key, mapFn) => (target, propertyKey) => { const metadata = Reflect.getMetadata(key, target.constructor, propertyKey); Reflect.defineMetadata(key, mapFn(metadata), target.constructor, propertyKey); }; export const getMethodMeta = (key, target, propertyKey) => Reflect.getMetadata(key, resolveConstructor(target), propertyKey); export const addMethodLabel = (key, label) => addMethodMeta('label', (prev = new Map()) => prev.set(key, label)); export const getMethodLabels = (target, propertyKey) => getMethodMeta('label', target, propertyKey) ?? new Map(); export const addMethodTag = (tag) => addMethodMeta('tag', (prev = new Set()) => prev.add(tag)); export const getMethodTags = (target, propertyKey) => getMethodMeta('tag', target, propertyKey) ?? new Set();