Conditions | 1 |
Total Lines | 18 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 1 |
Changes | 0 |
1 | import { ExpressBean } from '@/ExpressBeansTypes'; |
||
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 | }; |
||
24 |