-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfullCodeExample.js
47 lines (40 loc) · 1.08 KB
/
fullCodeExample.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
import {
enhanceActionTypes,
enhanceActionCreators,
enhanceDefaultState,
enhanceReducer,
enhanceSelectors,
} from 'redux-async-actions-factory';
const storeName = 'USER';
const asyncActionsNames = ['SIGNUP'];
export const actionTypes = {
...enhanceActionTypes(storeName, asyncActionsNames),
LOGOUT: 'LOGOUT',
};
export const actionCreators = {
...enhanceActionCreators(storeName, asyncActionsNames, actionTypes),
requestSignupStart: signupInfo => ({
type: actionTypes.REQUEST.SIGNUP.START,
payload: signupInfo,
}),
};
const defaultState = {
...enhanceDefaultState(asyncActionsNames),
};
const basicReducer = (state, action) => {
switch (action.type) {
case actionTypes.REQUEST.SIGNUP.SUCCESS:
return {
...state,
token: action.payload.token,
};
default:
return state;
}
};
export const reducer = (state = defaultState, action) =>
enhanceReducer(storeName, state, action, defaultState, basicReducer);
export const selectors = {
...enhanceSelectors(storeName, asyncActionsNames),
token: state => state.user.token,
};