You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
1.2 KiB

// ------------------------------------
// Initial State
// ------------------------------------
const initialState = {
error: null
}
// ------------------------------------
// Constants
// ------------------------------------
export const SET_ERROR = 'SET_ERROR'
export const CLEAR_ERROR = 'CLEAR_ERROR'
// ------------------------------------
// Actions
// ------------------------------------
export function setError(error) {
return {
type: SET_ERROR,
error
}
}
export function clearError() {
return {
type: CLEAR_ERROR
}
}
// ------------------------------------
// Action Handlers
// ------------------------------------
const ACTION_HANDLERS = {
[SET_ERROR]: (state, { error }) => ({ ...state, error }),
[CLEAR_ERROR]: () => initialState
}
// ------------------------------------
// Selectors
// ------------------------------------
const errorSelectors = {}
errorSelectors.getErrorState = state => state.error.error
export { errorSelectors }
// ------------------------------------
// Reducer
// ------------------------------------
export default function errorReducer(state = initialState, action) {
const handler = ACTION_HANDLERS[action.type]
return handler ? handler(state, action) : state
}