-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstate_predicates.ts
96 lines (92 loc) · 3.42 KB
/
state_predicates.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
85
86
87
88
89
90
91
92
93
94
95
96
import {RouterInstance} from './types';
const stack = {
isMovingForward: (router: RouterInstance<{}, 'stack'>) => {
return (
router.state.actionCount === router.manager.actionCount &&
router.history.length > 0 &&
router.state.data < router.history[0].data &&
router.history[0].visible === true &&
router.state.visible
);
},
isMovingBackward: (router: RouterInstance<{}, 'stack'>) => {
return (
router.state.actionCount === router.manager.actionCount &&
router.history.length > 0 &&
router.state.data > router.history[0].data &&
router.history[0].visible === true &&
router.state.visible
);
},
isAtFront: (router: RouterInstance<{}, 'stack'>) => {
return router.state.data === 1 && router.state.visible;
},
isAtBack: (router: RouterInstance<{}, 'stack'>) => {
return (
router.state.visible &&
router.siblings.filter(s => s.state.visible === true).length > 0 && // when there are other stacks being shown
router.state.data === router.siblings.filter(s => s.state.visible === true).length + 1 // add 1 to include this router since siblings are 'all but this'
);
},
isPositionSameAsLastTimeShown: (router: RouterInstance<{}, 'stack'>) => {
return (
router.state.visible &&
router.state.data === (router.history.find(s => s.visible === true) || {}).data
);
}
};
const scene = {
isVisibleSiblingsFirstTimeBeingShown: (router: RouterInstance<{}, 'scene'>) => {
const visibleSibling = router.siblings.find(s => s.state.visible === true);
return (
router.state.visible === false &&
visibleSibling &&
visibleSibling.history.find(h => h.visible === true) === undefined
);
},
hasVisibleSiblingBeenShownBefore: (router: RouterInstance<{}, 'scene'>) => {
const visibleSibling = router.siblings.find(s => s.state.visible === true);
return (
router.state.visible === false &&
visibleSibling &&
visibleSibling.history.find(h => h.visible === true) !== undefined
);
}
};
const common = {
isVisible: (router: RouterInstance<{}>) => {
return router.state.visible === true;
},
isHidden: (router: RouterInstance<{}>) => {
return router.state.visible !== true;
},
isJustHidden: (router: RouterInstance<{}>) => {
return (
router.state.actionCount === router.manager.actionCount && router.state.visible !== true
);
},
isJustShown: (router: RouterInstance<{}>) => {
return (
router.state.actionCount === router.manager.actionCount && router.state.visible === true
);
},
isFirstTimeBeingShown: (router: RouterInstance<{}>) => {
return (
router.state.actionCount === router.manager.actionCount &&
router.state.visible === true &&
router.history.find(h => h.visible === true) === undefined
);
},
hasBeenShownBefore: (router: RouterInstance<{}>) => {
return (
router.state.actionCount === router.manager.actionCount &&
router.state.visible === true &&
router.history.find(h => h.visible === true) !== undefined
);
}
};
export default {
stack,
scene,
...common
};