-
Notifications
You must be signed in to change notification settings - Fork 1
/
actions.js
23 lines (21 loc) · 995 Bytes
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function actionCreator(subtype, createPayload) {
const type = `@@router/${subtype}`;
const action = (...payload) => ({
payload: createPayload ? createPayload(...payload) : payload[0],
type,
});
action.toString = () => type;
action.type = type;
return action;
}
export const changeLocation = actionCreator('LOCATION_CHANGE');
export const navigate = actionCreator('NAVIGATION', (to, state) => ({state, to}));
// Compatibility with history actions.
const navigationAction = (creator) => actionCreator('NAVIGATION', creator);
export const back = navigationAction(() => ({to: -1}));
export const forward = navigationAction(() => ({to: 1}));
export const go = navigationAction((to) => ({to}));
export const goBack = navigationAction(() => ({to: -1}));
export const goForward = navigationAction(() => ({to: 1}));
export const push = navigationAction((to, state) => ({state, to}));
export const replace = navigationAction((to, state) => ({state: {...state, replace: true}, to}));