2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-25 09:00:33 +03:00

fix: prefer for..in instead keys.forEach

This commit is contained in:
pimlie
2019-02-11 11:12:19 +01:00
parent 5031acf0fa
commit 6741897369
2 changed files with 9 additions and 7 deletions
+5 -5
View File
@@ -28,22 +28,22 @@ export default function updateClientMetaInfo(options = {}, newInfo) {
const addedTags = {} const addedTags = {}
const removedTags = {} const removedTags = {}
Object.keys(newInfo).forEach((type) => { for (const type in newInfo) {
// ignore these // ignore these
if (metaInfoOptionKeys.includes(type)) { if (metaInfoOptionKeys.includes(type)) {
return continue
} }
if (type === 'title') { if (type === 'title') {
// update the title // update the title
updateTitle(newInfo.title) updateTitle(newInfo.title)
return continue
} }
if (metaInfoAttributeKeys.includes(type)) { if (metaInfoAttributeKeys.includes(type)) {
const tagName = type.substr(0, 4) const tagName = type.substr(0, 4)
updateAttribute(options, newInfo[type], getTag(tags, tagName)) updateAttribute(options, newInfo[type], getTag(tags, tagName))
return continue
} }
const { oldTags, newTags } = updateTag( const { oldTags, newTags } = updateTag(
@@ -58,7 +58,7 @@ export default function updateClientMetaInfo(options = {}, newInfo) {
addedTags[type] = newTags addedTags[type] = newTags
removedTags[type] = oldTags removedTags[type] = oldTags
} }
}) }
return { addedTags, removedTags } return { addedTags, removedTags }
} else { } else {
+4 -2
View File
@@ -13,7 +13,9 @@ export default function tagGenerator({ attribute, tagIDKeyName } = {}, type, tag
text({ body = false } = {}) { text({ body = false } = {}) {
// build a string containing all tags of this type // build a string containing all tags of this type
return tags.reduce((tagsStr, tag) => { 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 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 // 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 // these attributes are treated as children on the tag
if (tagAttributeAsInnerContent.includes(attr) || attr === 'once') { if (tagAttributeAsInnerContent.includes(attr) || attr === 'once') {
return attrsStr return attrsStr