-
-
Notifications
You must be signed in to change notification settings - Fork 47
/
register-areas.ts
31 lines (28 loc) · 968 Bytes
/
register-areas.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
import { MetadataArgsStorage } from "../metadata/metadata.ts";
import { registerProviders } from "./register-providers.ts";
import { registerHooks } from "./register-hooks.ts";
/** Registering areas */
export function registerAreas<TState>(metadata: MetadataArgsStorage<TState>) {
const container = metadata.container;
// Register each provider in area container
if (metadata.areas.length > 0) {
for (const area of metadata.areas) {
registerProviders(area, container);
registerHooks(area, metadata.hooks);
}
}
// bind controller to area, area to controller
metadata.controllers.map((controller) => {
if (controller.area === undefined) {
controller.area = metadata.areas.find((area) => {
if (area.controllers) {
return !!area.controllers.find(
(areaController) => areaController === controller.target,
);
}
return false;
});
}
return controller;
});
}