forked from jeffbski/redux-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logic.js
30 lines (25 loc) · 962 Bytes
/
logic.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
import { createLogic } from 'redux-logic';
import { USERS_FETCH, USERS_FETCH_CANCEL, usersFetchFulfilled,
usersFetchRejected } from './actions';
const delay = 4; // 4s delay for interactive use of cancel/take latest
export const usersFetchLogic = createLogic({
type: USERS_FETCH,
cancelType: USERS_FETCH_CANCEL,
latest: true, // take latest only
processOptions: {
dispatchReturn: true,
successType: usersFetchFulfilled,
failType: usersFetchRejected
},
// use axios injected as httpClient from configureStore logic deps
// we also have access to getState and action in the first argument
// but they were not needed for this particular code
process({ httpClient }) {
// the delay query param adds arbitrary delay to the response
return httpClient.get(`http://reqres.in/api/users?delay=${delay}`)
.then(resp => resp.data.data); // use data property of payload
}
});
export default [
usersFetchLogic
];