Underscore.js _.delay() to native setTimeout()

This commit is contained in:
djmaze 2020-07-22 20:28:25 +02:00
parent a82575a830
commit 43c92a82e6
29 changed files with 67 additions and 82 deletions

View file

@ -131,7 +131,7 @@ class AbstractApp extends AbstractBoot {
}
redirectToAdminPanel() {
_.delay(() => {
setTimeout(() => {
window.location.href = rootAdmin();
}, Magics.Time100ms);
}
@ -174,7 +174,7 @@ class AbstractApp extends AbstractBoot {
customLogoutLink = customLogoutLink || (admin ? rootAdmin() : rootUser());
if (logout && window.location.href !== customLogoutLink) {
_.delay(() => {
setTimeout(() => {
if (inIframe && window.parent) {
window.parent.location.href = customLogoutLink;
} else {
@ -188,7 +188,7 @@ class AbstractApp extends AbstractBoot {
setHash(root(), true);
routeOff();
_.delay(() => {
setTimeout(() => {
if (inIframe && window.parent) {
window.parent.location.reload();
} else {
@ -233,7 +233,7 @@ class AbstractApp extends AbstractBoot {
initOnStartOrLangChange(initNotificationLanguage);
_.delay(windowResizeCallback, Magics.Time1s);
setTimeout(windowResizeCallback, Magics.Time1s);
Events.sub('ssm.mobile-enter', () => {
leftPanelDisabled(true);

View file

@ -173,7 +173,7 @@ class AppUser extends AbstractApp {
}
if (Settings.settingsGet('UserBackgroundHash')) {
_.delay(() => {
setTimeout(() => {
const img = userBackground(Settings.settingsGet('UserBackgroundHash'));
if (img) {
$htmlCL.add('UserBackground');
@ -455,7 +455,7 @@ class AppUser extends AbstractApp {
.then((value) => !!value)
.then(callback)
.catch(() => {
_.delay(() => {
setTimeout(() => {
if (callback) {
callback(false); // eslint-disable-line callback-return
}
@ -597,7 +597,7 @@ class AppUser extends AbstractApp {
}
if (isUnd(bBoot) ? false : !!bBoot) {
_.delay(() => this.accountsCounts(), 1000 * 5);
setTimeout(() => this.accountsCounts(), 1000 * 5);
Events.sub('interval.10m-after5m', () => this.accountsCounts());
}
@ -797,7 +797,7 @@ class AppUser extends AbstractApp {
});
if (boot) {
_.delay(() => this.folderInformationMultiply(true), 2000);
setTimeout(() => this.folderInformationMultiply(true), 2000);
}
}
}
@ -1141,22 +1141,22 @@ class AppUser extends AbstractApp {
contactsSyncInterval = 5 <= contactsSyncInterval ? contactsSyncInterval : 20;
contactsSyncInterval = 320 >= contactsSyncInterval ? contactsSyncInterval : 320;
_.delay(() => this.contactsSync(), Magics.Time10s);
_.delay(() => this.folderInformationMultiply(true), Magics.Time2s);
setTimeout(() => this.contactsSync(), Magics.Time10s);
setTimeout(() => this.folderInformationMultiply(true), Magics.Time2s);
window.setInterval(() => this.contactsSync(), contactsSyncInterval * 60000 + 5000);
this.accountsAndIdentities(true);
_.delay(() => {
setTimeout(() => {
const sF = FolderStore.currentFolderFullNameRaw();
if (getFolderInboxName() !== sF) {
this.folderInformation(sF);
}
}, 1000);
_.delay(() => this.quota(), 5000);
_.delay(() => Remote.appDelayStart(noop), 35000);
setTimeout(() => this.quota(), 5000);
setTimeout(() => Remote.appDelayStart(noop), 35000);
Events.sub('rl.auto-logout', () => this.logout());
@ -1164,7 +1164,7 @@ class AppUser extends AbstractApp {
Events.pub('rl.bootstart-user-screens');
if (Settings.settingsGet('WelcomePageUrl')) {
_.delay(() => this.bootstartWelcomePopup(Settings.settingsGet('WelcomePageUrl')), 1000);
setTimeout(() => this.bootstartWelcomePopup(Settings.settingsGet('WelcomePageUrl')), 1000);
}
if (
@ -1172,7 +1172,7 @@ class AppUser extends AbstractApp {
window.navigator.registerProtocolHandler &&
Settings.capa(Capa.Composer)
) {
_.delay(() => {
setTimeout(() => {
try {
window.navigator.registerProtocolHandler(
'mailto',

View file

@ -222,7 +222,7 @@ class Selector {
this.scrollToFocused();
_.delay(() => this.scrollToFocused(), 100);
setTimeout(this.scrollToFocused, 100);
}
this.iSelectNextHelper = 0;

View file

@ -270,7 +270,7 @@ export function reload(admin, language) {
cache: true
}).then(
() => {
_.delay(
setTimeout(
() => {
reloadData();

View file

@ -380,7 +380,7 @@ export function delegateRun(object, methodName, params, delay = 0) {
if (0 >= delay) {
object[methodName](...params);
} else {
_.delay(() => {
setTimeout(() => {
object[methodName](...params);
}, delay);
}
@ -597,7 +597,7 @@ export function settingsSaveHelperFunction(fCallback, koTrigger, context = null,
if (fCallback) {
fCallback.call(context, type, data, cached, requestAction, requestParameters);
}
_.delay(() => {
setTimeout(() => {
koTrigger.call(context, SaveSettingsStep.Idle);
}, timer);
};
@ -1029,7 +1029,7 @@ export function triggerAutocompleteInputChange(delay = false) {
};
if (delay) {
_.delay(fFunc, 100);
setTimeout(fFunc, 100);
} else {
fFunc();
}

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { componentExportHelper } from 'Component/Abstract';
import { AbstractCheckbox } from 'Component/AbstractCheckbox';
@ -34,10 +33,10 @@ class CheckboxMaterialDesignComponent extends AbstractCheckbox {
triggerAnimation(box) {
if (box) {
this.animationBoxSetTrue();
_.delay(this.animationCheckmarkSetTrue, 200);
setTimeout(this.animationCheckmarkSetTrue, 200);
} else {
this.animationCheckmarkSetTrue();
_.delay(this.animationBoxSetTrue, 200);
setTimeout(this.animationBoxSetTrue, 200);
}
}
}

12
dev/External/ko.js vendored
View file

@ -21,7 +21,7 @@ ko.bindingHandlers.updateWidth = {
fValue = fValueAccessor(),
fInit = () => {
fValue($el.width());
window.setTimeout(() => {
setTimeout(() => {
fValue($el.width());
}, Magics.Time500ms);
};
@ -127,7 +127,7 @@ ko.bindingHandlers.visibleAnimated = {
const $el = $(element);
if (ko.unwrap(fValueAccessor())) {
$el.addClass('rl-animated-hidden').show();
_.delay(() => {
setTimeout(() => {
$el.removeClass('rl-animated-hidden');
}, 10);
} else {
@ -249,7 +249,7 @@ ko.bindingHandlers.tooltipErrorTip = {
openTips.deactivate();
openTips.setContent('');
} else {
_.delay(() => {
setTimeout(() => {
if ($el.is(':visible')) {
openTips.setContent(value);
openTips.activate();
@ -461,7 +461,7 @@ ko.bindingHandlers.modal = {
if (Globals.$htmlCL.contains('rl-anim')) {
Globals.$htmlCL.add('rl-modal-animation');
_.delay(() => {
setTimeout(() => {
Globals.$htmlCL.remove('rl-modal-animation');
}, Magics.Time500ms);
}
@ -1031,7 +1031,7 @@ ko.extenders.falseTimeout = (target, option) => {
target.subscribe((value) => {
if (value) {
window.clearTimeout(target.iFalseTimeoutTimeout);
target.iFalseTimeoutTimeout = window.setTimeout(() => {
target.iFalseTimeoutTimeout = setTimeout(() => {
target(false);
target.iFalseTimeoutTimeout = 0;
}, require('Common/Utils').pInt(option));
@ -1055,7 +1055,7 @@ ko.extenders.specialThrottle = (target, option) => {
} else {
if (target.valueForRead()) {
window.clearTimeout(target.iSpecialThrottleTimeout);
target.iSpecialThrottleTimeout = window.setTimeout(() => {
target.iSpecialThrottleTimeout = setTimeout(() => {
target.valueForRead(false);
target.iSpecialThrottleTimeout = 0;
}, target.iSpecialThrottleTimeoutValue);

View file

@ -202,7 +202,7 @@ export function buildViewModel(ViewModelClass, vmScreen) {
popupVisibilityNames.remove(vm.viewModelName);
vm.viewModelDom.css('z-index', 2000);
_.delay(() => vm.viewModelDom.hide(), 300);
setTimeout(() => vm.viewModelDom.hide(), 300);
}
});
}
@ -432,11 +432,11 @@ export function startScreens(screensClasses) {
hasher.changed.add(cross.parse, cross);
hasher.init();
_.delay(() => {
setTimeout(() => {
$htmlCL.remove('rl-started-trigger');
$htmlCL.add('rl-started');
}, 100);
_.delay(() => $htmlCL.add('rl-started-delay'), 200);
setTimeout(() => $htmlCL.add('rl-started-delay'), 200);
}
/**

View file

@ -856,7 +856,7 @@ class MessageModel extends AbstractModel {
if (lazy) {
// $('.RL-MailMessageView .messageView .messageItem .content')[0]
_.delay(() => this.lozad(), 300);
setTimeout(() => this.lozad(), 300);
}
windowResize(500);

View file

@ -109,8 +109,8 @@ class MailBoxUserScreen extends AbstractScreen {
MessageStore.messageList.subscribe(windowResizeCallback);
MessageStore.message.subscribe(windowResizeCallback);
_.delay(() => SettingsStore.layout.valueHasMutated(), Magics.Time50ms);
_.delay(() => warmUpScreenPopup(require('View/Popup/Compose')), Magics.Time500ms);
setTimeout(() => SettingsStore.layout.valueHasMutated(), Magics.Time50ms);
setTimeout(() => warmUpScreenPopup(require('View/Popup/Compose')), Magics.Time500ms);
Events.sub('mailbox.inbox-unread-count', (count) => {
FolderStore.foldersInboxUnreadCount(count);

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { Magics } from 'Common/Enums';
@ -41,7 +40,7 @@ class BrandingAdminSettings {
}
onBuild() {
_.delay(() => {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.title.trigger, this),
f2 = settingsSaveHelperSimpleFunction(this.loadingDesc.trigger, this),
f3 = settingsSaveHelperSimpleFunction(this.faviconUrl.trigger, this);

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { settingsSaveHelperSimpleFunction, defautOptionsAfterRender, trim, boolToAjax } from 'Common/Utils';
@ -144,7 +143,7 @@ class ContactsAdminSettings {
}
onBuild() {
_.delay(() => {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.pdoDsnTrigger, this),
f3 = settingsSaveHelperSimpleFunction(this.pdoUserTrigger, this),
f4 = settingsSaveHelperSimpleFunction(this.pdoPasswordTrigger, this),

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import {
@ -76,13 +75,13 @@ class GeneralAdminSettings {
}
onBuild() {
_.delay(() => {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.attachmentLimitTrigger, this),
f2 = settingsSaveHelperSimpleFunction(this.languageTrigger, this),
f3 = settingsSaveHelperSimpleFunction(this.themeTrigger, this),
fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageAdminTrigger(saveSettingsStep);
_.delay(() => this.languageAdminTrigger(SaveSettingsStep.Idle), Magics.Time1s);
setTimeout(() => this.languageAdminTrigger(SaveSettingsStep.Idle), Magics.Time1s);
};
this.mainAttachmentLimit.subscribe((value) => {

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { settingsSaveHelperSimpleFunction, boolToAjax, trim } from 'Common/Utils';
@ -20,7 +19,7 @@ class LoginAdminSettings {
}
onBuild() {
_.delay(() => {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.defaultDomain.trigger, this);
this.determineUserLanguage.subscribe((value) => {

View file

@ -1,4 +1,3 @@
import _ from '_';
import { settingsSaveHelperSimpleFunction, trim } from 'Common/Utils';
import { Magics } from 'Common/Enums';
@ -11,7 +10,7 @@ class BrandingPremAdminSettings extends BrandingAdminSettings {
super.onBuild(dom);
if (this.capa && this.capa() && !this.community) {
_.delay(() => {
setTimeout(() => {
const f1 = settingsSaveHelperSimpleFunction(this.loginLogo.trigger, this),
f2 = settingsSaveHelperSimpleFunction(this.loginDescription.trigger, this),
f3 = settingsSaveHelperSimpleFunction(this.loginCss.trigger, this),

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { trim, boolToAjax } from 'Common/Utils';
@ -105,7 +104,7 @@ class SecurityAdminSettings {
this.twoFactorDropperUser('');
this.isTwoFactorDropperShown(true);
_.delay(() => {
setTimeout(() => {
this.twoFactorDropperUser.focused(true);
}, Magics.Time50ms);
}

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { MESSAGES_PER_PAGE_VALUES } from 'Common/Consts';
@ -96,13 +95,13 @@ class GeneralUserSettings {
}
onBuild() {
_.delay(() => {
setTimeout(() => {
const f0 = settingsSaveHelperSimpleFunction(this.editorDefaultTypeTrigger, this),
f1 = settingsSaveHelperSimpleFunction(this.mppTrigger, this),
f2 = settingsSaveHelperSimpleFunction(this.layoutTrigger, this),
fReloadLanguageHelper = (saveSettingsStep) => () => {
this.languageTrigger(saveSettingsStep);
_.delay(() => this.languageTrigger(SaveSettingsStep.Idle), Magics.Time1s);
setTimeout(() => this.languageTrigger(SaveSettingsStep.Idle), Magics.Time1s);
};
this.language.subscribe((value) => {

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { delegateRunOnDestroy, boolToAjax } from 'Common/Utils';
@ -66,7 +65,7 @@ class OpenPgpUserSettings {
}
onBuild() {
_.delay(() => {
setTimeout(() => {
this.allowDraftAutosave.subscribe(Remote.saveSettingsHelper('AllowDraftAutosave', boolToAjax));
}, Magics.Time50ms);
}

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { pInt, settingsSaveHelperSimpleFunction } from 'Common/Utils';
@ -42,7 +41,7 @@ class SecurityUserSettings {
onBuild() {
if (this.capaAutoLogout) {
_.delay(() => {
setTimeout(() => {
const f0 = settingsSaveHelperSimpleFunction(this.autoLogout.trigger, this);
this.autoLogout.subscribe(Remote.saveSettingsHelper('AutoLogout', pInt, f0));

View file

@ -239,7 +239,7 @@ class MessageUserStore {
});
if (0 < count) {
_.delay(() => messagesDom.find('.rl-cache-purge').remove(), Magics.Time350ms);
setTimeout(() => messagesDom.find('.rl-cache-purge').remove(), Magics.Time350ms);
}
}
}
@ -358,7 +358,7 @@ class MessageUserStore {
item.deleted(true);
});
_.delay(() => {
setTimeout(() => {
messages.forEach(item => {
this.messageList.remove(item);
});

View file

@ -1,5 +1,4 @@
import ko from 'ko';
import _ from '_';
import { trim, triggerAutocompleteInputChange } from 'Common/Utils';
@ -103,7 +102,7 @@ class LoginAdminView extends AbstractViewNext {
onShow() {
routeOff();
_.delay(() => {
setTimeout(() => {
this.loginFocus(true);
}, Magics.Time100ms);
}

View file

@ -508,7 +508,7 @@ class ComposePopupView extends AbstractViewNext {
contactsCommand() {
if (this.allowContacts) {
this.skipCommand();
_.delay(() => {
setTimeout(() => {
showScreenPopup(require('View/Popup/Contacts'), [true, this.sLastFocusedField]);
}, Magics.Time200ms);
}
@ -706,7 +706,7 @@ class ComposePopupView extends AbstractViewNext {
editor(fOnInit) {
if (fOnInit) {
if (!this.oEditor && this.composeEditorArea()) {
// _.delay(() => {
// setTimeout(() => {
this.oEditor = new HtmlEditor(
this.composeEditorArea(),
null,
@ -1169,7 +1169,7 @@ class ComposePopupView extends AbstractViewNext {
setFocusInPopup() {
if (!bMobileDevice) {
_.delay(() => {
setTimeout(() => {
if ('' === this.to()) {
this.to.focused(true);
} else if (this.oEditor) {

View file

@ -178,7 +178,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
}
if (result && this.resultCallback) {
_.delay(() => {
setTimeout(() => {
let pgpPromise = null;
try {

View file

@ -276,7 +276,7 @@ class ContactsPopupView extends AbstractViewNext {
this.sLastComposeFocusedField = '';
_.delay(() => {
setTimeout(() => {
showScreenPopup(require('View/Popup/Compose'), [ComposeType.Empty, null, toEmails, ccEmails, bccEmails]);
}, Magics.Time200ms);
}
@ -327,14 +327,14 @@ class ContactsPopupView extends AbstractViewNext {
res = true;
}
_.delay(() => {
setTimeout(() => {
this.viewSaveTrigger(res ? SaveSettingsStep.TrueResult : SaveSettingsStep.FalseResult);
}, Magics.Time350ms);
if (res) {
this.watchDirty(false);
_.delay(() => {
setTimeout(() => {
this.viewSaveTrigger(SaveSettingsStep.Idle);
}, Magics.Time1s);
}
@ -470,7 +470,7 @@ class ContactsPopupView extends AbstractViewNext {
this.bDropPageAfterDelete = true;
}
_.delay(() => {
setTimeout(() => {
contacts.forEach(contact => {
koContacts.remove(contact);
delegateRunOnDestroy(contact);
@ -495,7 +495,7 @@ class ContactsPopupView extends AbstractViewNext {
if (Magics.Time500ms < (StorageResultType.Success === sResult && oData && oData.Time ? pInt(oData.Time) : 0)) {
this.reloadContactList(this.bDropPageAfterDelete);
} else {
_.delay(() => {
setTimeout(() => {
this.reloadContactList(this.bDropPageAfterDelete);
}, Magics.Time500ms);
}

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import key from 'key';
import $ from '$';
@ -37,7 +36,7 @@ class MessageOpenPgpPopupView extends AbstractViewNext {
doCommand() {
this.submitRequest(true);
_.delay(() => {
setTimeout(() => {
let privateKey = null;
try {

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { Magics } from 'Common/Enums';
@ -53,7 +52,7 @@ class NewOpenPgpKeyPopupView extends AbstractViewNext {
this.submitRequest(true);
this.submitError('');
_.delay(() => {
setTimeout(() => {
try {
PgpStore.openpgp
.generateKey({

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import key from 'key';
@ -54,7 +53,7 @@ class AbstractSystemDropDownUserView extends AbstractViewNext {
accountClick(account, event) {
if (account && event && !isUnd(event.which) && 1 === event.which) {
AccountStore.accounts.loading(true);
_.delay(() => AccountStore.accounts.loading(false), Magics.Time1s);
setTimeout(() => AccountStore.accounts.loading(false), Magics.Time1s);
}
return true;

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import {
@ -217,7 +216,7 @@ class LoginUserView extends AbstractViewNext {
this.additionalCode.visibility(true);
this.submitRequest(false);
_.delay(() => this.additionalCode.focused(true), Magics.Time100ms);
setTimeout(() => this.additionalCode.focused(true), Magics.Time100ms);
} else if (oData.Admin) {
getApp().redirectToAdminPanel();
} else {
@ -317,7 +316,7 @@ class LoginUserView extends AbstractViewNext {
this.email(AppStore.devEmail);
this.password(AppStore.devPassword);
_.delay(() => {
setTimeout(() => {
LanguageStore.language.subscribe((value) => {
this.langRequest(true);
@ -346,7 +345,7 @@ class LoginUserView extends AbstractViewNext {
selectLanguageOnTab(bShift) {
if (!bShift) {
_.delay(() => {
setTimeout(() => {
this.emailFocus(true);
}, Magics.Time50ms);

View file

@ -262,7 +262,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
if (message) {
this.showAttachmnetControls(false);
if (Local.get(ClientSideKeyName.MessageAttachmnetControls)) {
_.delay(() => {
setTimeout(() => {
this.showAttachmnetControls(true);
}, Magics.Time50ms);
}
@ -547,9 +547,9 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
Events.sub(
'window.resize',
_.throttle(() => {
_.delay(fCheckHeaderHeight, 1);
_.delay(fCheckHeaderHeight, Magics.Time200ms);
_.delay(fCheckHeaderHeight, Magics.Time500ms);
setTimeout(fCheckHeaderHeight, 1);
setTimeout(fCheckHeaderHeight, Magics.Time200ms);
setTimeout(fCheckHeaderHeight, Magics.Time500ms);
}, Magics.Time50ms)
);