Replace timeOutAction() with debounce

Replace delegateRun()
Revert my throttle/debounce setTimeout() to Function.prototype[throttle/debounce]
This commit is contained in:
djmaze 2020-08-18 20:24:17 +02:00
parent f6a55898c7
commit 97a73c6639
28 changed files with 225 additions and 372 deletions

View file

@ -31,25 +31,18 @@ class AbstractApp extends AbstractBoot {
this.isLocalAutocomplete = true;
this.lastErrorTime = 0;
var t;
addEventListener(
'resize',
()=>{
// throttle
if (!t) {
t = setTimeout(()=>{
const iH = $win.height(),
iW = $win.height();
(()=>{
const iH = $win.height(),
iW = $win.height();
if ($win.__sizes[0] !== iH || $win.__sizes[1] !== iW) {
$win.__sizes[0] = iH;
$win.__sizes[1] = iW;
dispatchEvent(new CustomEvent('resize.real'));
}
t = 0;
}, 50);
if ($win.__sizes[0] !== iH || $win.__sizes[1] !== iW) {
$win.__sizes[0] = iH;
$win.__sizes[1] = iW;
dispatchEvent(new CustomEvent('resize.real'));
}
}
}).throttle(50)
);
const $doc = document;
@ -64,12 +57,7 @@ class AbstractApp extends AbstractBoot {
}
});
var d;
const fn = ()=>{
// debounce
clearTimeout(d);
d = setTimeout(()=>dispatchEvent(new CustomEvent('rl.auto-logout-refresh')), 5000);
}
const fn = (()=>dispatchEvent(new CustomEvent('rl.auto-logout-refresh'))).debounce(5000);
$doc.addEventListener('mousemove', fn);
$doc.addEventListener('keypress', fn);

View file

@ -81,16 +81,14 @@ import { AbstractApp } from 'App/Abstract';
const doc = document;
if (!window.ResizeObserver) {
let rot;
window.ResizeObserver = class {
constructor(callback) {
callback = callback.debounce(250);
this.observer = new MutationObserver(mutations => {
let i = mutations.length;
while (i--) {
if ('style' == mutations[i].attributeName) {
// debounce
clearTimeout(rot);
rot = setTimeout(callback, 250);
callback();
break;
}
}
@ -113,15 +111,11 @@ class AppUser extends AbstractApp {
this.moveCache = {};
let qd, o = this;
this.quotaDebounce = ()=>{
// debounce
clearTimeout(qd);
qd = setTimeout(o.quota, 30000);
};
this.quotaDebounce = this.quota.debounce(30000);
this.moveOrDeleteResponseHelper = this.moveOrDeleteResponseHelper.bind(this);
this.messagesMoveTrigger = this.messagesMoveTrigger.debounce(500);
// wakeUp
const interval = 3600000; // 60m
var lastTime = (new Date()).getTime();
@ -262,30 +256,25 @@ class AppUser extends AbstractApp {
}
messagesMoveTrigger() {
// debounce
const o = this;
clearTimeout(o.mt);
o.mt = setTimeout(()=>{
const sTrashFolder = FolderStore.trashFolder(),
sSpamFolder = FolderStore.spamFolder();
const sTrashFolder = FolderStore.trashFolder(),
sSpamFolder = FolderStore.spamFolder();
Object.values(o.moveCache).forEach(item => {
const isSpam = sSpamFolder === item.To,
isTrash = sTrashFolder === item.To,
isHam = !isSpam && sSpamFolder === item.From && getFolderInboxName() === item.To;
Object.values(this.moveCache).forEach(item => {
const isSpam = sSpamFolder === item.To,
isTrash = sTrashFolder === item.To,
isHam = !isSpam && sSpamFolder === item.From && getFolderInboxName() === item.To;
Remote.messagesMove(
o.moveOrDeleteResponseHelper,
item.From,
item.To,
item.Uid,
isSpam ? 'SPAM' : isHam ? 'HAM' : '',
isSpam || isTrash
);
});
Remote.messagesMove(
this.moveOrDeleteResponseHelper,
item.From,
item.To,
item.Uid,
isSpam ? 'SPAM' : isHam ? 'HAM' : '',
isSpam || isTrash
);
});
o.moveCache = {};
}, 500);
this.moveCache = {};
}
messagesMoveHelper(fromFolderFullNameRaw, toFolderFullNameRaw, uidsForMove) {