-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathselectors.ts
50 lines (42 loc) · 1.75 KB
/
selectors.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
import type { RootState } from 'reducers';
import buildCommonConfSelectors from 'reducers/osrdconf/osrdConfCommon/selectors';
import { stdcmConfSlice } from 'reducers/osrdconf/stdcmConf';
import type { OsrdStdcmConfState } from 'reducers/osrdconf/types';
import { makeSubSelector } from 'utils/selectors';
const buildStdcmConfSelectors = () => {
const commonConfSelectors = buildCommonConfSelectors(stdcmConfSlice);
const getStdcmConf = (state: RootState) => state[stdcmConfSlice.name];
const makeOsrdConfSelector = makeSubSelector<OsrdStdcmConfState>(getStdcmConf);
const getStdcmPathSteps = makeOsrdConfSelector('stdcmPathSteps');
return {
...commonConfSelectors,
getStdcmConf,
getStandardStdcmAllowance: makeOsrdConfSelector('standardStdcmAllowance'),
getTotalMass: makeOsrdConfSelector('totalMass'),
getTotalLength: makeOsrdConfSelector('totalLength'),
getMaxSpeed: makeOsrdConfSelector('maxSpeed'),
getTowedRollingStockID: makeOsrdConfSelector('towedRollingStockID'),
getStdcmPathSteps,
getStdcmOrigin: (state: RootState) => {
const pathSteps = getStdcmPathSteps(state);
const origin = pathSteps.at(0);
if (origin!.isVia) {
throw new Error('Origin is a via point');
}
return origin!;
},
getStdcmDestination: (state: RootState) => {
const pathSteps = getStdcmPathSteps(state);
const destination = pathSteps.at(-1);
if (destination!.isVia) {
throw new Error('Destination is a via point');
}
return destination!;
},
getLinkedTrains: makeOsrdConfSelector('linkedTrains'),
};
};
const selectors = buildStdcmConfSelectors();
export const { getStdcmConf } = selectors;
export type StdcmConfSelectors = typeof selectors;
export default selectors;