cleanup Fetch API code

This commit is contained in:
djmaze 2020-09-15 11:51:07 +02:00
parent 95f55deaad
commit 344edaec2a
4 changed files with 22 additions and 60 deletions

View file

@ -184,13 +184,6 @@ class MessageModel extends AbstractModel {
).filter((value, index, self) => !!value && self.indexOf(value) == index);
}
/**
* @returns {Array}
*/
getRecipientsEmails() {
return this.getEmails(['to', 'cc']);
}
/**
* @returns {string}
*/

View file

@ -70,14 +70,19 @@ class AbstractFetchRemote
}
/**
* @param {?Function} fResultCallback
* @param {Object} oParameters
* @param {?number=} iTimeOut = 20000
* @param {?Function} fCallback
* @param {string} sAction
* @param {Object=} oParameters
* @param {?number=} iTimeout
* @param {string=} sGetAdd = ''
* @param {Array=} aAbortActions = []
*/
ajaxRequest(fResultCallback, params, iTimeOut = 20000, sGetAdd = '', abortActions = []) {
defaultRequest(fCallback, sAction, params, iTimeout, sGetAdd, abortActions) {
params = params || {};
params.Action = sAction;
sGetAdd = pString(sGetAdd);
const start = Date.now(),
action = params.Action || '';
@ -86,8 +91,8 @@ class AbstractFetchRemote
}
return rl.fetchJSON(getURL(sGetAdd), {
signal: this.createAbort(action, iTimeOut)
}, iTimeOut, sGetAdd ? null : params
signal: this.createAbort(action, undefined === iTimeout ? DEFAULT_AJAX_TIMEOUT : pInt(iTimeout))
}, sGetAdd ? null : params
).then(data => {
let cached = false;
if (data) {
@ -117,8 +122,8 @@ class AbstractFetchRemote
iAjaxErrorCount = iTokenErrorCount = 0;
}
if (fResultCallback) {
fResultCallback(
if (fCallback) {
fCallback(
sType,
StorageResultType.Success === sType ? data : null,
cached,
@ -154,27 +159,6 @@ class AbstractFetchRemote
});
}
/**
* @param {?Function} fCallback
* @param {string} sAction
* @param {Object=} oParameters
* @param {?number=} iTimeout
* @param {string=} sGetAdd = ''
* @param {Array=} aAbortActions = []
*/
defaultRequest(fCallback, sAction, oParameters, iTimeout, sGetAdd, aAbortActions) {
oParameters = oParameters || {};
oParameters.Action = sAction;
return this.ajaxRequest(
fCallback,
oParameters,
undefined === iTimeout ? DEFAULT_AJAX_TIMEOUT : pInt(iTimeout),
pString(sGetAdd),
aAbortActions
);
}
/**
* @param {?Function} fCallback
*/
@ -234,7 +218,7 @@ class AbstractFetchRemote
return rl.fetchJSON(getURL(), {
signal: this.createAbort(action, pInt(timeOut, DEFAULT_AJAX_TIMEOUT))
}, pInt(timeOut, DEFAULT_AJAX_TIMEOUT), params
}, params
).then(data => {
this.abort(action, true);

17
dev/bootstrap.js vendored
View file

@ -53,7 +53,7 @@ export default (App) => {
dropdownVisibility(!!rl.Dropdowns.find(item => item.classList.contains('open')))
).debounce(50);
rl.fetchJSON = (resource, init, timeout, postData) => {
rl.fetchJSON = (resource, init, postData) => {
init = Object.assign({
mode: 'same-origin',
cache: 'no-cache',
@ -85,21 +85,6 @@ export default (App) => {
}
return fetch(resource, init).then(response => response.json());
/*
let f = fetch(resource, init);
if (reviver) {
return f.then(response => response.text())
.then(json => {
try {
return JSON.parse(json, reviver);
} catch (e) {
console.error(e);
throw e;
}
});
}
return f.then(response => response.json());
*/
};
window.__APP_BOOT = fErrorCallback => {