forked from hpi-sam/digital-fuesim-manv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action-reducers.ts
84 lines (78 loc) · 3.24 KB
/
action-reducers.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
83
84
import { AlarmGroupActionReducers } from './alarm-group';
import { ClientActionReducers } from './client';
import { ExerciseActionReducers } from './exercise';
import { ConfigurationActionReducers } from './configuration';
import { HospitalActionReducers } from './hospital';
import { MapImageTemplatesActionReducers } from './map-image-templates';
import { MapImagesActionReducers } from './map-images';
import { MaterialActionReducers } from './material';
import { PatientActionReducers } from './patient';
import { PersonnelActionReducers } from './personnel';
import { TransferActionReducers } from './transfer';
import { TransferPointActionReducers } from './transfer-point';
import { VehicleActionReducers } from './vehicle';
import { ViewportActionReducers } from './viewport';
import { EmergencyOperationCenterActionReducers } from './emergency-operation-center';
import { SimulatedRegionActionReducers } from './simulated-region';
import { SimulationActionReducers } from './simulation';
import { RadiogramActionReducers } from './radiogram';
/**
* 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,
};
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']>;