Skip to content

Commit

Permalink
feat: track branches which contain metaInfo components
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie authored and TheAlexLichter committed Mar 12, 2019
1 parent fa90902 commit f2e8eb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/shared/inMetaInfoBranch.js
Original file line number Diff line number Diff line change
@@ -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)
}
15 changes: 13 additions & 2 deletions src/shared/mixin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import triggerUpdate from '../client/triggerUpdate'
import hasMetaInfo from './hasMetaInfo'
import { isUndefined, isFunction } from './typeof'
import { ensuredPush } from './ensure'

Expand All @@ -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
this.$root._vueMeta.hasMetaInfoDeprecationWarningShown = true
}
return !!this._vueMeta
return hasMetaInfo(this)
}
})

Expand All @@ -28,8 +29,18 @@ export default function createMixin(Vue, options) {
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) {
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
Expand All @@ -55,7 +66,7 @@ export default function createMixin(Vue, options) {
// force an initial refresh on page load and prevent other lifecycleHooks
// to triggerUpdate until this initial refresh is finished
// 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)) {
this.$root._vueMeta.initialized = this.$isServer

Expand Down

0 comments on commit f2e8eb5

Please sign in to comment.