mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-13 03:27:39 +03:00
cleanup Fetch API code
This commit is contained in:
parent
95f55deaad
commit
344edaec2a
4 changed files with 22 additions and 60 deletions
14
README.md
14
README.md
|
|
@ -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 |
|
|js/* |1.14.0 |native |
|
||||||
|----------- |--------: |--------: |
|
|----------- |--------: |--------: |
|
||||||
|admin.js |2.130.942 | 941.273 |
|
|admin.js |2.130.942 | 935.611 |
|
||||||
|app.js |4.184.455 |2.533.271 |
|
|app.js |4.184.455 |2.517.449 |
|
||||||
|boot.js | 671.522 | 5.777 |
|
|boot.js | 671.522 | 5.777 |
|
||||||
|libs.js | 647.614 | 327.257 |
|
|libs.js | 647.614 | 327.257 |
|
||||||
|polyfills.js | 325.834 | 0 |
|
|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 |
|
|js/min/* |1.14.0 |native |gzip 1.14 |gzip |brotli |
|
||||||
|--------------- |--------: |--------: |--------: |--------: |--------: |
|
|--------------- |--------: |--------: |--------: |--------: |--------: |
|
||||||
|admin.min.js | 252.147 | 128.671 | 73.657 | 37.600 | 32.254 |
|
|admin.min.js | 252.147 | 128.146 | 73.657 | 37.448 | 32.137 |
|
||||||
|app.min.js | 511.202 | 346.350 |140.462 | 90.770 | 73.272 |
|
|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 |
|
|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 |
|
|libs.min.js | 572.545 | 304.000 |176.720 | 94.870 | 83.524 |
|
||||||
|polyfills.min.js | 32.452 | 0 | 11.312 | 0 | 0 |
|
|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
|
### CSS changes
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -184,13 +184,6 @@ class MessageModel extends AbstractModel {
|
||||||
).filter((value, index, self) => !!value && self.indexOf(value) == index);
|
).filter((value, index, self) => !!value && self.indexOf(value) == index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @returns {Array}
|
|
||||||
*/
|
|
||||||
getRecipientsEmails() {
|
|
||||||
return this.getEmails(['to', 'cc']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -70,14 +70,19 @@ class AbstractFetchRemote
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {?Function} fResultCallback
|
* @param {?Function} fCallback
|
||||||
* @param {Object} oParameters
|
* @param {string} sAction
|
||||||
* @param {?number=} iTimeOut = 20000
|
* @param {Object=} oParameters
|
||||||
|
* @param {?number=} iTimeout
|
||||||
* @param {string=} sGetAdd = ''
|
* @param {string=} sGetAdd = ''
|
||||||
* @param {Array=} aAbortActions = []
|
* @param {Array=} aAbortActions = []
|
||||||
*/
|
*/
|
||||||
ajaxRequest(fResultCallback, params, iTimeOut = 20000, sGetAdd = '', abortActions = []) {
|
defaultRequest(fCallback, sAction, params, iTimeout, sGetAdd, abortActions) {
|
||||||
params = params || {};
|
params = params || {};
|
||||||
|
params.Action = sAction;
|
||||||
|
|
||||||
|
sGetAdd = pString(sGetAdd);
|
||||||
|
|
||||||
const start = Date.now(),
|
const start = Date.now(),
|
||||||
action = params.Action || '';
|
action = params.Action || '';
|
||||||
|
|
||||||
|
|
@ -86,8 +91,8 @@ class AbstractFetchRemote
|
||||||
}
|
}
|
||||||
|
|
||||||
return rl.fetchJSON(getURL(sGetAdd), {
|
return rl.fetchJSON(getURL(sGetAdd), {
|
||||||
signal: this.createAbort(action, iTimeOut)
|
signal: this.createAbort(action, undefined === iTimeout ? DEFAULT_AJAX_TIMEOUT : pInt(iTimeout))
|
||||||
}, iTimeOut, sGetAdd ? null : params
|
}, sGetAdd ? null : params
|
||||||
).then(data => {
|
).then(data => {
|
||||||
let cached = false;
|
let cached = false;
|
||||||
if (data) {
|
if (data) {
|
||||||
|
|
@ -117,8 +122,8 @@ class AbstractFetchRemote
|
||||||
iAjaxErrorCount = iTokenErrorCount = 0;
|
iAjaxErrorCount = iTokenErrorCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fResultCallback) {
|
if (fCallback) {
|
||||||
fResultCallback(
|
fCallback(
|
||||||
sType,
|
sType,
|
||||||
StorageResultType.Success === sType ? data : null,
|
StorageResultType.Success === sType ? data : null,
|
||||||
cached,
|
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
|
* @param {?Function} fCallback
|
||||||
*/
|
*/
|
||||||
|
|
@ -234,7 +218,7 @@ class AbstractFetchRemote
|
||||||
|
|
||||||
return rl.fetchJSON(getURL(), {
|
return rl.fetchJSON(getURL(), {
|
||||||
signal: this.createAbort(action, pInt(timeOut, DEFAULT_AJAX_TIMEOUT))
|
signal: this.createAbort(action, pInt(timeOut, DEFAULT_AJAX_TIMEOUT))
|
||||||
}, pInt(timeOut, DEFAULT_AJAX_TIMEOUT), params
|
}, params
|
||||||
).then(data => {
|
).then(data => {
|
||||||
this.abort(action, true);
|
this.abort(action, true);
|
||||||
|
|
||||||
|
|
|
||||||
17
dev/bootstrap.js
vendored
17
dev/bootstrap.js
vendored
|
|
@ -53,7 +53,7 @@ export default (App) => {
|
||||||
dropdownVisibility(!!rl.Dropdowns.find(item => item.classList.contains('open')))
|
dropdownVisibility(!!rl.Dropdowns.find(item => item.classList.contains('open')))
|
||||||
).debounce(50);
|
).debounce(50);
|
||||||
|
|
||||||
rl.fetchJSON = (resource, init, timeout, postData) => {
|
rl.fetchJSON = (resource, init, postData) => {
|
||||||
init = Object.assign({
|
init = Object.assign({
|
||||||
mode: 'same-origin',
|
mode: 'same-origin',
|
||||||
cache: 'no-cache',
|
cache: 'no-cache',
|
||||||
|
|
@ -85,21 +85,6 @@ export default (App) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetch(resource, init).then(response => response.json());
|
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 => {
|
window.__APP_BOOT = fErrorCallback => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue