isArray to native Array.isArray

isUnd(*) to native undefined === *
isFunc to native typeof * === 'function'
isObject to native typeof * === 'object'
microtime() to native Date().getTime();
noop to native ()=>{}
noopFalse to native ()=>false
noopTrue to native ()=>true
boolToAjax to native *?'1':'0'
Underscore.js to native
This commit is contained in:
djmaze 2020-07-29 21:49:41 +02:00
parent fa39c7ecba
commit ea48f5060b
72 changed files with 551 additions and 775 deletions

View file

@ -1,7 +1,7 @@
import ko from 'ko';
import { StorageResultType, Notification } from 'Common/Enums';
import { trim, isUnd } from 'Common/Utils';
import { trim } from 'Common/Utils';
import { RAINLOOP_TRIAL_KEY } from 'Common/Consts';
import { i18n, getNotification } from 'Common/Translator';
@ -89,7 +89,7 @@ class ActivatePopupView extends AbstractViewNext {
onShow(isTrial) {
this.domain(Settings.settingsGet('AdminDomain'));
if (!this.activateProcess()) {
isTrial = isUnd(isTrial) ? false : !!isTrial;
isTrial = undefined === isTrial ? false : !!isTrial;
this.key(isTrial ? RAINLOOP_TRIAL_KEY : '');
this.activateText('');

View file

@ -2,7 +2,6 @@ import ko from 'ko';
import key from 'key';
import { KeyState } from 'Common/Enums';
import { isFunc } from 'Common/Utils';
import { i18n } from 'Common/Translator';
import { popup } from 'Knoin/Knoin';
@ -46,7 +45,7 @@ class AskPopupView extends AbstractViewNext {
yesClick() {
this.cancelCommand();
if (isFunc(this.fYesAction)) {
if (typeof this.fYesAction === 'function') {
this.fYesAction.call(null);
}
}
@ -54,7 +53,7 @@ class AskPopupView extends AbstractViewNext {
noClick() {
this.cancelCommand();
if (isFunc(this.fNoAction)) {
if (typeof this.fNoAction === 'function') {
this.fNoAction.call(null);
}
}

View file

@ -1,5 +1,3 @@
import window from 'window';
import _ from '_';
import $ from '$';
import ko from 'ko';
import key from 'key';
@ -19,18 +17,15 @@ import {
import {
trim,
isArray,
isNormal,
delegateRun,
isNonEmptyArray,
clearBqSwitcher,
replySubjectAdd,
encodeHtml,
noopFalse,
inFocus,
delegateRunOnDestroy,
pInt,
isUnd
pInt
} from 'Common/Utils';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
@ -291,8 +286,8 @@ class ComposePopupView extends AbstractViewNext {
}
});
this.attachmentsInProcess.subscribe((value) => {
if (this.attachmentsInProcessError() && isArray(value) && value.length) {
this.attachmentsInProcess.subscribe(value => {
if (this.attachmentsInProcessError() && isNonEmptyArray(value)) {
this.attachmentsInProcessError(false);
}
});
@ -333,7 +328,12 @@ class ComposePopupView extends AbstractViewNext {
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = KeyState.Compose;
this.tryToClosePopup = _.debounce(this.tryToClosePopup.bind(this), Magics.Time200ms);
// debounce
var d, fn = this.tryToClosePopup.bind(this);
this.tryToClosePopup = ()=>{
d && clearTimeout(d);
d = setTimeout(fn, Magics.Time200ms);
};
this.emailsSource = this.emailsSource.bind(this);
this.autosaveFunction = this.autosaveFunction.bind(this);
@ -367,7 +367,7 @@ class ComposePopupView extends AbstractViewNext {
if (!this.emptyToError() && !this.attachmentsInErrorError() && !this.attachmentsInProcessError()) {
if (SettingsStore.replySameFolder()) {
if (
isArray(this.aDraftInfo) &&
Array.isArray(this.aDraftInfo) &&
3 === this.aDraftInfo.length &&
isNormal(this.aDraftInfo[2]) &&
this.aDraftInfo[2].length
@ -386,7 +386,7 @@ class ComposePopupView extends AbstractViewNext {
this.sendError(false);
this.sending(true);
if (isArray(this.aDraftInfo) && 3 === this.aDraftInfo.length) {
if (Array.isArray(this.aDraftInfo) && 3 === this.aDraftInfo.length) {
const flagsCache = getMessageFlagsFromCache(this.aDraftInfo[2], this.aDraftInfo[1]);
if (flagsCache) {
if ('forward' === this.aDraftInfo[0]) {
@ -531,12 +531,12 @@ class ComposePopupView extends AbstractViewNext {
}
autosaveStart() {
window.clearTimeout(this.iTimer);
this.iTimer = window.setTimeout(this.autosaveFunction, Magics.Time1m);
clearTimeout(this.iTimer);
this.iTimer = setTimeout(this.autosaveFunction, Magics.Time1m);
}
autosaveStop() {
window.clearTimeout(this.iTimer);
clearTimeout(this.iTimer);
}
emailsSource(oData, fResponse) {
@ -672,7 +672,7 @@ class ComposePopupView extends AbstractViewNext {
this.draftFolder(oData.Result.NewFolder);
this.draftUid(oData.Result.NewUid);
this.savedTime(window.Math.round(new window.Date().getTime() / 1000));
this.savedTime(Math.round(new Date().getTime() / 1000));
if (this.bFromDraft) {
setFolderHash(this.draftFolder(), '');
@ -907,9 +907,9 @@ class ComposePopupView extends AbstractViewNext {
oMessageOrArray = oMessageOrArray || null;
if (oMessageOrArray && isNormal(oMessageOrArray)) {
message =
isArray(oMessageOrArray) && 1 === oMessageOrArray.length
Array.isArray(oMessageOrArray) && 1 === oMessageOrArray.length
? oMessageOrArray[0]
: !isArray(oMessageOrArray)
: !Array.isArray(oMessageOrArray)
? oMessageOrArray
: null;
}
@ -1207,7 +1207,7 @@ class ComposePopupView extends AbstractViewNext {
onBuild() {
this.initUploader();
key('ctrl+q, command+q, ctrl+w, command+w', KeyState.Compose, noopFalse);
key('ctrl+q, command+q, ctrl+w, command+w', KeyState.Compose, ()=>false);
key('`', KeyState.Compose, () => {
if (this.oEditor && !this.oEditor.hasFocus() && !inFocus()) {
@ -1250,9 +1250,14 @@ class ComposePopupView extends AbstractViewNext {
});
Events.sub('window.resize.real', this.resizerTrigger);
Events.sub('window.resize.real', _.debounce(this.resizerTrigger, Magics.Time50ms));
var d, o = this;
Events.sub('window.resize.real', ()=>{
// debounce
d && clearTimeout(d);
d = setTimeout(o.resizerTrigger, Magics.Time50ms);
});
window.setInterval(() => {
setInterval(() => {
if (this.modalVisibility() && this.oEditor) {
this.oEditor.resize();
}
@ -1322,13 +1327,13 @@ class ComposePopupView extends AbstractViewNext {
}
if (item) {
item.progress(window.Math.floor((loaded / total) * 100));
item.progress(Math.floor((loaded / total) * 100));
}
})
.on('onSelect', (sId, oData) => {
this.dragAndDropOver(false);
const fileName = isUnd(oData.FileName) ? '' : oData.FileName.toString(),
const fileName = undefined === oData.FileName ? '' : oData.FileName.toString(),
size = isNormal(oData.Size) ? pInt(oData.Size) : null,
attachment = new ComposeAttachmentModel(sId, fileName, size);
@ -1394,7 +1399,7 @@ class ComposePopupView extends AbstractViewNext {
attachment.initByUploadJson(attachmentJson);
}
if (isUnd(uploadCache[id])) {
if (undefined === uploadCache[id]) {
delete uploadCache[id];
}
}

View file

@ -2,7 +2,7 @@ import $ from '$';
import ko from 'ko';
import key from 'key';
import { pString, log, isUnd, trim, defautOptionsAfterRender } from 'Common/Utils';
import { pString, log, trim, defautOptionsAfterRender } from 'Common/Utils';
import { Magics, KeyState } from 'Common/Enums';
import { i18n } from 'Common/Translator';
@ -102,7 +102,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
this.addOptionClass = (domOption, item) => {
this.defautOptionsAfterRender(domOption, item);
if (item && !isUnd(item.class) && domOption) {
if (item && undefined !== item.class && domOption) {
$(domOption).addClass(item.class);
}
};

View file

@ -22,8 +22,7 @@ import {
windowResizeCallback,
isNonEmptyArray,
fakeMd5,
pInt,
isUnd
pInt
} from 'Common/Utils';
import { CONTACTS_PER_PAGE } from 'Common/Consts';
@ -649,8 +648,8 @@ class ContactsPopupView extends AbstractViewNext {
}
onShow(bBackToCompose, sLastComposeFocusedField) {
this.bBackToCompose = isUnd(bBackToCompose) ? false : !!bBackToCompose;
this.sLastComposeFocusedField = isUnd(sLastComposeFocusedField) ? '' : sLastComposeFocusedField;
this.bBackToCompose = undefined === bBackToCompose ? false : !!bBackToCompose;
this.sLastComposeFocusedField = undefined === sLastComposeFocusedField ? '' : sLastComposeFocusedField;
routeOff();
this.reloadContactList(true);

View file

@ -1,9 +1,8 @@
import _ from '_';
import ko from 'ko';
import { SetSystemFoldersNotification, Magics } from 'Common/Enums';
import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { folderListOptionsBuilder, noop, defautOptionsAfterRender } from 'Common/Utils';
import { folderListOptionsBuilder, defautOptionsAfterRender } from 'Common/Utils';
import { initOnStartOrLangChange, i18n } from 'Common/Translator';
import FolderStore from 'Stores/User/Folder';
@ -56,6 +55,7 @@ class FolderSystemPopupView extends AbstractViewNext {
this.trashFolder = FolderStore.trashFolder;
this.archiveFolder = FolderStore.archiveFolder;
var d;
const fSetSystemFolders = () => {
Settings.settingsSet('SentFolder', FolderStore.sentFolder());
Settings.settingsSet('DraftFolder', FolderStore.draftFolder());
@ -63,17 +63,21 @@ class FolderSystemPopupView extends AbstractViewNext {
Settings.settingsSet('TrashFolder', FolderStore.trashFolder());
Settings.settingsSet('ArchiveFolder', FolderStore.archiveFolder());
},
fSaveSystemFolders = _.debounce(() => {
fSetSystemFolders();
Remote.saveSystemFolders(noop, {
SentFolder: FolderStore.sentFolder(),
DraftFolder: FolderStore.draftFolder(),
SpamFolder: FolderStore.spamFolder(),
TrashFolder: FolderStore.trashFolder(),
ArchiveFolder: FolderStore.archiveFolder(),
NullFolder: 'NullFolder'
});
}, Magics.Time1s),
fSaveSystemFolders = ()=>{
// debounce
d && clearTimeout(d);
d = setTimeout(()=>{
fSetSystemFolders();
Remote.saveSystemFolders(()=>{}, {
SentFolder: FolderStore.sentFolder(),
DraftFolder: FolderStore.draftFolder(),
SpamFolder: FolderStore.spamFolder(),
TrashFolder: FolderStore.trashFolder(),
ArchiveFolder: FolderStore.archiveFolder(),
NullFolder: 'NullFolder'
});
}, Magics.Time1s);
},
fCallback = () => {
fSetSystemFolders();
fSaveSystemFolders();

View file

@ -1,4 +1,3 @@
import _ from '_';
import key from 'key';
import { KeyState, Magics } from 'Common/Enums';
@ -17,32 +16,39 @@ class KeyboardShortcutsHelpPopupView extends AbstractViewNext {
}
onBuild(dom) {
var t;
key(
'tab, shift+tab, left, right',
KeyState.PopupKeyboardShortcutsHelp,
_.throttle((event, handler) => {
if (event && handler) {
const $tabs = dom.find('.nav.nav-tabs > li'),
isNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut);
(event, handler)=>{
// throttle
if (!t) {
t = setTimeout(()=>{
t = 0;
if (event && handler) {
const $tabs = dom.find('.nav.nav-tabs > li'),
isNext = handler && ('tab' === handler.shortcut || 'right' === handler.shortcut);
let index = $tabs.index($tabs.filter('.active'));
if (!isNext && 0 < index) {
index -= 1;
} else if (isNext && index < $tabs.length - 1) {
index += 1;
} else {
index = isNext ? 0 : $tabs.length - 1;
}
let index = $tabs.index($tabs.filter('.active'));
if (!isNext && 0 < index) {
index -= 1;
} else if (isNext && index < $tabs.length - 1) {
index += 1;
} else {
index = isNext ? 0 : $tabs.length - 1;
}
$tabs
.eq(index)
.find('a[data-toggle="tab"]')
.tab('show');
return false;
$tabs
.eq(index)
.find('a[data-toggle="tab"]')
.tab('show');
return false;
}
return true;
}, Magics.Time100ms);
}
return true;
}, Magics.Time100ms)
}
);
}
}

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import key from 'key';
@ -43,7 +42,12 @@ class PluginPopupView extends AbstractViewNext {
this.bDisabeCloseOnEsc = true;
this.sDefaultKeyScope = KeyState.All;
this.tryToClosePopup = _.debounce(this.tryToClosePopup.bind(this), Magics.Time200ms);
var d, fn = this.tryToClosePopup.bind(this);
this.tryToClosePopup = ()=>{
// debounce
d && clearTimeout(d);
d = setTimeout(fn, Magics.Time200ms);
};
}
@command((self) => self.hasConfiguration())

View file

@ -6,7 +6,7 @@ import AccountStore from 'Stores/User/Account';
import MessageStore from 'Stores/User/Message';
import { Capa, Magics, KeyState } from 'Common/Enums';
import { trim, isUnd } from 'Common/Utils';
import { trim } from 'Common/Utils';
import { settings } from 'Common/Links';
import * as Events from 'Common/Events';
@ -51,7 +51,7 @@ class AbstractSystemDropDownUserView extends AbstractViewNext {
}
accountClick(account, event) {
if (account && event && !isUnd(event.which) && 1 === event.which) {
if (account && event && undefined !== event.which && 1 === event.which) {
AccountStore.accounts.loading(true);
setTimeout(() => AccountStore.accounts.loading(false), Magics.Time1s);
}

View file

@ -3,7 +3,7 @@ import $ from '$';
import ko from 'ko';
import key from 'key';
import { trim, isNormal, isArray, windowResize } from 'Common/Utils';
import { trim, isNormal, windowResize } from 'Common/Utils';
import { Capa, Focused, Layout, KeyState, EventKeyCode, Magics } from 'Common/Enums';
import { $htmlCL, leftPanelDisabled, moveAction } from 'Common/Globals';
import { mailBox, settings } from 'Common/Links';
@ -245,7 +245,7 @@ class FolderListMailBoxUserView extends AbstractViewNext {
copy = $htmlCL.contains('rl-ctrl-key-pressed'),
uids = ui.helper.data('rl-uids');
if (fromFolderFullNameRaw && isNormal(fromFolderFullNameRaw) && isArray(uids)) {
if (fromFolderFullNameRaw && isNormal(fromFolderFullNameRaw) && Array.isArray(uids)) {
getApp().moveMessagesToFolder(fromFolderFullNameRaw, uids, toFolder.fullNameRaw, copy);
}
}

View file

@ -1,5 +1,4 @@
import window from 'window';
import _ from '_';
import $ from '$';
import ko from 'ko';
import key from 'key';
@ -22,7 +21,7 @@ import { UNUSED_OPTION_VALUE } from 'Common/Consts';
import { bMobileDevice, popupVisibility, leftPanelDisabled, moveAction } from 'Common/Globals';
import { noop, noopFalse, computedPagenatorHelper, draggablePlace, friendlySize, isUnd } from 'Common/Utils';
import { computedPagenatorHelper, draggablePlace, friendlySize } from 'Common/Utils';
import { mailBox, append } from 'Common/Links';
import { Selector } from 'Common/Selector';
@ -401,7 +400,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
}
window.clearTimeout(this.iGoToUpUpOrDownDownTimeout);
this.iGoToUpUpOrDownDownTimeout = window.setTimeout(() => {
this.iGoToUpUpOrDownDownTimeout = setTimeout(() => {
let prev = null,
next = null,
temp = null,
@ -516,7 +515,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
el.data('rl-folder', FolderStore.currentFolderFullNameRaw());
updateUidsInfo();
_.defer(updateUidsInfo);
setTimeout(updateUidsInfo,1);
return el;
}
@ -569,7 +568,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
clearMessageFlagsFromCacheByFolder(sFolderFullNameRaw);
}
Remote.messageSetSeenToAll(noop, sFolderFullNameRaw, true, sThreadUid ? uids : null);
Remote.messageSetSeenToAll(()=>{}, sFolderFullNameRaw, true, sThreadUid ? uids : null);
break;
case MessageSetAction.UnsetSeen:
folder = getFolderFromCacheList(sFolderFullNameRaw);
@ -595,7 +594,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
clearMessageFlagsFromCacheByFolder(sFolderFullNameRaw);
}
Remote.messageSetSeenToAll(noop, sFolderFullNameRaw, false, sThreadUid ? uids : null);
Remote.messageSetSeenToAll(()=>{}, sFolderFullNameRaw, false, sThreadUid ? uids : null);
break;
// no default
}
@ -668,7 +667,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
flagMessagesFast(bFlag) {
const checked = this.messageListCheckedOrSelected();
if (checked.length) {
if (isUnd(bFlag)) {
if (undefined === bFlag) {
const flagged = checked.filter(message => message.flagged());
this.setAction(
checked[0].folderFullNameRaw,
@ -688,7 +687,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
seenMessagesFast(seen) {
const checked = this.messageListCheckedOrSelected();
if (checked.length) {
if (isUnd(seen)) {
if (undefined === seen) {
const unseen = checked.filter(message => message.unseen());
this.setAction(
checked[0].folderFullNameRaw,
@ -932,8 +931,8 @@ class MessageListMailBoxUserView extends AbstractViewNext {
return false;
});
key('ctrl+left, command+left', KeyState.MessageView, noopFalse);
key('ctrl+right, command+right', KeyState.MessageView, noopFalse);
key('ctrl+left, command+left', KeyState.MessageView, ()=>false);
key('ctrl+right, command+right', KeyState.MessageView, ()=>false);
}
prefetchNextTick() {

View file

@ -1,4 +1,3 @@
import _ from '_';
import $ from '$';
import ko from 'ko';
import key from 'key';
@ -22,7 +21,6 @@ import { $htmlCL, leftPanelDisabled, keyScopeReal, useKeyboardShortcuts, moveAct
import {
isNonEmptyArray,
trim,
noop,
windowResize,
windowResizeCallback,
inFocus,
@ -542,13 +540,20 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
this.showFullInfo.subscribe(fCheckHeaderHeight);
this.message.subscribe(fCheckHeaderHeight);
var t;
Events.sub(
'window.resize',
_.throttle(() => {
setTimeout(fCheckHeaderHeight, 1);
setTimeout(fCheckHeaderHeight, Magics.Time200ms);
setTimeout(fCheckHeaderHeight, Magics.Time500ms);
}, Magics.Time50ms)
()=>{
// throttle
if (!t) {
t = setTimeout(()=>{
setTimeout(fCheckHeaderHeight, 1);
setTimeout(fCheckHeaderHeight, Magics.Time200ms);
setTimeout(fCheckHeaderHeight, Magics.Time500ms);
t = 0;
}, Magics.Time50ms);
}
}
);
this.showFullInfo.subscribe((value) => {
@ -932,7 +937,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
readReceipt(oMessage) {
if (oMessage && oMessage.readReceipt()) {
Remote.sendReadReceiptMessage(
noop,
()=>{},
oMessage.folderFullNameRaw,
oMessage.uid,
oMessage.readReceipt(),