generated from wednesday-solutions/react-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
reducer.js
36 lines (33 loc) · 1.11 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
/*
*
* 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 };
/* eslint-disable default-case, no-param-reassign */
export const homeContainerReducer = (state = initialState, action) =>
produce(state, draft => {
switch (action.type) {
case homeContainerTypes.REQUEST_GET_GITHUB_REPOS:
draft.repoName = action.repoName;
break;
case homeContainerTypes.CLEAR_GITHUB_REPOS:
return initialState;
case homeContainerTypes.SUCCESS_GET_GITHUB_REPOS:
draft.reposData = action.data;
break;
case homeContainerTypes.FAILURE_GET_GITHUB_REPOS:
draft.reposError = get(action.error, 'message', 'something_went_wrong');
break;
}
});
export default homeContainerReducer;