UNPKG

ts-ioc-container

Version:
25 lines (24 loc) 847 B
import { resolveArgs } from '../injector/inject'; export class HookContext { instance; scope; methodName; constructor(instance, scope, methodName) { this.instance = instance; this.scope = scope; this.methodName = methodName; } resolveArgs(...args) { return resolveArgs(this.instance.constructor, this.methodName)(this.scope, ...args); } invokeMethod({ args = this.resolveArgs() }) { // @ts-ignore return this.instance[this.methodName](...args); } setProperty(fn) { // @ts-ignore this.instance[this.methodName] = fn(this.scope); } } export const createHookContext = (Target, scope, methodName = 'constructor') => new HookContext(Target, scope, methodName); export const hookMetaKey = (methodName = 'constructor') => `inject:${methodName}`;