Redux changes and refactoring
This commit is contained in:
26
src/redux/reducers/error_reducer.js
Normal file
26
src/redux/reducers/error_reducer.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import {createReducer} from 'redux-starter-kit';
|
||||
import {CLEAR_ERROR, SET_ERROR_INFO} from '../actions/error_actions';
|
||||
|
||||
export const errorReducer = createReducer({
|
||||
DisplayError: false,
|
||||
ErrorCritical: false,
|
||||
ErrorStack: [],
|
||||
}, {
|
||||
[CLEAR_ERROR]: state => {
|
||||
const errorStack = (state.ErrorStack.length > 0) ? state.ErrorStack.slice(1) : [];
|
||||
return {
|
||||
...state,
|
||||
DisplayError: (errorStack.length > 0),
|
||||
ErrorStack: errorStack,
|
||||
}
|
||||
},
|
||||
[SET_ERROR_INFO]: (state, action) => {
|
||||
const errorStack = [action.payload.msg, ...state.ErrorStack];
|
||||
return {
|
||||
...state,
|
||||
DisplayError: true,
|
||||
ErrorCritical: state.ErrorCritical || action.payload.critical,
|
||||
ErrorStack: errorStack,
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user