-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp-controller-services.ts
More file actions
76 lines (71 loc) · 2.66 KB
/
Copy pathapp-controller-services.ts
File metadata and controls
76 lines (71 loc) · 2.66 KB
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
import { createConfigSyncController } from "./config-sync-controller.js";
import { createSimulationMutations } from "./interactions/simulation-mutations.js";
import { createUiSessionController } from "./ui-session-controller.js";
import { createUiSessionStorage } from "./ui-session.js";
import type { PostControlFunction } from "./types/controller-api.js";
import type { MutationRunner, SimulationMutations } from "./types/controller-runtime.js";
import type { ConfigSyncController, UiSessionController } from "./types/controller-sync-session.js";
import type { AppControllerSync } from "./types/controller-app.js";
import type { AppView } from "./types/controller-view.js";
import type { DomElements } from "./types/dom.js";
import type { AppState } from "./types/state.js";
export interface AppControllerServicePhaseResult {
configSyncController: ConfigSyncController;
uiSessionController: UiSessionController;
getSimulationMutations: () => SimulationMutations;
}
export function createAppControllerServices({
state,
elements,
mutationRunner,
appView,
onError,
postControlFn,
sync,
}: {
state: AppState;
elements: DomElements;
mutationRunner: MutationRunner;
appView: AppView;
onError: (error: unknown) => void;
postControlFn: PostControlFunction;
sync: AppControllerSync;
}): AppControllerServicePhaseResult {
let simulationMutations: SimulationMutations | null = null;
const getSimulationMutations = (): SimulationMutations => {
if (!simulationMutations) {
simulationMutations = createSimulationMutations({
state,
mutationRunner,
onError,
applySimulationState: sync.applySimulationState,
resolveSimulationState: sync.resolveSimulationState,
refreshState: sync.refreshState,
renderControlPanel: appView.renderControlsPanel,
});
}
return simulationMutations;
};
const uiSessionController = createUiSessionController({
state,
elements,
createUiSessionStorage,
});
uiSessionController.restoreInitialCellSize();
uiSessionController.restoreDrawerState();
const configSyncController = createConfigSyncController({
state,
mutationRunner,
simulationMutations: getSimulationMutations(),
postControl: postControlFn,
onError,
onSyncStateChanged: appView.renderControlsPanel,
applySimulationState: sync.applySimulationState,
refreshState: sync.refreshState,
});
return {
configSyncController,
uiSessionController,
getSimulationMutations,
};
}