mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-31 21:19:21 +03:00
Replace timeOutAction() with debounce
Replace delegateRun() Revert my throttle/debounce setTimeout() to Function.prototype[throttle/debounce]
This commit is contained in:
parent
f6a55898c7
commit
97a73c6639
28 changed files with 225 additions and 372 deletions
|
|
@ -145,7 +145,7 @@ class CookieDriver {
|
|||
|
||||
try {
|
||||
const storageResult = Cookies.getJSON(CLIENT_SIDE_STORAGE_INDEX_NAME);
|
||||
result = storageResult && undefined !== storageResult[key] ? storageResult[key] : null;
|
||||
result = storageResult && null != storageResult[key] ? storageResult[key] : null;
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ class LocalStorageDriver {
|
|||
const storageValue = this.s.getItem(CLIENT_SIDE_STORAGE_INDEX_NAME) || null,
|
||||
storageResult = null === storageValue ? null : JSON.parse(storageValue);
|
||||
|
||||
return storageResult && undefined !== storageResult[key] ? storageResult[key] : null;
|
||||
return storageResult && null != storageResult[key] ? storageResult[key] : null;
|
||||
} catch (e) {} // eslint-disable-line no-empty
|
||||
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -32,16 +32,7 @@ class HtmlEditor {
|
|||
this.element = element;
|
||||
this.$element = jQuery(element);
|
||||
|
||||
// throttle
|
||||
var t, o = this;
|
||||
this.resize = ()=>{
|
||||
if (!t) {
|
||||
t = setTimeout(()=>{
|
||||
o.resizeEditor();
|
||||
t = 0;
|
||||
}, 100);
|
||||
}
|
||||
};
|
||||
this.resize = this.resizeEditor.throttle(100);
|
||||
|
||||
this.init();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,6 @@ export function runSettingsViewModelHooks(admin) {
|
|||
*/
|
||||
export function settingsGet(pluginSection, name) {
|
||||
let plugins = Settings.settingsGet('Plugins');
|
||||
plugins = plugins && undefined !== plugins[pluginSection] ? plugins[pluginSection] : null;
|
||||
return plugins ? (undefined === plugins[name] ? null : plugins[name]) : null;
|
||||
plugins = plugins && null != plugins[pluginSection] ? plugins[pluginSection] : null;
|
||||
return plugins ? (null == plugins[name] ? null : plugins[name]) : null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,12 +52,7 @@ class Selector {
|
|||
this.focusedItem = koFocusedItem || ko.observable(null);
|
||||
this.selectedItem = koSelectedItem || ko.observable(null);
|
||||
|
||||
var d, o = this;
|
||||
this.itemSelectedThrottle = (item)=>{
|
||||
// debounce
|
||||
clearTimeout(d);
|
||||
d = setTimeout(()=>o.itemSelected(item), 300);
|
||||
};
|
||||
this.itemSelectedThrottle = (item=>this.itemSelected(item)).debounce(300);
|
||||
|
||||
this.listChecked.subscribe((items) => {
|
||||
if (items.length) {
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ export function i18n(key, valueList, defaulValue) {
|
|||
result = undefined === defaulValue ? key : defaulValue;
|
||||
}
|
||||
|
||||
if (undefined !== valueList && null !== valueList) {
|
||||
if (null != valueList) {
|
||||
for (valueName in valueList) {
|
||||
if (Object.prototype.hasOwnProperty.call(valueList, valueName)) {
|
||||
result = result.replace('%' + valueName + '%', valueList[valueName]);
|
||||
|
|
|
|||
|
|
@ -124,17 +124,6 @@ export function splitPlainText(text, len = 100) {
|
|||
return prefix + result;
|
||||
}
|
||||
|
||||
const timeOutAction = (() => {
|
||||
const timeOuts = {};
|
||||
return (action, fFunction, timeOut) => {
|
||||
timeOuts[action] = undefined === timeOuts[action] ? 0 : timeOuts[action];
|
||||
clearTimeout(timeOuts[action]);
|
||||
timeOuts[action] = setTimeout(fFunction, timeOut);
|
||||
};
|
||||
})();
|
||||
|
||||
export { timeOutAction };
|
||||
|
||||
/**
|
||||
* @param {any} m
|
||||
* @returns {any}
|
||||
|
|
@ -258,27 +247,6 @@ export function friendlySize(sizeInBytes) {
|
|||
return sizeInBytes + 'B';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?} object
|
||||
* @param {string} methodName
|
||||
* @param {Array=} params
|
||||
* @param {number=} delay = 0
|
||||
*/
|
||||
export function delegateRun(object, methodName, params, delay = 0) {
|
||||
if (object && object[methodName]) {
|
||||
delay = pInt(delay);
|
||||
params = isArray(params) ? params : [];
|
||||
|
||||
if (0 >= delay) {
|
||||
object[methodName](...params);
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
object[methodName](...params);
|
||||
}, delay);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {(Object|null|undefined)} context
|
||||
* @param {Function} fExecute
|
||||
|
|
@ -830,14 +798,9 @@ export function selectElement(element) {
|
|||
sel.addRange(range);
|
||||
}
|
||||
|
||||
var dv;
|
||||
export const detectDropdownVisibility = ()=>{
|
||||
// leading debounce
|
||||
clearTimeout(dv);
|
||||
dv = setTimeout(()=>
|
||||
dropdownVisibility(!!GlobalsData.aBootstrapDropdowns.find(item => item.hasClass('open')))
|
||||
, 50);
|
||||
};
|
||||
export const detectDropdownVisibility = (()=>
|
||||
dropdownVisibility(!!GlobalsData.aBootstrapDropdowns.find(item => item.hasClass('open')))
|
||||
).debounce(50);
|
||||
|
||||
/**
|
||||
* @param {boolean=} delay = false
|
||||
|
|
@ -881,11 +844,9 @@ export function getConfigurationFromScriptTag(configuration) {
|
|||
export function delegateRunOnDestroy(objectOrObjects) {
|
||||
if (objectOrObjects) {
|
||||
if (isArray(objectOrObjects)) {
|
||||
objectOrObjects.forEach(item => {
|
||||
delegateRunOnDestroy(item);
|
||||
});
|
||||
} else if (objectOrObjects && objectOrObjects.onDestroy) {
|
||||
objectOrObjects.onDestroy();
|
||||
objectOrObjects.forEach(item => delegateRunOnDestroy(item));
|
||||
} else {
|
||||
objectOrObjects.onDestroy && objectOrObjects.onDestroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1199,8 +1160,8 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
|
|||
to,
|
||||
cc,
|
||||
bcc,
|
||||
undefined === params.subject ? null : pString(decodeURIComponent(params.subject)),
|
||||
undefined === params.body ? null : plainToHtml(pString(decodeURIComponent(params.body)))
|
||||
null == params.subject ? null : pString(decodeURIComponent(params.subject)),
|
||||
null == params.body ? null : plainToHtml(pString(decodeURIComponent(params.body)))
|
||||
]);
|
||||
|
||||
return true;
|
||||
|
|
@ -1212,7 +1173,7 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
|
|||
var wr;
|
||||
export const windowResize = timeout => {
|
||||
clearTimeout(wr);
|
||||
if (undefined === timeout || null === timeout) {
|
||||
if (null == timeout) {
|
||||
$win.trigger('resize');
|
||||
} else {
|
||||
wr = setTimeout(()=>$win.trigger('resize'), timeout);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue