| Total Complexity | 1 |
| Complexity/F | 1 |
| Lines of Code | 24 |
| Function Count | 1 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | import { ExpressBean } from '@/ExpressBeansTypes'; |
||
| 2 | 8 | import { logger, registeredMethods } from '@/core'; |
|
| 3 | 8 | import { Executor, ExecutorPhase } from '@/core/executor'; |
|
| 4 | |||
| 5 | /** |
||
| 6 | * Hook a function to a phase. |
||
| 7 | * @decorator |
||
| 8 | */ |
||
| 9 | 8 | export function Hook(phase: ExecutorPhase) { |
|
| 10 | 32 | return<This>( |
|
| 11 | method: () => any, |
||
| 12 | context: ClassMethodDecoratorContext<This, () => any>, |
||
| 13 | ) => { |
||
| 14 | 18 | logger.debug(`Registering ${phase} function ${String(context.name)}`); |
|
| 15 | 18 | Executor.setExecution('start', () => { |
|
| 16 | 18 | const bean = registeredMethods.get(method) as ExpressBean; |
|
| 17 | 18 | logger.debug(`Initializing ${bean._className}.${String(context.name)} as ${phase} function`); |
|
| 18 | 18 | Executor.setExecution(phase, () => method.bind(bean)(), method); |
|
| 19 | }); |
||
| 20 | |||
| 21 | 18 | return method; |
|
| 22 | }; |
||
| 23 | } |
||
| 24 |