-
Notifications
You must be signed in to change notification settings - Fork 92
/
reducer.js
44 lines (41 loc) · 1.34 KB
/
reducer.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
/*
*
* HomeContainer reducer
*
*/
import { produce } from 'immer';
import { createActions } from 'reduxsauce';
import get from 'lodash/get';
export const { Types: homeContainerTypes, Creators: homeContainerCreators } = createActions({
requestGetGithubRepos: ['repoName'],
successGetGithubRepos: ['data'],
failureGetGithubRepos: ['error'],
clearGithubRepos: {}
});
export const initialState = { repoName: null, reposData: {}, reposError: null, loading: null };
export const homeContainerReducer = (state = initialState, action) =>
produce(state, (draft) => {
switch (action.type) {
case homeContainerTypes.REQUEST_GET_GITHUB_REPOS:
draft.repoName = action.repoName;
draft.loading = true;
break;
case homeContainerTypes.CLEAR_GITHUB_REPOS:
draft.repoName = null;
draft.reposError = null;
draft.reposData = {};
draft.loading = null;
break;
case homeContainerTypes.SUCCESS_GET_GITHUB_REPOS:
draft.reposData = action.data;
draft.reposError = null;
draft.loading = false;
break;
case homeContainerTypes.FAILURE_GET_GITHUB_REPOS:
draft.reposError = get(action.error, 'message', 'something_went_wrong');
draft.reposData = null;
draft.loading = false;
break;
}
});
export default homeContainerReducer;