Skip to content

Commit

Permalink
fix: prefer for..in instead keys.forEach
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Feb 11, 2019
1 parent 5031acf commit 6741897
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/client/updateClientMetaInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -58,7 +58,7 @@ export default function updateClientMetaInfo(options = {}, newInfo) {
addedTags[type] = newTags
removedTags[type] = oldTags
}
})
}

return { addedTags, removedTags }
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/server/generators/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
Expand Down

0 comments on commit 6741897

Please sign in to comment.