2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-23 08:00:34 +03:00

add change event

This commit is contained in:
Declan de Wet
2016-11-03 18:48:01 +02:00
parent c670b25add
commit 7fe58438d8
4 changed files with 36 additions and 8 deletions
+14 -6
View File
@@ -28,6 +28,10 @@ if (typeof window !== 'undefined' && window !== null) {
export default function updateClientMetaInfo (newInfo, $root) {
// if this is not a server render, then update
if (htmlTag.getAttribute(SERVER_RENDERED_ATTRIBUTE) === null) {
// initialize tracked changes
const addedTags = {}
const removedTags = {}
// update the title
updateTitle(newInfo.title)
@@ -40,14 +44,18 @@ export default function updateClientMetaInfo (newInfo, $root) {
// update tags
for (let i = 0, len = tags.length; i < len; i++) {
const tag = tags[i]
updateTags(tag, newInfo[tag], headTag)
const { oldTags, newTags } = updateTags(tag, newInfo[tag], headTag)
if (newTags.length) {
addedTags[tag] = newTags
removedTags[tag] = oldTags
}
}
// emit event
if (typeof newInfo.changed === 'function') {
newInfo.changed(newInfo, addedTags, removedTags)
}
} else {
htmlTag.removeAttribute(SERVER_RENDERED_ATTRIBUTE)
}
// HACK: since we're performing DOM side effects, we can't rely on
// Vue.nextTick in our tests. This event helps keep the test suite
// free of setTimeout clutter
$root.$emit('vue-meta-update')
}
+1 -1
View File
@@ -15,7 +15,7 @@ export default function getMetaInfo (component) {
for (let key in info) {
if (info.hasOwnProperty(key)) {
const value = info[key]
if (typeof value === 'function') {
if (typeof value === 'function' && key !== 'changed') {
info[key] = value()
}
}