mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-03-03 18:28:48 +08:00
Underscore.js _.find() to native Array.find()
This commit is contained in:
parent
2404f6466d
commit
9c0072d626
19 changed files with 55 additions and 79 deletions
|
@ -552,9 +552,9 @@ class AppUser extends AbstractApp {
|
|||
// aAcounts = AccountStore.accounts()
|
||||
// ;
|
||||
//
|
||||
// _.each(oData.Result['Counts'], (oItem) => {
|
||||
// oData.Result['Counts'].find(oItem => {
|
||||
//
|
||||
// var oAccount = _.find(aAcounts, (oAccount) => {
|
||||
// var oAccount = aAcounts.find(oAccount => {
|
||||
// return oAccount && oItem[0] === oAccount.email && sEmail !== oAccount.email;
|
||||
// });
|
||||
//
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import _ from '_';
|
||||
import { MessageSetAction } from 'Common/Enums';
|
||||
import { trim, pInt, isArray } from 'Common/Utils';
|
||||
|
||||
|
@ -223,7 +222,7 @@ export function initMessageFlagsFromCache(message) {
|
|||
}
|
||||
|
||||
if (0 < message.threads().length) {
|
||||
const unseenSubUid = _.find(message.threads(), (sSubUid) => {
|
||||
const unseenSubUid = message.threads().find(sSubUid => {
|
||||
if (uid !== sSubUid) {
|
||||
const subFlags = getMessageFlagsFromCache(message.folderFullNameRaw, sSubUid);
|
||||
return subFlags && 0 < subFlags.length && !!subFlags[0];
|
||||
|
@ -231,7 +230,7 @@ export function initMessageFlagsFromCache(message) {
|
|||
return false;
|
||||
});
|
||||
|
||||
const flaggedSubUid = _.find(message.threads(), (sSubUid) => {
|
||||
const flaggedSubUid = message.threads().find(sSubUid => {
|
||||
if (uid !== sSubUid) {
|
||||
const subFlags = getMessageFlagsFromCache(message.folderFullNameRaw, sSubUid);
|
||||
return subFlags && 0 < subFlags.length && !!subFlags[1];
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import window from 'window';
|
||||
import _ from '_';
|
||||
import $ from '$';
|
||||
import key from 'key';
|
||||
import ko from 'ko';
|
||||
|
@ -152,15 +151,7 @@ export const htmlEditorLangsMap = {
|
|||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
let bAllowPdfPreview = !bMobileDevice;
|
||||
|
||||
if (bAllowPdfPreview && window.navigator && window.navigator.mimeTypes) {
|
||||
bAllowPdfPreview = !!_.find(window.navigator.mimeTypes, (type) => type && 'application/pdf' === type.type);
|
||||
|
||||
if (!bAllowPdfPreview) {
|
||||
bAllowPdfPreview = 'undefined' !== typeof window.navigator.mimeTypes['application/pdf'];
|
||||
}
|
||||
}
|
||||
let bAllowPdfPreview = !bMobileDevice && undefined !== window.navigator.mimeTypes['application/pdf'];
|
||||
|
||||
export { bAllowPdfPreview };
|
||||
|
||||
|
|
|
@ -180,7 +180,7 @@ class Selector {
|
|||
} else if (0 < aItems.length) {
|
||||
if (null !== isNextFocused) {
|
||||
getNext = false;
|
||||
isNextFocused = _.find(aCache, (sUid) => {
|
||||
isNextFocused = aCache.find(sUid => {
|
||||
if (getNext && uids.includes(sUid)) {
|
||||
return sUid;
|
||||
} else if (isNextFocused === sUid) {
|
||||
|
@ -190,7 +190,7 @@ class Selector {
|
|||
});
|
||||
|
||||
if (isNextFocused) {
|
||||
temp = _.find(aItems, (oItem) => isNextFocused === this.getItemUid(oItem));
|
||||
temp = aItems.find(oItem => isNextFocused === this.getItemUid(oItem));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1018,7 +1018,7 @@ export function selectElement(element) {
|
|||
}
|
||||
|
||||
export const detectDropdownVisibility = _.debounce(() => {
|
||||
dropdownVisibility(!!_.find(GlobalsData.aBootstrapDropdowns, (item) => item.hasClass('open')));
|
||||
dropdownVisibility(!!GlobalsData.aBootstrapDropdowns.find(item => item.hasClass('open')));
|
||||
}, 50);
|
||||
|
||||
/**
|
||||
|
|
|
@ -146,7 +146,7 @@ class FilterModel extends AbstractModel {
|
|||
}
|
||||
|
||||
if (0 < this.conditions().length) {
|
||||
if (_.find(this.conditions(), (cond) => cond && !cond.verify())) {
|
||||
if (this.conditions().find(cond => cond && !cond.verify())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import _ from '_';
|
||||
import ko from 'ko';
|
||||
|
||||
import { FolderType } from 'Common/Enums';
|
||||
|
@ -64,9 +63,8 @@ class FolderModel extends AbstractModel {
|
|||
|
||||
this.hasSubScribedSubfolders = ko.computed(
|
||||
() =>
|
||||
!!_.find(
|
||||
this.subFolders(),
|
||||
(oFolder) => (oFolder.subScribed() || oFolder.hasSubScribedSubfolders()) && !oFolder.isSystemFolder()
|
||||
!!this.subFolders().find(
|
||||
oFolder => (oFolder.subScribed() || oFolder.hasSubScribedSubfolders()) && !oFolder.isSystemFolder()
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -230,9 +228,8 @@ class FolderModel extends AbstractModel {
|
|||
|
||||
this.hasSubScribedUnreadMessagesSubfolders = ko.computed(
|
||||
() =>
|
||||
!!_.find(
|
||||
this.subFolders(),
|
||||
(folder) => folder.hasUnreadMessages() || folder.hasSubScribedUnreadMessagesSubfolders()
|
||||
!!this.subFolders().find(
|
||||
folder => folder.hasUnreadMessages() || folder.hasSubScribedUnreadMessagesSubfolders()
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -493,7 +493,7 @@ class MessageModel extends AbstractModel {
|
|||
* @returns {boolean}
|
||||
*/
|
||||
hasVisibleAttachments() {
|
||||
return !!_.find(this.attachments(), (item) => !item.isLinked);
|
||||
return !!this.attachments().find(item => !item.isLinked);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -506,7 +506,7 @@ class MessageModel extends AbstractModel {
|
|||
|
||||
if (isNonEmptyArray(attachments)) {
|
||||
cid = cid.replace(/^<+/, '').replace(/>+$/, '');
|
||||
result = _.find(attachments, (item) => cid === item.cidWithOutTags);
|
||||
result = attachments.find(item => cid === item.cidWithOutTags);
|
||||
}
|
||||
|
||||
return result || null;
|
||||
|
@ -521,7 +521,7 @@ class MessageModel extends AbstractModel {
|
|||
const attachments = this.attachments();
|
||||
|
||||
if (isNonEmptyArray(attachments)) {
|
||||
result = _.find(attachments, (item) => contentLocation === item.contentLocation);
|
||||
result = attachments.find(item => contentLocation === item.contentLocation);
|
||||
}
|
||||
|
||||
return result || null;
|
||||
|
|
|
@ -39,17 +39,15 @@ class AbstractSettingsScreen extends AbstractScreen {
|
|||
viewModelPlace = null,
|
||||
viewModelDom = null;
|
||||
|
||||
RoutedSettingsViewModel = _.find(
|
||||
VIEW_MODELS.settings,
|
||||
(SettingsViewModel) =>
|
||||
RoutedSettingsViewModel = VIEW_MODELS.settings.find(
|
||||
SettingsViewModel =>
|
||||
SettingsViewModel && SettingsViewModel.__rlSettingsData && subName === SettingsViewModel.__rlSettingsData.Route
|
||||
);
|
||||
|
||||
if (RoutedSettingsViewModel) {
|
||||
if (
|
||||
_.find(
|
||||
VIEW_MODELS['settings-removed'],
|
||||
(DisabledSettingsViewModel) =>
|
||||
VIEW_MODELS['settings-removed'].find(
|
||||
DisabledSettingsViewModel =>
|
||||
DisabledSettingsViewModel && DisabledSettingsViewModel === RoutedSettingsViewModel
|
||||
)
|
||||
) {
|
||||
|
@ -58,9 +56,8 @@ class AbstractSettingsScreen extends AbstractScreen {
|
|||
|
||||
if (
|
||||
RoutedSettingsViewModel &&
|
||||
_.find(
|
||||
VIEW_MODELS['settings-disabled'],
|
||||
(DisabledSettingsViewModel) =>
|
||||
VIEW_MODELS['settings-disabled'].find(
|
||||
DisabledSettingsViewModel =>
|
||||
DisabledSettingsViewModel && DisabledSettingsViewModel === RoutedSettingsViewModel
|
||||
)
|
||||
) {
|
||||
|
@ -155,18 +152,16 @@ class AbstractSettingsScreen extends AbstractScreen {
|
|||
if (
|
||||
SettingsViewModel &&
|
||||
SettingsViewModel.__rlSettingsData &&
|
||||
!_.find(
|
||||
VIEW_MODELS['settings-removed'],
|
||||
(RemoveSettingsViewModel) => RemoveSettingsViewModel && RemoveSettingsViewModel === SettingsViewModel
|
||||
!VIEW_MODELS['settings-removed'].find(
|
||||
RemoveSettingsViewModel => RemoveSettingsViewModel && RemoveSettingsViewModel === SettingsViewModel
|
||||
)
|
||||
) {
|
||||
this.menu.push({
|
||||
route: SettingsViewModel.__rlSettingsData.Route,
|
||||
label: SettingsViewModel.__rlSettingsData.Label,
|
||||
selected: ko.observable(false),
|
||||
disabled: !!_.find(
|
||||
VIEW_MODELS['settings-disabled'],
|
||||
(DisabledSettingsViewModel) => DisabledSettingsViewModel && DisabledSettingsViewModel === SettingsViewModel
|
||||
disabled: !!VIEW_MODELS['settings-disabled'].find(
|
||||
DisabledSettingsViewModel => DisabledSettingsViewModel && DisabledSettingsViewModel === SettingsViewModel
|
||||
)
|
||||
});
|
||||
}
|
||||
|
@ -176,9 +171,8 @@ class AbstractSettingsScreen extends AbstractScreen {
|
|||
}
|
||||
|
||||
routes() {
|
||||
const DefaultViewModel = _.find(
|
||||
VIEW_MODELS.settings,
|
||||
(SettingsViewModel) =>
|
||||
const DefaultViewModel = VIEW_MODELS.settings.find(
|
||||
SettingsViewModel =>
|
||||
SettingsViewModel && SettingsViewModel.__rlSettingsData && SettingsViewModel.__rlSettingsData.IsDefault
|
||||
),
|
||||
defaultRoute =
|
||||
|
|
|
@ -56,7 +56,7 @@ class GeneralUserSettings {
|
|||
|
||||
this.identityMain = ko.computed(() => {
|
||||
const list = this.identities();
|
||||
return isArray(list) ? _.find(list, (item) => item && '' === item.id()) : null;
|
||||
return isArray(list) ? list.find(item => item && '' === item.id()) : null;
|
||||
});
|
||||
|
||||
this.identityMainDesc = ko.computed(() => {
|
||||
|
|
|
@ -50,7 +50,7 @@ class OpenPgpUserSettings {
|
|||
this.openPgpKeyForDeletion(null);
|
||||
|
||||
if (openPgpKeyToRemove && PgpStore.openpgpKeyring) {
|
||||
const findedItem = _.find(PgpStore.openpgpkeys(), (key) => openPgpKeyToRemove === key);
|
||||
const findedItem = PgpStore.openpgpkeys().find(key => openPgpKeyToRemove === key);
|
||||
if (findedItem) {
|
||||
PgpStore.openpgpkeys.remove(findedItem);
|
||||
delegateRunOnDestroy(findedItem);
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
import _ from '_';
|
||||
import { CookieDriver } from 'Common/ClientStorageDriver/Cookie';
|
||||
import { LocalStorageDriver } from 'Common/ClientStorageDriver/LocalStorage';
|
||||
|
||||
const SupportedStorageDriver = _.find(
|
||||
[LocalStorageDriver, CookieDriver],
|
||||
(StorageDriver) => StorageDriver && StorageDriver.supported()
|
||||
const SupportedStorageDriver = [LocalStorageDriver, CookieDriver].find(
|
||||
StorageDriver => StorageDriver && StorageDriver.supported()
|
||||
);
|
||||
|
||||
const driver = SupportedStorageDriver ? new SupportedStorageDriver() : null;
|
||||
|
|
|
@ -47,7 +47,7 @@ class FolderUserStore {
|
|||
);
|
||||
|
||||
this.foldersListWithSingleInboxRootFolder = ko.computed(
|
||||
() => !_.find(this.folderList(), (folder) => folder && !folder.isSystemFolder() && folder.visible())
|
||||
() => !this.folderList().find(folder => folder && !folder.isSystemFolder() && folder.visible())
|
||||
);
|
||||
|
||||
this.currentFolderFullNameRaw = ko.computed(() => (this.currentFolder() ? this.currentFolder().fullNameRaw : ''));
|
||||
|
@ -193,7 +193,7 @@ class FolderUserStore {
|
|||
return 0;
|
||||
});
|
||||
|
||||
_.find(timeouts, (aItem) => {
|
||||
timeouts.find(aItem => {
|
||||
const folder = getFolderFromCacheList(aItem[1]);
|
||||
if (folder) {
|
||||
folder.interval = utc;
|
||||
|
|
|
@ -380,9 +380,9 @@ class MessageUserStore {
|
|||
if (
|
||||
messageList &&
|
||||
0 < messageList.length &&
|
||||
!!_.find(messageList, (item) => !!(item && item.deleted() && item.uid === this.messageListThreadUid()))
|
||||
!!messageList.find(item => !!(item && item.deleted() && item.uid === this.messageListThreadUid()))
|
||||
) {
|
||||
const message = _.find(messageList, (item) => item && !item.deleted());
|
||||
const message = messageList.find(item => item && !item.deleted());
|
||||
if (message && this.messageListThreadUid() !== pString(message.uid)) {
|
||||
this.messageListThreadUid(pString(message.uid));
|
||||
|
||||
|
@ -633,9 +633,8 @@ class MessageUserStore {
|
|||
this.selectorMessageFocused(null);
|
||||
}
|
||||
} else if (!selectedMessage && message) {
|
||||
selectedMessage = _.find(
|
||||
this.messageList(),
|
||||
(subMessage) =>
|
||||
selectedMessage = this.messageList().find(
|
||||
subMessage =>
|
||||
subMessage &&
|
||||
subMessage.folderFullNameRaw === message.folderFullNameRaw &&
|
||||
subMessage.uid === message.uid
|
||||
|
|
|
@ -30,7 +30,7 @@ class PgpUserStore {
|
|||
}
|
||||
|
||||
findKeyByHex(keys, hash) {
|
||||
return _.find(keys, (item) => hash && item && (hash === item.id || item.ids.includes(hash)));
|
||||
return keys.find(item => hash && item && (hash === item.id || item.ids.includes(hash)));
|
||||
}
|
||||
|
||||
findPublicKeyByHex(hash) {
|
||||
|
@ -108,7 +108,7 @@ class PgpUserStore {
|
|||
* @returns {?}
|
||||
*/
|
||||
findPublicKeyByEmailNotNative(email) {
|
||||
return _.find(this.openpgpkeysPublic(), (item) => item && item.emails.includes(email)) || null;
|
||||
return this.openpgpkeysPublic().find(item => item && item.emails.includes(email)) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,7 +116,7 @@ class PgpUserStore {
|
|||
* @returns {?}
|
||||
*/
|
||||
findPrivateKeyByEmailNotNative(email) {
|
||||
return _.find(this.openpgpkeysPrivate(), (item) => item && item.emails.includes(email)) || null;
|
||||
return this.openpgpkeysPrivate().find(item => item && item.emails.includes(email)) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -142,7 +142,7 @@ class PgpUserStore {
|
|||
*/
|
||||
findPrivateKeyByEmail(email, password) {
|
||||
let privateKey = null;
|
||||
const key = _.find(this.openpgpkeysPrivate(), (item) => item && item.emails.includes(email));
|
||||
const key = this.openpgpkeysPrivate().find(item => item && item.emails.includes(email));
|
||||
|
||||
if (key) {
|
||||
try {
|
||||
|
@ -217,7 +217,7 @@ class PgpUserStore {
|
|||
if (publicKeys && 0 < publicKeys.length) {
|
||||
try {
|
||||
const result = message.verify(publicKeys),
|
||||
valid = _.find(_.isArray(result) ? result : [], (item) => item && item.valid && item.keyid);
|
||||
valid = (_.isArray(result) ? result : []).find(item => item && item.valid && item.keyid);
|
||||
|
||||
if (valid && valid.keyid && valid.keyid && valid.keyid.toHex) {
|
||||
fCallback(this.findPublicKeyByHex(valid.keyid.toHex()));
|
||||
|
|
|
@ -1263,12 +1263,12 @@ class ComposePopupView extends AbstractViewNext {
|
|||
* @returns {?Object}
|
||||
*/
|
||||
getAttachmentById(id) {
|
||||
return _.find(this.attachments(), (item) => item && id === item.id);
|
||||
return this.attachments().find(item => item && id === item.id);
|
||||
}
|
||||
|
||||
cancelAttachmentHelper(id, oJua) {
|
||||
return () => {
|
||||
const attachment = _.find(this.attachments(), (item) => item && item.id === id);
|
||||
const attachment = this.attachments().find(item => item && item.id === id);
|
||||
if (attachment) {
|
||||
this.attachments.remove(attachment);
|
||||
delegateRunOnDestroy(attachment);
|
||||
|
@ -1516,7 +1516,7 @@ class ComposePopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
removeLinkedAttachments() {
|
||||
const arrachment = _.find(this.attachments(), (item) => item && item.isLinked);
|
||||
const arrachment = this.attachments().find(item => item && item.isLinked);
|
||||
if (arrachment) {
|
||||
this.attachments.remove(arrachment);
|
||||
delegateRunOnDestroy(arrachment);
|
||||
|
|
|
@ -244,7 +244,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
@command()
|
||||
selectCommand() {
|
||||
const keyId = this.selectedPrivateKey(),
|
||||
option = keyId ? _.find(this.privateKeysOptions(), (item) => item && keyId === item.id) : null;
|
||||
option = keyId ? this.privateKeysOptions().find(item => item && keyId === item.id) : null;
|
||||
|
||||
if (option) {
|
||||
this.signKey({
|
||||
|
@ -261,7 +261,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
|
|||
addCommand() {
|
||||
const keyId = this.selectedPublicKey(),
|
||||
keys = this.encryptKeys(),
|
||||
option = keyId ? _.find(this.publicKeysOptions(), (item) => item && keyId === item.id) : null;
|
||||
option = keyId ? this.publicKeysOptions().find(item => item && keyId === item.id) : null;
|
||||
|
||||
if (option) {
|
||||
keys.push({
|
||||
|
|
|
@ -119,7 +119,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
emails = this.viewPropertiesEmails(),
|
||||
fFilter = (property) => '' !== trim(property.value());
|
||||
|
||||
return !!(_.find(names, fFilter) || _.find(emails, fFilter));
|
||||
return !!(names.find(fFilter) || emails.find(fFilter));
|
||||
});
|
||||
|
||||
this.viewPropertiesPhones = ko.computed(() =>
|
||||
|
@ -381,7 +381,7 @@ class ContactsPopupView extends AbstractViewNext {
|
|||
}
|
||||
|
||||
addNewOrFocusProperty(type, typeStr) {
|
||||
const item = _.find(this.viewProperties(), (prop) => type === prop.type());
|
||||
const item = this.viewProperties().find(prop => type === prop.type());
|
||||
if (item) {
|
||||
item.focused(true);
|
||||
} else {
|
||||
|
|
|
@ -255,9 +255,8 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
});
|
||||
|
||||
Events.sub('mailbox.message.show', (sFolder, sUid) => {
|
||||
const message = _.find(
|
||||
this.messageList(),
|
||||
(item) => item && sFolder === item.folderFullNameRaw && sUid === item.uid
|
||||
const message = this.messageList().find(
|
||||
item => item && sFolder === item.folderFullNameRaw && sUid === item.uid
|
||||
);
|
||||
|
||||
if ('INBOX' === sFolder) {
|
||||
|
@ -411,7 +410,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
temp = null,
|
||||
current = null;
|
||||
|
||||
_.find(this.messageListPagenator(), (item) => {
|
||||
this.messageListPagenator().find(item => {
|
||||
if (item) {
|
||||
if (current) {
|
||||
next = item;
|
||||
|
@ -942,9 +941,8 @@ class MessageListMailBoxUserView extends AbstractViewNext {
|
|||
|
||||
prefetchNextTick() {
|
||||
if (ifvisible && !this.bPrefetch && !ifvisible.now() && this.viewModelVisibility()) {
|
||||
const message = _.find(
|
||||
this.messageList(),
|
||||
(item) => item && !hasRequestedMessage(item.folderFullNameRaw, item.uid)
|
||||
const message = this.messageList().find(
|
||||
item => item && !hasRequestedMessage(item.folderFullNameRaw, item.uid)
|
||||
);
|
||||
if (message) {
|
||||
this.bPrefetch = true;
|
||||
|
|
Loading…
Reference in a new issue