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 | 7 | import { logger, registeredMethods } from '@/core'; |
|
3 | 7 | import { Executor, ExecutorPhase } from '@/core/executor'; |
|
4 | |||
5 | /** |
||
6 | * Hook a function to a phase. |
||
7 | * @decorator |
||
8 | */ |
||
9 | 7 | export function Hook(phase: ExecutorPhase) { |
|
10 | 28 | return<This>( |
|
11 | method: () => any, |
||
12 | context: ClassMethodDecoratorContext<This, () => any>, |
||
13 | ) => { |
||
14 | 9 | logger.debug(`Registering ${phase} function ${String(context.name)}`); |
|
15 | 9 | Executor.setExecution('start', () => { |
|
16 | 9 | const bean = registeredMethods.get(method) as ExpressBean; |
|
17 | 9 | logger.debug(`Initializing ${bean._className}.${String(context.name)} as ${phase} function`); |
|
18 | 9 | Executor.setExecution(phase, () => method.bind(bean)(), method); |
|
19 | }); |
||
20 | |||
21 | 9 | return method; |
|
22 | }; |
||
23 | } |
||
24 |