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.
45 lines
1.0 KiB
45 lines
1.0 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
|
|
}
|
|
|
|
// ------------------------------------
|
|
// Reducer
|
|
// ------------------------------------
|
|
export default function errorReducer(state = initialState, action) {
|
|
const handler = ACTION_HANDLERS[action.type]
|
|
|
|
return handler ? handler(state, action) : state
|
|
}
|
|
|