Object.entries().forEach() to forEachObjectEntry()

This commit is contained in:
djmaze 2021-12-01 14:23:37 +01:00
parent b8eb8f83fa
commit 6d7911a9ed
8 changed files with 18 additions and 18 deletions

View file

@ -2,7 +2,7 @@ import ko from 'ko';
import { Notification, UploadErrorCode } from 'Common/Enums'; import { Notification, UploadErrorCode } from 'Common/Enums';
import { langLink } from 'Common/Links'; import { langLink } from 'Common/Links';
import { doc, createElement } from 'Common/Globals'; import { doc, createElement } from 'Common/Globals';
import { getKeyByValue } from 'Common/Utils'; import { getKeyByValue, forEachObjectEntry } from 'Common/Utils';
let I18N_DATA = {}; let I18N_DATA = {};
@ -66,7 +66,7 @@ export const
} }
} }
if (valueList) { if (valueList) {
Object.entries(valueList).forEach(([key, value]) => { forEachObjectEntry(valueList, (key, value) => {
result = result.replace('%' + key + '%', value); result = result.replace('%' + key + '%', value);
}); });
} }

View file

@ -1,4 +1,4 @@
import { isArray, isFunction, addObservablesTo, addComputablesTo, forEachObjectValue } from 'Common/Utils'; import { isArray, isFunction, addObservablesTo, addComputablesTo, forEachObjectValue, forEachObjectEntry } from 'Common/Utils';
function dispose(disposable) { function dispose(disposable) {
if (disposable && isFunction(disposable.dispose)) { if (disposable && isFunction(disposable.dispose)) {
@ -43,7 +43,7 @@ export class AbstractModel {
} }
addSubscribables(subscribables) { addSubscribables(subscribables) {
Object.entries(subscribables).forEach(([key, fn]) => this.subscribables.push( this[key].subscribe(fn) ) ); forEachObjectEntry(subscribables, (key, fn) => this.subscribables.push( this[key].subscribe(fn) ) );
} }
/** Called by delegateRunOnDestroy */ /** Called by delegateRunOnDestroy */
@ -51,7 +51,7 @@ export class AbstractModel {
/** dispose ko subscribables */ /** dispose ko subscribables */
this.subscribables.forEach(dispose); this.subscribables.forEach(dispose);
/** clear object entries */ /** clear object entries */
// Object.entries(this).forEach(([key, value]) => { // forEachObjectEntry(this, (key, value) => {
forEachObjectValue(this, value => { forEachObjectValue(this, value => {
/** clear CollectionModel */ /** clear CollectionModel */
let arr = ko.isObservableArray(value) ? value() : value; let arr = ko.isObservableArray(value) ? value() : value;
@ -89,7 +89,7 @@ export class AbstractModel {
if (!model.validJson(json)) { if (!model.validJson(json)) {
return false; return false;
} }
Object.entries(json).forEach(([key, value]) => { forEachObjectEntry(json, (key, value) => {
if ('@' !== key[0]) try { if ('@' !== key[0]) try {
key = key[0].toLowerCase() + key.substr(1); key = key[0].toLowerCase() + key.substr(1);
switch (typeof this[key]) switch (typeof this[key])

View file

@ -1,7 +1,7 @@
import ko from 'ko'; import ko from 'ko';
import { doc, $htmlCL, elementById } from 'Common/Globals'; import { doc, $htmlCL, elementById } from 'Common/Globals';
import { isFunction, forEachObjectValue } from 'Common/Utils'; import { isFunction, forEachObjectValue, forEachObjectEntry } from 'Common/Utils';
let let
SCREENS = {}, SCREENS = {},
@ -349,7 +349,7 @@ export const
}, },
decorateKoCommands = (thisArg, commands) => decorateKoCommands = (thisArg, commands) =>
Object.entries(commands).forEach(([key, canExecute]) => { forEachObjectEntry(commands, (key, canExecute) => {
let command = thisArg[key], let command = thisArg[key],
fn = (...args) => fn.enabled() && fn.canExecute() && command.apply(thisArg, args); fn = (...args) => fn.enabled() && fn.canExecute() && command.apply(thisArg, args);

View file

@ -1,4 +1,4 @@
import { isArray } from 'Common/Utils'; import { isArray, forEachObjectEntry } from 'Common/Utils';
export class AbstractCollectionModel extends Array export class AbstractCollectionModel extends Array
{ {
@ -24,7 +24,7 @@ export class AbstractCollectionModel extends Array
const result = new this(); const result = new this();
if (json) { if (json) {
if ('Collection/'+this.name.replace('Model', '') === json['@Object']) { if ('Collection/'+this.name.replace('Model', '') === json['@Object']) {
Object.entries(json).forEach(([key, value]) => '@' !== key[0] && (result[key] = value)); forEachObjectEntry(json, (key, value) => '@' !== key[0] && (result[key] = value));
json = json['@Collection']; json = json['@Collection'];
} }
if (isArray(json)) { if (isArray(json)) {

View file

@ -4,7 +4,7 @@ import { MessagePriority } from 'Common/EnumsUser';
import { i18n } from 'Common/Translator'; import { i18n } from 'Common/Translator';
import { encodeHtml } from 'Common/Html'; import { encodeHtml } from 'Common/Html';
import { isArray, arrayLength } from 'Common/Utils'; import { isArray, arrayLength, forEachObjectEntry } from 'Common/Utils';
import { serverRequestRaw } from 'Common/Links'; import { serverRequestRaw } from 'Common/Links';
@ -275,7 +275,7 @@ export class MessageModel extends AbstractModel {
*/ */
lineAsCss() { lineAsCss() {
let classes = []; let classes = [];
Object.entries({ forEachObjectEntry({
deleted: this.deleted(), deleted: this.deleted(),
'deleted-mark': this.isDeleted(), 'deleted-mark': this.isDeleted(),
selected: this.selected(), selected: this.selected(),
@ -291,7 +291,7 @@ export class MessageModel extends AbstractModel {
// hasChildrenMessage: 1 < this.threadsLen(), // hasChildrenMessage: 1 < this.threadsLen(),
hasUnseenSubMessage: this.hasUnseenSubMessage(), hasUnseenSubMessage: this.hasUnseenSubMessage(),
hasFlaggedSubMessage: this.hasFlaggedSubMessage() hasFlaggedSubMessage: this.hasFlaggedSubMessage()
}).forEach(([key, value]) => value && classes.push(key)); }, (key, value) => value && classes.push(key));
return classes.join(' '); return classes.join(' ');
} }

View file

@ -12,7 +12,7 @@ import {
SetSystemFoldersNotification SetSystemFoldersNotification
} from 'Common/EnumsUser'; } from 'Common/EnumsUser';
import { inFocus, pInt, isArray, arrayLength } from 'Common/Utils'; import { inFocus, pInt, isArray, arrayLength, forEachObjectEntry } from 'Common/Utils';
import { delegateRunOnDestroy, initFullscreen } from 'Common/UtilsUser'; import { delegateRunOnDestroy, initFullscreen } from 'Common/UtilsUser';
import { encodeHtml, HtmlEditor } from 'Common/Html'; import { encodeHtml, HtmlEditor } from 'Common/Html';
@ -1018,7 +1018,7 @@ class ComposePopupView extends AbstractViewPopup {
if (arrayLength(downloads)) { if (arrayLength(downloads)) {
Remote.messageUploadAttachments((iError, oData) => { Remote.messageUploadAttachments((iError, oData) => {
if (!iError) { if (!iError) {
Object.entries(oData.Result).forEach(([tempName, id]) => { forEachObjectEntry(oData.Result, (tempName, id) => {
const attachment = this.getAttachmentById(id); const attachment = this.getAttachmentById(id);
if (attachment) { if (attachment) {
attachment.tempName(tempName); attachment.tempName(tempName);

View file

@ -1,4 +1,4 @@
import { pInt, pString } from 'Common/Utils'; import { pInt, pString, forEachObjectEntry } from 'Common/Utils';
import { i18n, getNotification } from 'Common/Translator'; import { i18n, getNotification } from 'Common/Translator';
import Remote from 'Remote/Admin/Fetch'; import Remote from 'Remote/Admin/Fetch';
@ -275,7 +275,7 @@ class DomainPopupView extends AbstractViewPopup {
clearForm() { clearForm() {
this.edit(false); this.edit(false);
Object.entries(this.getDefaults()).forEach(([key, value]) => this[key](value)); forEachObjectEntry(this.getDefaults(), (key, value) => this[key](value));
this.enableSmartPorts(true); this.enableSmartPorts(true);
} }
} }

View file

@ -63,7 +63,7 @@ export class SystemDropDownUserView extends AbstractViewRight {
} }
} else { } else {
/* // Not working yet /* // Not working yet
Object.entries(oData.Result).forEach((key, value) => rl.settings.set(key, value)); forEachObjectEntry(oData.Result, (key, value) => rl.settings.set(key, value));
clearCache(); clearCache();
// MessageUserStore.setMessage(); // MessageUserStore.setMessage();
// MessageUserStore.purgeMessageBodyCache(); // MessageUserStore.purgeMessageBodyCache();