mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-24 00:40:35 +03:00
feat: track branches which contain metaInfo components
This commit is contained in:
committed by
Alexander Lichter
parent
fa90902fc7
commit
f2e8eb537d
@@ -0,0 +1,6 @@
|
|||||||
|
import { isUndefined } from './typeof'
|
||||||
|
|
||||||
|
// a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
|
||||||
|
export default function inMetaInfoBranch(vm = this) {
|
||||||
|
return vm && !isUndefined(vm._vueMeta)
|
||||||
|
}
|
||||||
+13
-2
@@ -1,4 +1,5 @@
|
|||||||
import triggerUpdate from '../client/triggerUpdate'
|
import triggerUpdate from '../client/triggerUpdate'
|
||||||
|
import hasMetaInfo from './hasMetaInfo'
|
||||||
import { isUndefined, isFunction } from './typeof'
|
import { isUndefined, isFunction } from './typeof'
|
||||||
import { ensuredPush } from './ensure'
|
import { ensuredPush } from './ensure'
|
||||||
|
|
||||||
@@ -16,7 +17,7 @@ export default function createMixin(Vue, options) {
|
|||||||
console.warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please import hasMetaInfo and use hasMetaInfo(vm) instead') // eslint-disable-line no-console
|
console.warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please import hasMetaInfo and use hasMetaInfo(vm) instead') // eslint-disable-line no-console
|
||||||
this.$root._vueMeta.hasMetaInfoDeprecationWarningShown = true
|
this.$root._vueMeta.hasMetaInfoDeprecationWarningShown = true
|
||||||
}
|
}
|
||||||
return !!this._vueMeta
|
return hasMetaInfo(this)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -28,8 +29,18 @@ export default function createMixin(Vue, options) {
|
|||||||
this.$root._vueMeta = {}
|
this.$root._vueMeta = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// to speed up updates we keep track of branches which have a component with vue-meta info defined
|
||||||
|
// if _vueMeta = true it has info, if _vueMeta = false a child has info
|
||||||
if (!this._vueMeta) {
|
if (!this._vueMeta) {
|
||||||
this._vueMeta = true
|
this._vueMeta = true
|
||||||
|
|
||||||
|
let p = this.$parent
|
||||||
|
while (p && p !== this.$root) {
|
||||||
|
if (isUndefined(p._vueMeta)) {
|
||||||
|
p._vueMeta = false
|
||||||
|
}
|
||||||
|
p = p.$parent
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// coerce function-style metaInfo to a computed prop so we can observe
|
// coerce function-style metaInfo to a computed prop so we can observe
|
||||||
@@ -55,7 +66,7 @@ export default function createMixin(Vue, options) {
|
|||||||
// force an initial refresh on page load and prevent other lifecycleHooks
|
// force an initial refresh on page load and prevent other lifecycleHooks
|
||||||
// to triggerUpdate until this initial refresh is finished
|
// to triggerUpdate until this initial refresh is finished
|
||||||
// this is to make sure that when a page is opened in an inactive tab which
|
// this is to make sure that when a page is opened in an inactive tab which
|
||||||
// has throttled rAF/timers we still immeditately set the page title
|
// has throttled rAF/timers we still immediately set the page title
|
||||||
if (isUndefined(this.$root._vueMeta.initialized)) {
|
if (isUndefined(this.$root._vueMeta.initialized)) {
|
||||||
this.$root._vueMeta.initialized = this.$isServer
|
this.$root._vueMeta.initialized = this.$isServer
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user