1 |
|
2 | import { endsWith, startsWith } from "lodash";
|
3 |
|
4 | export const PREFIX = "@API";
|
5 | export const REQUEST = "REQUEST";
|
6 | export const SUCCESS = "SUCCESS";
|
7 | export const FAILURE = "FAILURE";
|
8 | export const CLEAR = "CLEAR";
|
9 | export const REFRESH = "REFRESH";
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export const makeTypes = key => ({
|
16 | request: `${PREFIX}/${key}/${REQUEST}`,
|
17 | success: `${PREFIX}/${key}/${SUCCESS}`,
|
18 | failure: `${PREFIX}/${key}/${FAILURE}`,
|
19 | clear: `${PREFIX}/${key}/${CLEAR}`,
|
20 | refresh: `${PREFIX}/${key}/${REFRESH}`,
|
21 | });
|
22 |
|
23 | export const successOf = key => `${PREFIX}/${key}/${SUCCESS}`;
|
24 | export const requestOf = key => `${PREFIX}/${key}/${REQUEST}`;
|
25 | export const failureOf = key => `${PREFIX}/${key}/${FAILURE}`;
|
26 | export const clearOf = key => `${PREFIX}/${key}/${CLEAR}`;
|
27 | export const refreshOf = key => `${PREFIX}/${key}/${REFRESH}`;
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export function isApi(action) {
|
34 | const { key, type } = action;
|
35 | return key && startsWith(type, PREFIX);
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export function isRequest(action) {
|
43 | return isApi(action) && endsWith(action.type, REQUEST);
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export function isSuccess(action) {
|
51 | return isApi(action) && endsWith(action.type, SUCCESS);
|
52 | }
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | export function isFailure(action) {
|
59 | return isApi(action) && endsWith(action.type, FAILURE);
|
60 | }
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | export function isClear(action) {
|
67 | return isApi(action) && endsWith(action.type, CLEAR);
|
68 | }
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | export function isRefresh(action) {
|
75 | return isApi(action) && endsWith(action.type, REFRESH);
|
76 | }
|