Skip to content

Commit f7c8b7e

Browse files
committed
[refactor-2] add some states into state tree
1 parent 03e2edd commit f7c8b7e

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

src-react/reducers/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import { combineReducers } from 'redux';
22

33
import path from './path';
44
import ungitConfig from './ungit-config';
5+
import userConfig from './user-config';
6+
import versions from './versions';
57

68

79
const ungitApp = combineReducers({
810
ungitConfig,
11+
userConfig,
12+
versions,
913
path
1014
});
1115

src-react/reducers/path.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ function path(state, action) {
55
case types.PATH_PAGE_PENDING:
66
return { ...state, pending: true };
77
case types.RECEIVE_UNGIT_CONFIG:
8+
case types.RECEIVE_USER_CONFIG:
9+
case types.RECEIVE_GIT_VERSION:
10+
case types.RECEIVE_LATEST_VERSION:
811
return { ...state, pending: false };
912
case types.PATH_PAGE_API_ERR:
10-
const { payload: errMessage } = action
11-
return { ...state, pending: false, errMessage };
13+
const { payload: errMessage } = action;
14+
return { ...state, pending: false, errMessage: [ ...state.errMessage, errMessage ] };
1215
default:
1316
return { ...state };
1417
}

src-react/reducers/user-config.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as types from 'constants/action-types';
2+
3+
function userConfig(state, action) {
4+
switch(action.type) {
5+
case types.RECEIVE_USER_CONFIG:
6+
const { payload: userConfig } = action;
7+
return { ...userConfig };
8+
default:
9+
return { ...state };
10+
}
11+
}
12+
13+
export default userConfig;

src-react/reducers/versions.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as types from 'constants/action-types';
2+
3+
function userConfig(state, action) {
4+
switch(action.type) {
5+
case types.RECEIVE_GIT_VERSION:
6+
const { payload: gitVersion } = action;
7+
return { ...state, gitVersion };
8+
case types.RECEIVE_LATEST_VERSION:
9+
const { payload: latestVersion } = action;
10+
return { ...state, latestVersion };
11+
default:
12+
return { ...state };
13+
}
14+
}
15+
16+
export default userConfig;

src-react/store.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import ungitApp from './reducers';
44

55
const initialState = {
66
ungitConfig: null,
7+
userConfig: null,
8+
versions: {
9+
gitVersion: null,
10+
latestVersion: null
11+
},
712
path: {
813
pending: false,
9-
errMessage: null
14+
errMessage: []
1015
}
1116
};
1217

0 commit comments

Comments
 (0)