-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathaction-reducers.ts
More file actions
88 lines (82 loc) · 3.5 KB
/
action-reducers.ts
File metadata and controls
88 lines (82 loc) · 3.5 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
77
78
79
80
81
82
83
84
85
86
87
88
import { AlarmGroupActionReducers } from './alarm-group.js';
import { ClientActionReducers } from './client.js';
import { ExerciseActionReducers } from './exercise.js';
import { ConfigurationActionReducers } from './configuration.js';
import { HospitalActionReducers } from './hospital.js';
import { MapImageTemplatesActionReducers } from './map-image-template.js';
import { MapImagesActionReducers } from './map-image.js';
import { MaterialActionReducers } from './material.js';
import { PatientActionReducers } from './patient.js';
import { PersonnelActionReducers } from './personnel.js';
import { TransferActionReducers } from './transfer.js';
import { TransferPointActionReducers } from './transfer-point.js';
import { VehicleActionReducers } from './vehicle.js';
import { ViewportActionReducers } from './viewport.js';
import { EmergencyOperationCenterActionReducers } from './emergency-operation-center.js';
import { SimulatedRegionActionReducers } from './simulated-region.js';
import { SimulationActionReducers } from './simulation.js';
import { RadiogramActionReducers } from './radiogram.js';
import { VehicleTemplateActionReducers } from './vehicle-templates.js';
import { RestrictedZoneActionReducers } from './restricted-zone.js';
/**
* All action reducers of the exercise must be registered here
*/
const actionReducers = {
...ClientActionReducers,
...ExerciseActionReducers,
...MaterialActionReducers,
...MapImagesActionReducers,
...PatientActionReducers,
...PersonnelActionReducers,
...VehicleActionReducers,
...ViewportActionReducers,
...TransferPointActionReducers,
...ConfigurationActionReducers,
...AlarmGroupActionReducers,
...MapImageTemplatesActionReducers,
...TransferActionReducers,
...HospitalActionReducers,
...EmergencyOperationCenterActionReducers,
...SimulatedRegionActionReducers,
...SimulationActionReducers,
...RadiogramActionReducers,
...VehicleTemplateActionReducers,
...RestrictedZoneActionReducers,
};
type ExerciseActionReducer =
(typeof actionReducers)[keyof typeof actionReducers];
type ExerciseActionTypeDictionary = {
[_ActionReducer in ExerciseActionReducer as InstanceType<
_ActionReducer['action']
>['type']]: _ActionReducer;
};
/**
* This dictionary maps the action type to the ActionReducer.
*/
let exerciseActionTypeDictionary: ExerciseActionTypeDictionary | undefined;
export function getExerciseActionTypeDictionary(): ExerciseActionTypeDictionary {
if (exerciseActionTypeDictionary) {
return exerciseActionTypeDictionary;
}
const dictionary = {} as any;
// fill in the dictionary
Object.values(actionReducers)
.map(
(actionReducer) =>
({
// the generated ts code from class default values adds them only in the constructor: https://github.com/microsoft/TypeScript/issues/15607
// therefore we have to call the constructor (An ActionClass constructor is therefore required to not throw an error when called without arguments)
type: new actionReducer.action().type,
actionClass: actionReducer,
}) as const
)
.forEach(({ type, actionClass }) => {
dictionary[type] = actionClass;
});
exerciseActionTypeDictionary = dictionary as ExerciseActionTypeDictionary;
return exerciseActionTypeDictionary;
}
/**
* A Union of all actions of the exercise.
*/
export type ExerciseAction = InstanceType<ExerciseActionReducer['action']>;