generated from wednesday-solutions/react-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreducer.js
41 lines (38 loc) · 1.21 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
/*
*
* HomeContainer reducer
*
*/
import produce from 'immer';
import { fromJS } from 'immutable';
import { createActions } from 'reduxsauce';
import _ from 'lodash';
export const {
Types: homeContainerTypes,
Creators: homeContainerCreators
} = createActions({
requestGetGithubRepos: ['repoName'],
successGetGithubRepos: ['data'],
failureGetGithubRepos: ['error'],
clearGithubRepos: []
});
export const initialState = fromJS({});
/* 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:
return initialState.set('repoName', action.repoName);
case homeContainerTypes.CLEAR_GITHUB_REPOS:
return initialState.set('repoName', null).set('reposData', null);
case homeContainerTypes.SUCCESS_GET_GITHUB_REPOS:
return state.set('reposData', action.data);
case homeContainerTypes.FAILURE_GET_GITHUB_REPOS:
return state.set(
'reposError',
_.get(action.error, 'message', 'something_went_wrong')
);
}
return state;
});
export default homeContainerReducer;