forked from wednesday-solutions/nextjs-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
37 lines (33 loc) · 1.03 KB
/
app.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
/*
*
* App reducer
*
*/
import produce from 'immer';
import { createActions } from 'reduxsauce';
import get from 'lodash/get';
export const initialState = { repoName: null, reposData: [], reposError: null };
export const { Types: appTypes, Creators: appCreators } = createActions({
requestGetGithubRepos: ['repoName'],
successGetGithubRepos: ['data'],
failureGetGithubRepos: ['error'],
clearGithubRepos: []
});
/* eslint-disable default-case, no-param-reassign */
export const appReducer = (state = initialState, action) =>
produce(state, (draft) => {
switch (action.type) {
case appTypes.REQUEST_GET_GITHUB_REPOS:
draft.repoName = action.repoName;
break;
case appTypes.CLEAR_GITHUB_REPOS:
return initialState;
case appTypes.SUCCESS_GET_GITHUB_REPOS:
draft.reposData = action.data;
break;
case appTypes.FAILURE_GET_GITHUB_REPOS:
draft.reposError = get(action.error, 'message', 'something_went_wrong');
break;
}
});
export default appReducer;