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

@ -89,23 +89,23 @@ Things might work in Edge 18, Firefox 50-62 and Chrome 54-68 due to one polyfill
|js/* |1.14.0 |native |
|----------- |--------: |--------: |
|admin.js |2.130.942 | 941.273 |
|app.js |4.184.455 |2.533.271 |
|admin.js |2.130.942 | 935.611 |
|app.js |4.184.455 |2.517.449 |
|boot.js | 671.522 | 5.777 |
|libs.js | 647.614 | 327.257 |
|polyfills.js | 325.834 | 0 |
|TOTAL |7.960.367 |3.807.578 |
|TOTAL |7.960.367 |3.786.094 |
|js/min/* |1.14.0 |native |gzip 1.14 |gzip |brotli |
|--------------- |--------: |--------: |--------: |--------: |--------: |
|admin.min.js | 252.147 | 128.671 | 73.657 | 37.600 | 32.254 |
|app.min.js | 511.202 | 346.350 |140.462 | 90.770 | 73.272 |
|admin.min.js | 252.147 | 128.146 | 73.657 | 37.448 | 32.137 |
|app.min.js | 511.202 | 344.299 |140.462 | 90.265 | 73.006 |
|boot.min.js | 66.007 | 3.101 | 22.567 | 1.576 | 1.346 |
|libs.min.js | 572.545 | 304.000 |176.720 | 94.870 | 83.524 |
|polyfills.min.js | 32.452 | 0 | 11.312 | 0 | 0 |
|TOTAL |1.434.353 | 782.122 |424.718 |224.816 |190.396 |
|TOTAL |1.434.353 | 779.546 |424.718 |224.159 |190.013 |
652.231 bytes (199.902 gzip) is not much, but it feels faster.
654.807 bytes (200.559 gzip) is not much, but it feels faster.
### CSS changes

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 => {