-
Notifications
You must be signed in to change notification settings - Fork 568
/
configuration.ts
82 lines (74 loc) 路 2.14 KB
/
configuration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { IMidwayApplication, IMidwayContainer } from '../interface';
import { InjectionConfigurationOptions } from '../decorator';
export class FunctionalConfiguration {
private readyHandler;
private stopHandler;
private configLoadHandler;
private serverReadyHandler;
private options: InjectionConfigurationOptions;
constructor(options: InjectionConfigurationOptions) {
this.options = options;
this.readyHandler = () => {};
this.stopHandler = () => {};
this.configLoadHandler = () => {};
this.serverReadyHandler = () => {};
}
onConfigLoad(
configLoadHandler:
| ((container: IMidwayContainer, app: IMidwayApplication) => any)
| IMidwayContainer,
app?: IMidwayApplication
) {
if (typeof configLoadHandler === 'function') {
this.configLoadHandler = configLoadHandler;
} else {
return this.configLoadHandler(configLoadHandler, app);
}
return this;
}
onReady(
readyHandler:
| ((container: IMidwayContainer, app: IMidwayApplication) => void)
| IMidwayContainer,
app?: IMidwayApplication
) {
if (typeof readyHandler === 'function') {
this.readyHandler = readyHandler;
} else {
return this.readyHandler(readyHandler, app);
}
return this;
}
onServerReady(
serverReadyHandler:
| ((container: IMidwayContainer, app: IMidwayApplication) => void)
| IMidwayContainer,
app?: IMidwayApplication
) {
if (typeof serverReadyHandler === 'function') {
this.serverReadyHandler = serverReadyHandler;
} else {
return this.serverReadyHandler(serverReadyHandler, app);
}
return this;
}
onStop(
stopHandler:
| ((container: IMidwayContainer, app: IMidwayApplication) => void)
| IMidwayContainer,
app?: IMidwayApplication
) {
if (typeof stopHandler === 'function') {
this.stopHandler = stopHandler;
} else {
return this.stopHandler(stopHandler, app);
}
return this;
}
getConfigurationOptions() {
return this.options;
}
}
export const createConfiguration = (options: InjectionConfigurationOptions) => {
return new FunctionalConfiguration(options);
};