@malagu/core
Version:
19 lines (14 loc) • 781 B
text/typescript
import { AOP_TAG } from '../aop/aop-protocol';
import { ComponentOption, applyComponentDecorator, COMPONENT_TAG, ComponentId, parseComponentOption } from './component';
export interface AspectOption extends ComponentOption {
id: ComponentId;
pointcut?: string;
}
export type AdviceOrAspectOption = ComponentId | AspectOption;
export const Aspect = (adviceOrAspectOption: AdviceOrAspectOption): ClassDecorator => (target: any) => {
const option = <AspectOption>parseComponentOption(target, adviceOrAspectOption);
option.id = Array.isArray(option.id) ? option.id[1] : option.id;
option.pointcut = option.pointcut || COMPONENT_TAG;
option.tag = { tag: AOP_TAG, value: option.pointcut };
applyComponentDecorator({ proxy: false, ...option }, target);
};