This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
react-rest-request/target/reducer.js

17 lines
903 B
JavaScript
Raw Normal View History

export function requestReducer(state, action) {
switch (action.type) {
case 'call': {
2021-06-17 22:43:29 +03:00
return Object.assign(Object.assign({}, state), { response: undefined, fetchError: undefined, isCanceled: false, loading: true, isCalled: true, prevHeaders: action.headers, prevVariables: action.variables, prevParams: action.params });
}
case 'success': {
2021-06-17 22:43:29 +03:00
return Object.assign(Object.assign({}, state), { loading: false, response: action.response, data: action.response.data });
}
case 'failure': {
2021-06-17 22:43:29 +03:00
return Object.assign(Object.assign({}, state), { loading: false, response: action.response, data: null, fetchError: action.response.error, isCanceled: action.response.canceled });
}
case 'cancel': {
2021-06-17 22:43:29 +03:00
return Object.assign(Object.assign({}, state), { isCanceled: false, fetchError: undefined });
}
}
}