JSFiddle - React, Tailwind, and code Playground
by kontrach
JavaScript
if (hasId({id: 'hello'}, 'id')) {
makeGet('url').then(handleGetSuccess, handleGetError);
} else {
makePost('url').then(handlePostSuccess, handlePostError)
}
function hasId(obj, id) {
return obj.hasOwnProperty(id); // or similar functionality
}
function makePost(url) {
return fetch(url, {method: 'POST'});
}
function makeGet(url) {
return fetch(url);
}
function handleGetSuccess(result) {
// angular copy
}
function handleGetError(err) {
showModal().then(
yes => makeGet('url'),
err => void 0 // nothing
)
.then(() => void 0 /* angular copy*/)
}
function handlePostSuccess(result) {
// angular copy
}
function handlePostError(err) {
showModal().then(
yes => makePost('url'),
err => void 0 // nothing
)
.then(() => void 0 /* angular copy*/)
}
function showModal() {
return Promise.resolve();
}