-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcomposition-root.ts
79 lines (73 loc) · 3.32 KB
/
composition-root.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
import axios from "axios";
import { AppConfiguration, AppServices } from "./abstractions";
import { AppConfigurationRendererImplementation } from "./implementations/app-configuration-renderer";
import {
DopplerSessionMfeAppSessionStateAccessor,
DopplerSessionMfeAppSessionStateMonitor,
} from "./implementations/app-session/doppler-mfe-app-session-state-monitor";
import {
ServicesFactories,
SingletonLazyAppServicesContainer,
} from "./implementations/SingletonLazyAppServicesContainer";
import { defaultAppConfiguration } from "./default-configuration";
import { DummyHtmlEditorApiClient } from "./implementations/dummies/html-editor-api-client";
import { HtmlEditorApiClientImpl } from "./implementations/HtmlEditorApiClientImpl";
import { DummyDopplerRestApiClient } from "./implementations/dummies/doppler-rest-api-client";
import { DopplerRestApiClientImpl } from "./implementations/DopplerRestApiClientImpl";
import { MfeLoaderAssetManifestClientImpl } from "./implementations/MfeLoaderAssetManifestClientImpl";
import { DopplerLegacyClientImpl } from "./implementations/DopplerLegacyClientImpl";
import { DummyDopplerLegacyClient } from "./implementations/dummies/doppler-legacy-client";
import { EditorExtensionsBridgeImplementation } from "./implementations/editor-extensions-bridge";
export const configureApp = (
customConfiguration: Partial<AppConfiguration>,
): AppServices => {
const appConfiguration = {
...defaultAppConfiguration,
...customConfiguration,
};
const realFactories: ServicesFactories = {
windowFactory: () => window,
axiosStaticFactory: () => axios,
appConfigurationFactory: () => appConfiguration,
appConfigurationRendererFactory: (appServices: AppServices) =>
new AppConfigurationRendererImplementation(appServices),
htmlEditorApiClientFactory: (appServices) =>
new HtmlEditorApiClientImpl({
axiosStatic: appServices.axiosStatic,
appSessionStateAccessor: appServices.appSessionStateAccessor,
appConfiguration: appServices.appConfiguration,
}),
dopplerRestApiClientFactory: ({
axiosStatic,
appSessionStateAccessor,
appConfiguration,
}) =>
new DopplerRestApiClientImpl({
axiosStatic,
appSessionStateAccessor,
appConfiguration,
}),
dopplerLegacyClientFactory: (appServices) =>
new DopplerLegacyClientImpl(appServices),
appSessionStateAccessorFactory: ({ window }: AppServices) =>
new DopplerSessionMfeAppSessionStateAccessor({ window }),
appSessionStateMonitorFactory: ({ window }: AppServices) =>
new DopplerSessionMfeAppSessionStateMonitor({
window,
}),
assetManifestClientFactory: ({ window }: AppServices) =>
new MfeLoaderAssetManifestClientImpl({ window }),
editorExtensionsBridgeFactory: (appServices) =>
new EditorExtensionsBridgeImplementation(appServices),
};
const dummyFactories: Partial<ServicesFactories> = {
htmlEditorApiClientFactory: () => new DummyHtmlEditorApiClient(),
dopplerRestApiClientFactory: () => new DummyDopplerRestApiClient(),
dopplerLegacyClientFactory: () => new DummyDopplerLegacyClient(),
};
const factories = appConfiguration.useDummies
? { ...realFactories, ...dummyFactories }
: realFactories;
const appServices = new SingletonLazyAppServicesContainer(factories);
return appServices;
};