-
Notifications
You must be signed in to change notification settings - Fork 57
/
derived-state.ts
42 lines (33 loc) · 952 Bytes
/
derived-state.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
import { createStructuredSelector, createSelector } from "reselect";
import {
GameObject,
PrimaryElementBehavior,
getBehavior
} from "oni-save-parser";
import { AppState } from "@/state";
import selectedValue from "@/selectors/selected-value";
const position = createSelector(
selectedValue,
(value: GameObject) => value && value.position
);
const primaryElementBehavior = createSelector(selectedValue, value => {
if (!value) {
return null;
}
return getBehavior(value, PrimaryElementBehavior);
});
const primaryElement = createSelector(primaryElementBehavior, behavior => {
if (!behavior) {
return null;
}
return behavior.templateData.ElementID;
});
const structuredSelector = {
position,
primaryElement
};
export type StateProps = StructuredStateProps<typeof structuredSelector>;
const mapStateToProps = createStructuredSelector<AppState, StateProps>(
structuredSelector
);
export default mapStateToProps;