core/src/plugin/decorators/auto.ts

20 lines
469 B
TypeScript
Raw Normal View History

import 'reflect-metadata';
2020-11-21 15:41:08 +00:00
2020-11-29 19:23:43 +00:00
/**
* Automatically execute method on plugin initialization
*/
export function Auto() {
2020-11-21 15:41:08 +00:00
return (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor,
) => {
let autorunners: Array<string> = Reflect.getMetadata('sb:autorunners', target);
if (!autorunners) {
Reflect.defineMetadata('sb:autorunners', autorunners = [], target);
}
autorunners.push(propertyKey);
2020-11-21 15:41:08 +00:00
return descriptor;
};
}