Skip to content
This repository has been archived by the owner on Dec 13, 2020. It is now read-only.

Commit

Permalink
Refactor fetch thunk action using async/await
Browse files Browse the repository at this point in the history
Issue #1361
  • Loading branch information
pablosichert committed Jan 13, 2018
1 parent 637b012 commit 981d230
Showing 1 changed file with 49 additions and 48 deletions.
97 changes: 49 additions & 48 deletions src/actions/WindowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -523,57 +523,58 @@ export function patch(
viewId,
isEdit
) {
return dispatch => {
dispatch(indicatorState("pending"));

return patchRequest({
entity,
docType: windowType,
docId: id,
tabId,
rowId,
property,
value,
isAdvanced,
viewId,
isEdit
})
.then(response => {
let data =
response.data instanceof Array ? response.data : [response.data];
dispatch(
mapDataToState(data, isModal, rowId, id, windowType, isAdvanced)
);
return async dispatch => {
await dispatch(indicatorState("pending"));

dispatch(indicatorState("saved"));
try {
const response = await patchRequest({
entity,
docType: windowType,
docId: id,
tabId,
rowId,
property,
value,
isAdvanced,
viewId,
isEdit
});

return data;
})
.catch(() => {
getData(
entity,
windowType,
id,
tabId,
const data =
response.data instanceof Array ? response.data : [response.data];

await dispatch(
mapDataToState(data, isModal, rowId, id, windowType, isAdvanced)
);

await dispatch(indicatorState("saved"));

return data;
} catch (error) {
const response = await getData(
entity,
windowType,
id,
tabId,
rowId,
null,
null,
isAdvanced,
null,
viewId
);

await dispatch(
mapDataToState(
response.data,
isModal,
rowId,
null,
null,
isAdvanced,
null,
viewId
).then(response => {
dispatch(
mapDataToState(
response.data,
isModal,
rowId,
id,
windowType,
isAdvanced
)
);
});
});
id,
windowType,
isAdvanced
)
);
}
};
}

Expand Down

0 comments on commit 981d230

Please sign in to comment.