src/hooks/decorators/Hook.ts   A
last analyzed

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 24
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
eloc 16
mnd 0
bc 0
fnc 1
dl 0
loc 24
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
ccs 10
cts 10
cp 1
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A Hook.ts ➔ Hook 0 18 1
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