Skip to content

Commit

Permalink
feat: child can indicate parent vmid to be removed (resolves: #288)
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie authored and manniL committed Mar 12, 2019
1 parent 22e456c commit 915fedf
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/shared/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export function arrayMerge({ component, tagIDKeyName, metaTemplateKeyName, conte
return
}

// if source specifies null as content then ignore both the target as the source
if (sourceItem[contentKeyName] === null || sourceItem.innerHTML === null) {
// remove current index from source array so its not concatenated to destination below
source.splice(sourceIndex, 1)
return
}

// we now know that targetItem is a duplicate and we should ignore it in favor of sourceItem
// now we only need to check if the target has a template to combine it with the source
const targetTemplate = targetItem[metaTemplateKeyName]
Expand Down
48 changes: 48 additions & 0 deletions test/getMetaInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,4 +671,52 @@ describe('getMetaInfo', () => {
__dangerouslyDisableSanitizersByTagID: {}
})
})

test('child can indicate to remove parent vmids', () => {
Vue.component('merge-child', {
render: h => h('div'),
metaInfo: {
title: 'Hi',
meta: [
{
vmid: 'og:title',
content: null
}
]
}
})

const component = new Vue({
metaInfo: {
title: 'Hello',
meta: [
{
vmid: 'og:title',
property: 'og:title',
content: 'Test title',
template: chunk => `${chunk} - My page`
}
]
},
el: document.createElement('div'),
render: h => h('div', null, [h('merge-child')])
})

expect(getMetaInfo(component)).toEqual({
title: 'Hi',
titleChunk: 'Hi',
titleTemplate: '%s',
htmlAttrs: {},
headAttrs: {},
bodyAttrs: {},
meta: [],
base: [],
link: [],
style: [],
script: [],
noscript: [],
__dangerouslyDisableSanitizers: [],
__dangerouslyDisableSanitizersByTagID: {}
})
})
})

0 comments on commit 915fedf

Please sign in to comment.