16 lines
813 B
JavaScript
16 lines
813 B
JavaScript
export function requestReducer(state, action) {
|
|
switch (action.type) {
|
|
case 'call': {
|
|
return Object.assign(Object.assign({}, state), { error: undefined, isCanceled: false, loading: true, isCalled: true, prevHeaders: action.headers, prevVariables: action.variables, prevParams: action.params });
|
|
}
|
|
case 'success': {
|
|
return Object.assign(Object.assign({}, state), { loading: false, data: action.response.data });
|
|
}
|
|
case 'failure': {
|
|
return Object.assign(Object.assign({}, state), { loading: false, data: null, error: action.response.error, isCanceled: action.response.canceled });
|
|
}
|
|
case 'cancel': {
|
|
return Object.assign(Object.assign({}, state), { isCanceled: false, error: undefined });
|
|
}
|
|
}
|
|
}
|