Underscore.js _.each() to native Array.forEach() (optional with Object.entries/values)

This commit is contained in:
djmaze 2020-07-22 14:49:18 +02:00
parent 178e5f6ef7
commit a5d41edb24
25 changed files with 72 additions and 79 deletions

View file

@ -1,4 +1,3 @@
import _ from '_';
import ko from 'ko';
import { trim } from 'Common/Utils';
@ -56,7 +55,7 @@ class AdvancedSearchPopupView extends AbstractViewNext {
parseSearchStringValue(search) {
const parts = (search || '').split(/[\s]+/g);
_.each(parts, (part) => {
parts.forEach(part => {
switch (part) {
case 'has:attachment':
this.hasAttachment(true);

View file

@ -588,7 +588,7 @@ class ComposePopupView extends AbstractViewNext {
}
};
_.each(identities, (item, index) => {
identities.forEach((item, index) => {
identitiesCache[item.email()] = [item, index];
});
@ -600,13 +600,13 @@ class ComposePopupView extends AbstractViewNext {
case ComposeType.ReplyAll:
case ComposeType.Forward:
case ComposeType.ForwardAsAttachment:
_.each(_.union(message.to, message.cc, message.bcc), fEachHelper);
_.union(message.to, message.cc, message.bcc).forEach(fEachHelper);
if (!resultIdentity) {
_.each(message.deliveredTo, fEachHelper);
message.deliveredTo.forEach(fEachHelper);
}
break;
case ComposeType.Draft:
_.each(_.union(message.from, message.replyTo), fEachHelper);
_.union(message.from, message.replyTo).forEach(fEachHelper);
break;
// no default
}
@ -775,7 +775,7 @@ class ComposePopupView extends AbstractViewNext {
}
if (moments && 0 < moments.length) {
_.each(moments, (data) => {
moments.forEach(data => {
signature = signature.replace(data[0], momentorFormat(0, data[1]));
});
}
@ -1112,7 +1112,7 @@ class ComposePopupView extends AbstractViewNext {
this.setFocusInPopup();
});
} else if (isNonEmptyArray(oMessageOrArray)) {
_.each(oMessageOrArray, (item) => {
oMessageOrArray.forEach(item => {
this.addMessageAsAttachment(item);
});
@ -1151,7 +1151,7 @@ class ComposePopupView extends AbstractViewNext {
onMessageUploadAttachments(sResult, oData) {
if (StorageResultType.Success === sResult && oData && oData.Result) {
if (!this.viewModelVisibility()) {
_.each(oData.Result, (id, tempName) => {
oData.Result.forEach((id, tempName) => {
const attachment = this.getAttachmentById(id);
if (attachment) {
attachment.tempName(tempName);
@ -1411,7 +1411,7 @@ class ComposePopupView extends AbstractViewNext {
*/
prepearAttachmentsForSendOrSave() {
const result = {};
_.each(this.attachmentsInReady(), (item) => {
this.attachmentsInReady().forEach(item => {
if (item && '' !== item.tempName() && item.enabled()) {
result[item.tempName()] = [item.fileName(), item.isInline ? '1' : '0', item.CID, item.contentLocation];
}
@ -1474,7 +1474,7 @@ class ComposePopupView extends AbstractViewNext {
this.addMessageAsAttachment(message);
} else {
const attachments = message.attachments();
_.each(isNonEmptyArray(attachments) ? attachments : [], (item) => {
(isNonEmptyArray(attachments) ? attachments : []).forEach(item => {
let add = false;
switch (type) {
case ComposeType.Reply:
@ -1524,7 +1524,7 @@ class ComposePopupView extends AbstractViewNext {
}
setMessageAttachmentFailedDownloadText() {
_.each(this.attachments(), (attachment) => {
this.attachments().forEach(attachment => {
if (attachment && attachment.fromMessage) {
attachment
.waiting(false)

View file

@ -157,7 +157,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
} else if (this.encryptKeys()) {
aPublicKeys = [];
_.each(this.encryptKeys(), (oKey) => {
this.encryptKeys().forEach(oKey => {
if (oKey && oKey.key) {
aPublicKeys = aPublicKeys.concat(_.compact(_.flatten(oKey.key.getNativeKeys())));
} else if (oKey && oKey.email) {
@ -279,7 +279,7 @@ class ComposeOpenPgpPopupView extends AbstractViewNext {
@command()
updateCommand() {
_.each(this.encryptKeys(), (oKey) => {
this.encryptKeys().forEach(oKey => {
oKey.removable(!this.sign() || !this.signKey() || this.signKey().key.id !== oKey.key.id);
});
}

View file

@ -301,7 +301,7 @@ class ContactsPopupView extends AbstractViewNext {
const requestUid = fakeMd5(),
properties = [];
_.each(this.viewProperties(), (oItem) => {
this.viewProperties().forEach(oItem => {
if (oItem.type() && oItem.type() !== ContactPropertyType.FullName && '' !== trim(oItem.value())) {
properties.push([oItem.type(), oItem.value(), oItem.typeStr()]);
}
@ -456,7 +456,7 @@ class ContactsPopupView extends AbstractViewNext {
count = this.contacts().length;
if (0 < contacts.length) {
_.each(contacts, (contact) => {
contacts.forEach(contact => {
if (currentContact && currentContact.idContact === contact.idContact) {
currentContact = null;
this.currentContact(null);
@ -471,7 +471,7 @@ class ContactsPopupView extends AbstractViewNext {
}
_.delay(() => {
_.each(contacts, (contact) => {
contacts.forEach(contact => {
koContacts.remove(contact);
delegateRunOnDestroy(contact);
});
@ -523,7 +523,7 @@ class ContactsPopupView extends AbstractViewNext {
if (contact) {
id = contact.idContact;
if (isNonEmptyArray(contact.properties)) {
_.each(contact.properties, (property) => {
contact.properties.forEach(property => {
if (property && property[0]) {
if (ContactPropertyType.LastName === property[0]) {
lastName = property[1];

View file

@ -42,7 +42,7 @@ class LanguagesPopupView extends AbstractViewNext {
setLanguageSelection() {
const currentLang = this.fLang ? ko.unwrap(this.fLang) : '';
_.each(this.languages(), (item) => {
this.languages().forEach(item => {
item.selected(item.key === currentLang);
});
}

View file

@ -51,7 +51,7 @@ class PluginPopupView extends AbstractViewNext {
const list = {};
list.Name = this.name();
_.each(this.configures(), (oItem) => {
this.configures().forEach(oItem => {
let value = oItem.value();
if (false === value || true === value) {
value = value ? '1' : '0';

View file

@ -146,7 +146,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
read: () => 0 < MessageStore.messageListChecked().length,
write: (value) => {
value = !!value;
_.each(MessageStore.messageList(), (message) => {
MessageStore.messageList().forEach(message => {
message.checked(value);
});
}
@ -551,7 +551,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
case MessageSetAction.SetSeen:
folder = getFolderFromCacheList(sFolderFullNameRaw);
if (folder) {
_.each(MessageStore.messageList(), (message) => {
MessageStore.messageList().forEach(message => {
if (message.unseen()) {
cnt += 1;
}
@ -577,7 +577,7 @@ class MessageListMailBoxUserView extends AbstractViewNext {
case MessageSetAction.UnsetSeen:
folder = getFolderFromCacheList(sFolderFullNameRaw);
if (folder) {
_.each(MessageStore.messageList(), (message) => {
MessageStore.messageList().forEach(message => {
if (!message.unseen()) {
cnt += 1;
}

View file

@ -142,7 +142,7 @@ class MessageViewMailBoxUserView extends AbstractViewNext {
this.showAttachmnetControls.subscribe((v) => {
if (this.message()) {
_.each(this.message().attachments(), (item) => {
this.message().attachments().forEach(item => {
if (item) {
item.checked(!!v);
}