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

This commit is contained in:
djmaze 2020-07-22 20:09:31 +02:00
parent 032fa8c736
commit a82575a830
27 changed files with 68 additions and 78 deletions

View file

@ -17,7 +17,7 @@ class AccountUserStore {
}
computers() {
this.accountsEmails = ko.computed(() => _.compact(_.map(this.accounts(), (item) => (item ? item.email : null))));
this.accountsEmails = ko.computed(() => _.compact(this.accounts().map(item => (item ? item.email : null))));
this.accountsUnreadCount = ko.computed(() => 0);
// this.accountsUnreadCount = ko.computed(() => {

View file

@ -95,7 +95,7 @@ class FolderUserStore {
});
this.folderListSystem = ko.computed(() =>
_.compact(_.map(this.folderListSystemNames(), (name) => getFolderFromCacheList(name)))
_.compact(this.folderListSystemNames().map(name => getFolderFromCacheList(name)))
);
this.folderMenuForMove = ko.computed(() =>

View file

@ -6,7 +6,7 @@ class IdentityUserStore {
this.identities = ko.observableArray([]);
this.identities.loading = ko.observable(false).extend({ throttle: 100 });
this.identitiesIDS = ko.computed(() => _.compact(_.map(this.identities(), (item) => (item ? item.id : null))));
this.identitiesIDS = ko.computed(() => _.compact(this.identities().map(item => (item ? item.id : null))));
}
}

View file

@ -294,7 +294,7 @@ class MessageUserStore {
* @param {boolean=} copy = false
*/
removeMessagesFromList(fromFolderFullNameRaw, uidForRemove, toFolderFullNameRaw = '', copy = false) {
uidForRemove = _.map(uidForRemove, (mValue) => pInt(mValue));
uidForRemove = uidForRemove.map(mValue => pInt(mValue));
let unseenCount = 0,
messageList = this.messageList(),
@ -709,7 +709,7 @@ class MessageUserStore {
* @returns {string}
*/
calculateMessageListHash(list) {
return _.map(list, (message) => '' + message.hash + '_' + message.threadsLen() + '_' + message.flagHash()).join(
return list.map(message => '' + message.hash + '_' + message.threadsLen() + '_' + message.flagHash()).join(
'|'
);
}

View file

@ -44,7 +44,7 @@ class PgpUserStore {
findPublicKeysByEmail(email) {
return _.compact(
_.flatten(
_.map(this.openpgpkeysPublic(), (item) => {
this.openpgpkeysPublic().map(item => {
const key = item && item.emails.includes(email) ? item : null;
return key ? key.getNativeKeys() : [null];
}),
@ -56,7 +56,7 @@ class PgpUserStore {
findPublicKeysBySigningKeyIds(signingKeyIds) {
return _.compact(
_.flatten(
_.map(signingKeyIds, (id) => {
signingKeyIds.map(id => {
const key = id && id.toHex ? this.findPublicKeyByHex(id.toHex()) : null;
return key ? key.getNativeKeys() : [null];
}),
@ -69,7 +69,7 @@ class PgpUserStore {
let result = isArray(encryptionKeyIds)
? _.compact(
_.flatten(
_.map(encryptionKeyIds, (id) => {
encryptionKeyIds.map(id => {
const key = id && id.toHex ? this.findPrivateKeyByHex(id.toHex()) : null;
return key ? (returnWrapKeys ? [key] : key.getNativeKeys()) : [null];
}),
@ -82,13 +82,13 @@ class PgpUserStore {
result = _.uniq(
_.compact(
_.flatten(
_.map(recipients, (sEmail) => {
recipients.map(sEmail => {
const keys = sEmail ? this.findAllPrivateKeysByEmailNotNative(sEmail) : null;
return keys
? returnWrapKeys
? keys
: _.flatten(
_.map(keys, (key) => key.getNativeKeys()),
keys.map(key => key.getNativeKeys()),
true
)
: [null];
@ -297,7 +297,7 @@ class PgpUserStore {
} else if (validPrivateKey) {
const keyIds = isNonEmptyArray(signingKeyIds) ? signingKeyIds : null,
additional = keyIds
? _.compact(_.map(keyIds, (item) => (item && item.toHex ? item.toHex() : null))).join(', ')
? _.compact(keyIds.map(item => (item && item.toHex ? item.toHex() : null))).join(', ')
: '';
store.controlsHelper(
@ -354,7 +354,7 @@ class PgpUserStore {
} else {
const keyIds = isNonEmptyArray(signingKeyIds) ? signingKeyIds : null,
additional = keyIds
? _.compact(_.map(keyIds, (item) => (item && item.toHex ? item.toHex() : null))).join(', ')
? _.compact(keyIds.map(item => (item && item.toHex ? item.toHex() : null))).join(', ')
: '';
store.controlsHelper(

View file

@ -16,7 +16,7 @@ class TemplateUserStore {
subscribers() {
this.templates.subscribe((list) => {
this.templatesNames(_.compact(_.map(list, (item) => (item ? item.name : null))));
this.templatesNames(_.compact(list.map(item => (item ? item.name : null))));
});
// this.templatesNames.subscribe((aList) => {