From 674189736994f3a7314eb4cd6dd29e0e3e24c0a8 Mon Sep 17 00:00:00 2001 From: pimlie Date: Mon, 11 Feb 2019 11:12:19 +0100 Subject: [PATCH] fix: prefer for..in instead keys.forEach --- src/client/updateClientMetaInfo.js | 10 +++++----- src/server/generators/tag.js | 6 ++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/client/updateClientMetaInfo.js b/src/client/updateClientMetaInfo.js index 45776b3d..e7bb46ad 100644 --- a/src/client/updateClientMetaInfo.js +++ b/src/client/updateClientMetaInfo.js @@ -28,22 +28,22 @@ export default function updateClientMetaInfo(options = {}, newInfo) { const addedTags = {} const removedTags = {} - Object.keys(newInfo).forEach((type) => { + for (const type in newInfo) { // ignore these if (metaInfoOptionKeys.includes(type)) { - return + continue } if (type === 'title') { // update the title updateTitle(newInfo.title) - return + continue } if (metaInfoAttributeKeys.includes(type)) { const tagName = type.substr(0, 4) updateAttribute(options, newInfo[type], getTag(tags, tagName)) - return + continue } const { oldTags, newTags } = updateTag( @@ -58,7 +58,7 @@ export default function updateClientMetaInfo(options = {}, newInfo) { addedTags[type] = newTags removedTags[type] = oldTags } - }) + } return { addedTags, removedTags } } else { diff --git a/src/server/generators/tag.js b/src/server/generators/tag.js index 8127c9d4..1740154f 100644 --- a/src/server/generators/tag.js +++ b/src/server/generators/tag.js @@ -13,7 +13,9 @@ export default function tagGenerator({ attribute, tagIDKeyName } = {}, type, tag text({ body = false } = {}) { // build a string containing all tags of this type return tags.reduce((tagsStr, tag) => { - if (Object.keys(tag).length === 0) { + const tagKeys = Object.keys(tag) + + if (tagKeys.length === 0) { return tagsStr // Bail on empty tag object } @@ -22,7 +24,7 @@ export default function tagGenerator({ attribute, tagIDKeyName } = {}, type, tag } // build a string containing all attributes of this tag - const attrs = Object.keys(tag).reduce((attrsStr, attr) => { + const attrs = tagKeys.reduce((attrsStr, attr) => { // these attributes are treated as children on the tag if (tagAttributeAsInnerContent.includes(attr) || attr === 'once') { return attrsStr