forked from react-navigation/react-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigationActions.js
78 lines (67 loc) · 1.68 KB
/
NavigationActions.js
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
/**
* @flow
*/
import type { NavigationAction } from './TypeDefinition';
const BACK = 'Navigation/BACK';
const INIT = 'Navigation/INIT';
const NAVIGATE = 'Navigation/NAVIGATE';
const RESET = 'Navigation/RESET';
const SET_PARAMS = 'Navigation/SET_PARAMS';
const URI = 'Navigation/URI';
const createAction = (type: string) => (payload: Object = {}) => ({
type,
...payload,
});
const back = createAction(BACK);
const init = createAction(INIT);
const navigate = createAction(NAVIGATE);
const reset = createAction(RESET);
const setParams = createAction(SET_PARAMS);
const uri = createAction(URI);
const deprecatedActionMap = {
Back: BACK,
Init: INIT,
Navigate: NAVIGATE,
Reset: RESET,
SetParams: SET_PARAMS,
Uri: URI,
};
const mapDeprecatedActionAndWarn = (action: Object) => {
const mappedType = deprecatedActionMap[action.type];
if (!mappedType) {
return action;
}
console.warn(
[
`The action type '${action.type}' has been renamed to '${mappedType}'.`,
`'${action.type}' will continue to work while in beta but will be removed`,
'in the first major release. Moving forward, you should use the',
'action constants and action creators exported by this library in',
"the 'actions' object.",
'See https://github.com/react-community/react-navigation/pull/120 for',
'more details.',
].join(' ')
);
return {
...action,
type: deprecatedActionMap[action.type],
};
};
export default {
// Action constants
BACK,
INIT,
NAVIGATE,
RESET,
SET_PARAMS,
URI,
// Action creators
back,
init,
navigate,
reset,
setParams,
uri,
// TODO: Remove once old actions are deprecated
mapDeprecatedActionAndWarn,
};