NavigationActions.js
3.46 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var BACK = 'Navigation/BACK';
var INIT = 'Navigation/INIT';
var NAVIGATE = 'Navigation/NAVIGATE';
var RESET = 'Navigation/RESET';
var SET_PARAMS = 'Navigation/SET_PARAMS';
var URI = 'Navigation/URI';
var createAction = function createAction(type, fn) {
fn.toString = function () {
return type;
};
return fn;
};
var back = createAction(BACK, function () {
var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return {
type: BACK,
key: payload.key
};
});
var init = createAction(INIT, function () {
var payload = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var action = {
type: INIT
};
if (payload.params) {
action.params = payload.params;
}
return action;
});
var navigate = createAction(NAVIGATE, function (payload) {
var action = {
type: NAVIGATE,
routeName: payload.routeName
};
if (payload.params) {
action.params = payload.params;
}
if (payload.action) {
action.action = payload.action;
}
return action;
});
var reset = createAction(RESET, function (payload) {
return {
type: RESET,
index: payload.index,
key: payload.key,
actions: payload.actions
};
});
var setParams = createAction(SET_PARAMS, function (payload) {
return {
type: SET_PARAMS,
key: payload.key,
params: payload.params
};
});
var uri = createAction(URI, function (payload) {
return {
type: URI,
uri: payload.uri
};
});
var mapDeprecatedNavigateAction = function mapDeprecatedNavigateAction(action) {
if (action.type === 'Navigate') {
var payload = {
routeName: action.routeName,
params: action.params
};
if (action.action) {
payload.action = mapDeprecatedNavigateAction(action.action);
}
return navigate(payload);
}
return action;
};
var mapDeprecatedAction = function mapDeprecatedAction(action) {
if (action.type === 'Back') {
return back(action);
} else if (action.type === 'Init') {
return init(action);
} else if (action.type === 'Navigate') {
return mapDeprecatedNavigateAction(action);
} else if (action.type === 'Reset') {
return reset({
index: action.index,
key: action.key,
actions: action.actions.map(mapDeprecatedNavigateAction)
});
} else if (action.type === 'SetParams') {
return setParams(action);
}
return action;
};
var mapDeprecatedActionAndWarn = function mapDeprecatedActionAndWarn(action) {
var newAction = mapDeprecatedAction(action);
if (newAction !== action) {
var oldType = action.type;
var newType = newAction.type;
console.warn(['The action type \'' + oldType + '\' has been renamed to \'' + newType + '\'.', '\'' + oldType + '\' 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 newAction;
};
exports.default = {
// Action constants
BACK: BACK,
INIT: INIT,
NAVIGATE: NAVIGATE,
RESET: RESET,
SET_PARAMS: SET_PARAMS,
URI: URI,
// Action creators
back: back,
init: init,
navigate: navigate,
reset: reset,
setParams: setParams,
uri: uri,
// TODO: Remove once old actions are deprecated
mapDeprecatedActionAndWarn: mapDeprecatedActionAndWarn
};