mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-06-22 07:00:33 +03:00
refactor: small bundle size improvements
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import { clientSequences } from '../shared/escaping'
|
import { clientSequences } from '../shared/escaping'
|
||||||
|
import { rootConfigKey } from '../shared/constants'
|
||||||
import { showWarningNotSupported } from '../shared/log'
|
import { showWarningNotSupported } from '../shared/log'
|
||||||
import { getComponentMetaInfo } from '../shared/getComponentOption'
|
import { getComponentMetaInfo } from '../shared/getComponentOption'
|
||||||
import { getAppsMetaInfo, clearAppsMetaInfo } from '../shared/additional-app'
|
import { getAppsMetaInfo, clearAppsMetaInfo } from '../shared/additional-app'
|
||||||
@@ -16,19 +17,19 @@ import updateClientMetaInfo from './updateClientMetaInfo'
|
|||||||
*
|
*
|
||||||
* @return {Object} - new meta info
|
* @return {Object} - new meta info
|
||||||
*/
|
*/
|
||||||
export default function refresh (vm, options = {}) {
|
export default function refresh (rootVm, options = {}) {
|
||||||
// make sure vue-meta was initiated
|
// make sure vue-meta was initiated
|
||||||
if (!vm.$root._vueMeta) {
|
if (!rootVm[rootConfigKey]) {
|
||||||
showWarningNotSupported()
|
showWarningNotSupported()
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect & aggregate all metaInfo $options
|
// collect & aggregate all metaInfo $options
|
||||||
const rawInfo = getComponentMetaInfo(options, vm.$root)
|
const rawInfo = getComponentMetaInfo(options, rootVm)
|
||||||
|
|
||||||
const metaInfo = getMetaInfo(options, rawInfo, clientSequences, vm.$root)
|
const metaInfo = getMetaInfo(options, rawInfo, clientSequences, rootVm)
|
||||||
|
|
||||||
const { appId } = vm.$root._vueMeta
|
const { appId } = rootVm[rootConfigKey]
|
||||||
const tags = updateClientMetaInfo(appId, options, metaInfo)
|
const tags = updateClientMetaInfo(appId, options, metaInfo)
|
||||||
|
|
||||||
// emit "event" with new info
|
// emit "event" with new info
|
||||||
@@ -45,5 +46,5 @@ export default function refresh (vm, options = {}) {
|
|||||||
clearAppsMetaInfo(true)
|
clearAppsMetaInfo(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
return { vm, metaInfo, tags }
|
return { vm: rootVm, metaInfo, tags }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,19 @@
|
|||||||
|
import { rootConfigKey } from '../shared/constants'
|
||||||
|
|
||||||
// store an id to keep track of DOM updates
|
// store an id to keep track of DOM updates
|
||||||
let batchId = null
|
let batchId = null
|
||||||
|
|
||||||
export function triggerUpdate (vm, hookName) {
|
export function triggerUpdate (rootVm, hookName) {
|
||||||
// if an update was triggered during initialization or when an update was triggered by the
|
// if an update was triggered during initialization or when an update was triggered by the
|
||||||
// metaInfo watcher, set initialized to null
|
// metaInfo watcher, set initialized to null
|
||||||
// then we keep falsy value but know we need to run a triggerUpdate after initialization
|
// then we keep falsy value but know we need to run a triggerUpdate after initialization
|
||||||
if (!vm.$root._vueMeta.initialized && (vm.$root._vueMeta.initializing || hookName === 'watcher')) {
|
if (!rootVm[rootConfigKey].initialized && (rootVm[rootConfigKey].initializing || hookName === 'watcher')) {
|
||||||
vm.$root._vueMeta.initialized = null
|
rootVm[rootConfigKey].initialized = null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm.$root._vueMeta.initialized && !vm.$root._vueMeta.paused) {
|
if (rootVm[rootConfigKey].initialized && !rootVm[rootConfigKey].paused) {
|
||||||
// batch potential DOM updates to prevent extraneous re-rendering
|
// batch potential DOM updates to prevent extraneous re-rendering
|
||||||
batchUpdate(() => vm.$meta().refresh())
|
batchUpdate(() => rootVm.$meta().refresh())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import { version } from '../package.json'
|
import { version } from '../package.json'
|
||||||
|
import { showWarningNotSupportedInBrowserBundle } from './shared/log'
|
||||||
import createMixin from './shared/mixin'
|
import createMixin from './shared/mixin'
|
||||||
import { setOptions } from './shared/options'
|
import { setOptions } from './shared/options'
|
||||||
import $meta from './shared/$meta'
|
import $meta from './shared/$meta'
|
||||||
@@ -27,6 +28,6 @@ function install (Vue, options = {}) {
|
|||||||
export default {
|
export default {
|
||||||
version,
|
version,
|
||||||
install,
|
install,
|
||||||
generate: process.server ? generate : () => {},
|
generate: process.server ? generate : () => showWarningNotSupportedInBrowserBundle('generate'),
|
||||||
hasMetaInfo
|
hasMetaInfo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { serverSequences } from '../shared/escaping'
|
import { serverSequences } from '../shared/escaping'
|
||||||
|
import { rootConfigKey } from '../shared/constants'
|
||||||
import { showWarningNotSupported } from '../shared/log'
|
import { showWarningNotSupported } from '../shared/log'
|
||||||
import { getComponentMetaInfo } from '../shared/getComponentOption'
|
import { getComponentMetaInfo } from '../shared/getComponentOption'
|
||||||
import { getAppsMetaInfo, clearAppsMetaInfo } from '../shared/additional-app'
|
import { getAppsMetaInfo, clearAppsMetaInfo } from '../shared/additional-app'
|
||||||
@@ -12,17 +13,17 @@ import generateServerInjector from './generateServerInjector'
|
|||||||
* @vm {Object} - Vue instance - ideally the root component
|
* @vm {Object} - Vue instance - ideally the root component
|
||||||
* @return {Object} - server meta info with `toString` methods
|
* @return {Object} - server meta info with `toString` methods
|
||||||
*/
|
*/
|
||||||
export default function inject (vm, options = {}) {
|
export default function inject (rootVm, options = {}) {
|
||||||
// make sure vue-meta was initiated
|
// make sure vue-meta was initiated
|
||||||
if (!vm.$root._vueMeta) {
|
if (!rootVm[rootConfigKey]) {
|
||||||
showWarningNotSupported()
|
showWarningNotSupported()
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// collect & aggregate all metaInfo $options
|
// collect & aggregate all metaInfo $options
|
||||||
const rawInfo = getComponentMetaInfo(options, vm.$root)
|
const rawInfo = getComponentMetaInfo(options, rootVm)
|
||||||
|
|
||||||
const metaInfo = getMetaInfo(options, rawInfo, serverSequences, vm.$root)
|
const metaInfo = getMetaInfo(options, rawInfo, serverSequences, rootVm)
|
||||||
|
|
||||||
// generate server injector
|
// generate server injector
|
||||||
const serverInjector = generateServerInjector(options, metaInfo)
|
const serverInjector = generateServerInjector(options, metaInfo)
|
||||||
|
|||||||
+9
-7
@@ -1,7 +1,7 @@
|
|||||||
import refresh from '../client/refresh'
|
import refresh from '../client/refresh'
|
||||||
import inject from '../server/inject'
|
import inject from '../server/inject'
|
||||||
import { showWarningNotSupported } from '../shared/log'
|
|
||||||
import { addApp } from './additional-app'
|
import { addApp } from './additional-app'
|
||||||
|
import { showWarningNotSupportedInBrowserBundle } from './log'
|
||||||
import { addNavGuards } from './nav-guards'
|
import { addNavGuards } from './nav-guards'
|
||||||
import { pause, resume } from './pausing'
|
import { pause, resume } from './pausing'
|
||||||
import { getOptions } from './options'
|
import { getOptions } from './options'
|
||||||
@@ -12,17 +12,19 @@ export default function $meta (options = {}) {
|
|||||||
* @this {Object} - the Vue instance (a root component)
|
* @this {Object} - the Vue instance (a root component)
|
||||||
* @return {Object} - injector
|
* @return {Object} - injector
|
||||||
*/
|
*/
|
||||||
|
const $root = this.$root
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getOptions: () => getOptions(options),
|
getOptions: () => getOptions(options),
|
||||||
setOptions: ({ refreshOnceOnNavigation } = {}) => {
|
setOptions: ({ refreshOnceOnNavigation } = {}) => {
|
||||||
if (refreshOnceOnNavigation) {
|
if (refreshOnceOnNavigation) {
|
||||||
addNavGuards(this)
|
addNavGuards($root)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
refresh: () => refresh(this, options),
|
refresh: () => refresh($root, options),
|
||||||
inject: () => process.server ? inject(this, options) : showWarningNotSupported(),
|
inject: () => process.server ? inject($root, options) : showWarningNotSupportedInBrowserBundle('inject'),
|
||||||
pause: () => pause(this),
|
pause: () => pause($root),
|
||||||
resume: () => resume(this),
|
resume: () => resume($root),
|
||||||
addApp: appId => addApp(this, appId, options)
|
addApp: appId => addApp($root, appId, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,16 @@ import { getTag, removeElementsByAppId } from '../utils/elements'
|
|||||||
|
|
||||||
let appsMetaInfo
|
let appsMetaInfo
|
||||||
|
|
||||||
export function addApp (vm, appId, options) {
|
export function addApp (rootVm, appId, options) {
|
||||||
return {
|
return {
|
||||||
set: metaInfo => setMetaInfo(vm.$root, appId, options, metaInfo),
|
set: metaInfo => setMetaInfo(rootVm, appId, options, metaInfo),
|
||||||
remove: () => removeMetaInfo(vm.$root, appId, options)
|
remove: () => removeMetaInfo(rootVm, appId, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setMetaInfo (vm, appId, options, metaInfo) {
|
export function setMetaInfo (rootVm, appId, options, metaInfo) {
|
||||||
// if a vm exists _and_ its mounted then immediately update
|
// if a vm exists _and_ its mounted then immediately update
|
||||||
if (vm && vm.$el) {
|
if (rootVm && rootVm.$el) {
|
||||||
return updateClientMetaInfo(appId, options, metaInfo)
|
return updateClientMetaInfo(appId, options, metaInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ export function setMetaInfo (vm, appId, options, metaInfo) {
|
|||||||
appsMetaInfo[appId] = metaInfo
|
appsMetaInfo[appId] = metaInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeMetaInfo (vm, appId, options) {
|
export function removeMetaInfo (rootVm, appId, options) {
|
||||||
if (vm && vm.$el) {
|
if (rootVm && rootVm.$el) {
|
||||||
const tags = {}
|
const tags = {}
|
||||||
for (const type of metaInfoAttributeKeys) {
|
for (const type of metaInfoAttributeKeys) {
|
||||||
const tagName = type.substr(0, 4)
|
const tagName = type.substr(0, 4)
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ export const defaultInfo = {
|
|||||||
__dangerouslyDisableSanitizersByTagID: {}
|
__dangerouslyDisableSanitizersByTagID: {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const rootConfigKey = '_vueMeta'
|
||||||
|
|
||||||
// This is the name of the component option that contains all the information that
|
// This is the name of the component option that contains all the information that
|
||||||
// gets converted to the various meta tags & attributes for the page.
|
// gets converted to the various meta tags & attributes for the page.
|
||||||
export const keyName = 'metaInfo'
|
export const keyName = 'metaInfo'
|
||||||
|
|||||||
@@ -13,4 +13,6 @@ export function warn (str) {
|
|||||||
console.warn(str)
|
console.warn(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const showWarningNotSupportedInBrowserBundle = method => warn(`${method} is not supported in browser builds`)
|
||||||
|
|
||||||
export const showWarningNotSupported = () => warn('This vue app/component has no vue-meta configuration')
|
export const showWarningNotSupported = () => warn('This vue app/component has no vue-meta configuration')
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
import { isUndefined, isObject } from '../utils/is-type'
|
import { isUndefined, isObject } from '../utils/is-type'
|
||||||
|
import { rootConfigKey } from './constants'
|
||||||
|
|
||||||
// Vue $root instance has a _vueMeta object property, otherwise its a boolean true
|
// Vue $root instance has a _vueMeta object property, otherwise its a boolean true
|
||||||
export function hasMetaInfo (vm = this) {
|
export function hasMetaInfo (vm = this) {
|
||||||
return vm && (vm._vueMeta === true || isObject(vm._vueMeta))
|
return vm && (vm[rootConfigKey] === true || isObject(vm[rootConfigKey]))
|
||||||
}
|
}
|
||||||
|
|
||||||
// a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
|
// a component is in a metaInfo branch when itself has meta info or one of its (grand-)children has
|
||||||
export function inMetaInfoBranch (vm = this) {
|
export function inMetaInfoBranch (vm = this) {
|
||||||
return vm && !isUndefined(vm._vueMeta)
|
return vm && !isUndefined(vm[rootConfigKey])
|
||||||
}
|
}
|
||||||
|
|||||||
+41
-36
@@ -1,6 +1,7 @@
|
|||||||
import { triggerUpdate } from '../client/update'
|
import { triggerUpdate } from '../client/update'
|
||||||
import { isUndefined, isFunction } from '../utils/is-type'
|
import { isUndefined, isFunction } from '../utils/is-type'
|
||||||
import { ensuredPush } from '../utils/ensure'
|
import { ensuredPush } from '../utils/ensure'
|
||||||
|
import { rootConfigKey } from './constants'
|
||||||
import { hasMetaInfo } from './meta-helpers'
|
import { hasMetaInfo } from './meta-helpers'
|
||||||
import { addNavGuards } from './nav-guards'
|
import { addNavGuards } from './nav-guards'
|
||||||
import { warn } from './log'
|
import { warn } from './log'
|
||||||
@@ -14,13 +15,17 @@ export default function createMixin (Vue, options) {
|
|||||||
// watch for client side component updates
|
// watch for client side component updates
|
||||||
return {
|
return {
|
||||||
beforeCreate () {
|
beforeCreate () {
|
||||||
|
const $root = this.$root
|
||||||
|
const $options = this.$options
|
||||||
|
const $isServer = this.$isServer
|
||||||
|
|
||||||
Object.defineProperty(this, '_hasMetaInfo', {
|
Object.defineProperty(this, '_hasMetaInfo', {
|
||||||
configurable: true,
|
configurable: true,
|
||||||
get () {
|
get () {
|
||||||
// Show deprecation warning once when devtools enabled
|
// Show deprecation warning once when devtools enabled
|
||||||
if (Vue.config.devtools && !this.$root._vueMeta.hasMetaInfoDeprecationWarningShown) {
|
if (Vue.config.devtools && !$root[rootConfigKey]._shown) {
|
||||||
warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead')
|
warn('VueMeta DeprecationWarning: _hasMetaInfo has been deprecated and will be removed in a future version. Please use hasMetaInfo(vm) instead')
|
||||||
this.$root._vueMeta.hasMetaInfoDeprecationWarningShown = true
|
$root[rootConfigKey]._shown = true
|
||||||
}
|
}
|
||||||
return hasMetaInfo(this)
|
return hasMetaInfo(this)
|
||||||
}
|
}
|
||||||
@@ -29,24 +34,24 @@ export default function createMixin (Vue, options) {
|
|||||||
// Add a marker to know if it uses metaInfo
|
// Add a marker to know if it uses metaInfo
|
||||||
// _vnode is used to know that it's attached to a real component
|
// _vnode is used to know that it's attached to a real component
|
||||||
// useful if we use some mixin to add some meta tags (like nuxt-i18n)
|
// useful if we use some mixin to add some meta tags (like nuxt-i18n)
|
||||||
if (isUndefined(this.$options[options.keyName]) || this.$options[options.keyName] === null) {
|
if (isUndefined($options[options.keyName]) || $options[options.keyName] === null) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.$root._vueMeta) {
|
if (!$root[rootConfigKey]) {
|
||||||
this.$root._vueMeta = { appId }
|
$root[rootConfigKey] = { appId }
|
||||||
appId++
|
appId++
|
||||||
}
|
}
|
||||||
|
|
||||||
// to speed up updates we keep track of branches which have a component with vue-meta info defined
|
// 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 _vueMeta = true it has info, if _vueMeta = false a child has info
|
||||||
if (!this._vueMeta) {
|
if (!this[rootConfigKey]) {
|
||||||
this._vueMeta = true
|
this[rootConfigKey] = true
|
||||||
|
|
||||||
let p = this.$parent
|
let p = this.$parent
|
||||||
while (p && p !== this.$root) {
|
while (p && p !== $root) {
|
||||||
if (isUndefined(p._vueMeta)) {
|
if (isUndefined(p[rootConfigKey])) {
|
||||||
p._vueMeta = false
|
p[rootConfigKey] = false
|
||||||
}
|
}
|
||||||
p = p.$parent
|
p = p.$parent
|
||||||
}
|
}
|
||||||
@@ -54,19 +59,19 @@ export default function createMixin (Vue, options) {
|
|||||||
|
|
||||||
// coerce function-style metaInfo to a computed prop so we can observe
|
// coerce function-style metaInfo to a computed prop so we can observe
|
||||||
// it on creation
|
// it on creation
|
||||||
if (isFunction(this.$options[options.keyName])) {
|
if (isFunction($options[options.keyName])) {
|
||||||
if (!this.$options.computed) {
|
if (!$options.computed) {
|
||||||
this.$options.computed = {}
|
$options.computed = {}
|
||||||
}
|
}
|
||||||
this.$options.computed.$metaInfo = this.$options[options.keyName]
|
$options.computed.$metaInfo = $options[options.keyName]
|
||||||
|
|
||||||
if (!this.$isServer) {
|
if (!$isServer) {
|
||||||
// if computed $metaInfo exists, watch it for updates & trigger a refresh
|
// if computed $metaInfo exists, watch it for updates & trigger a refresh
|
||||||
// when it changes (i.e. automatically handle async actions that affect metaInfo)
|
// when it changes (i.e. automatically handle async actions that affect metaInfo)
|
||||||
// credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux)
|
// credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux)
|
||||||
ensuredPush(this.$options, 'created', () => {
|
ensuredPush($options, 'created', () => {
|
||||||
this.$watch('$metaInfo', () => {
|
this.$watch('$metaInfo', () => {
|
||||||
triggerUpdate(this, 'watcher')
|
triggerUpdate($root, 'watcher')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -76,28 +81,28 @@ export default function createMixin (Vue, options) {
|
|||||||
// 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 immediately set the page title
|
// has throttled rAF/timers we still immediately set the page title
|
||||||
if (isUndefined(this.$root._vueMeta.initialized)) {
|
if (isUndefined($root[rootConfigKey].initialized)) {
|
||||||
this.$root._vueMeta.initialized = this.$isServer
|
$root[rootConfigKey].initialized = $isServer
|
||||||
|
|
||||||
if (!this.$root._vueMeta.initialized) {
|
if (!$root[rootConfigKey].initialized) {
|
||||||
ensuredPush(this.$options, 'beforeMount', () => {
|
ensuredPush($options, 'beforeMount', () => {
|
||||||
// if this Vue-app was server rendered, set the appId to 'ssr'
|
// if this Vue-app was server rendered, set the appId to 'ssr'
|
||||||
// only one SSR app per page is supported
|
// only one SSR app per page is supported
|
||||||
if (this.$root.$el && this.$root.$el.hasAttribute && this.$root.$el.hasAttribute('data-server-rendered')) {
|
if ($root.$el && $root.$el.hasAttribute && $root.$el.hasAttribute('data-server-rendered')) {
|
||||||
this.$root._vueMeta.appId = options.ssrAppId
|
$root[rootConfigKey].appId = options.ssrAppId
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// we use the mounted hook here as on page load
|
// we use the mounted hook here as on page load
|
||||||
ensuredPush(this.$options, 'mounted', () => {
|
ensuredPush($options, 'mounted', () => {
|
||||||
if (!this.$root._vueMeta.initialized) {
|
if (!$root[rootConfigKey].initialized) {
|
||||||
// used in triggerUpdate to check if a change was triggered
|
// used in triggerUpdate to check if a change was triggered
|
||||||
// during initialization
|
// during initialization
|
||||||
this.$root._vueMeta.initializing = true
|
$root[rootConfigKey].initializing = true
|
||||||
|
|
||||||
// refresh meta in nextTick so all child components have loaded
|
// refresh meta in nextTick so all child components have loaded
|
||||||
this.$nextTick(function () {
|
this.$nextTick(function () {
|
||||||
const { tags, metaInfo } = this.$root.$meta().refresh()
|
const { tags, metaInfo } = $root.$meta().refresh()
|
||||||
|
|
||||||
// After ssr hydration (identifier by tags === false) check
|
// After ssr hydration (identifier by tags === false) check
|
||||||
// if initialized was set to null in triggerUpdate. That'd mean
|
// if initialized was set to null in triggerUpdate. That'd mean
|
||||||
@@ -105,17 +110,17 @@ export default function createMixin (Vue, options) {
|
|||||||
// to be applied OR a metaInfo watcher was triggered before the
|
// to be applied OR a metaInfo watcher was triggered before the
|
||||||
// current hook was called
|
// current hook was called
|
||||||
// (during initialization all changes are blocked)
|
// (during initialization all changes are blocked)
|
||||||
if (tags === false && this.$root._vueMeta.initialized === null) {
|
if (tags === false && $root[rootConfigKey].initialized === null) {
|
||||||
this.$nextTick(() => triggerUpdate(this, 'initializing'))
|
this.$nextTick(() => triggerUpdate($root, 'initializing'))
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$root._vueMeta.initialized = true
|
$root[rootConfigKey].initialized = true
|
||||||
delete this.$root._vueMeta.initializing
|
delete $root[rootConfigKey].initializing
|
||||||
|
|
||||||
// add the navigation guards if they havent been added yet
|
// add the navigation guards if they havent been added yet
|
||||||
// they are needed for the afterNavigation callback
|
// they are needed for the afterNavigation callback
|
||||||
if (!options.refreshOnceOnNavigation && metaInfo.afterNavigation) {
|
if (!options.refreshOnceOnNavigation && metaInfo.afterNavigation) {
|
||||||
addNavGuards(this)
|
addNavGuards($root)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -123,19 +128,19 @@ export default function createMixin (Vue, options) {
|
|||||||
|
|
||||||
// add the navigation guards if requested
|
// add the navigation guards if requested
|
||||||
if (options.refreshOnceOnNavigation) {
|
if (options.refreshOnceOnNavigation) {
|
||||||
addNavGuards(this)
|
addNavGuards($root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// do not trigger refresh on the server side
|
// do not trigger refresh on the server side
|
||||||
if (this.$isServer) {
|
if ($isServer) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// no need to add this hooks on server side
|
// no need to add this hooks on server side
|
||||||
updateOnLifecycleHook.forEach((lifecycleHook) => {
|
updateOnLifecycleHook.forEach((lifecycleHook) => {
|
||||||
ensuredPush(this.$options, lifecycleHook, () => triggerUpdate(this, lifecycleHook))
|
ensuredPush($options, lifecycleHook, () => triggerUpdate(this, lifecycleHook))
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// TODO: move back into beforeCreate when Vue issue is resolved
|
// TODO: move back into beforeCreate when Vue issue is resolved
|
||||||
@@ -155,7 +160,7 @@ export default function createMixin (Vue, options) {
|
|||||||
|
|
||||||
clearInterval(interval)
|
clearInterval(interval)
|
||||||
|
|
||||||
triggerUpdate(this, 'destroyed')
|
triggerUpdate(this.$root, 'destroyed')
|
||||||
}, 50)
|
}, 50)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
import { isFunction } from '../utils/is-type'
|
import { isFunction } from '../utils/is-type'
|
||||||
|
import { rootConfigKey } from './constants'
|
||||||
|
|
||||||
export function addNavGuards (vm) {
|
export function addNavGuards (rootVm) {
|
||||||
// return when nav guards already added or no router exists
|
// return when nav guards already added or no router exists
|
||||||
if (vm.$root._vueMeta.navGuards || !vm.$root.$router) {
|
if (rootVm[rootConfigKey].navGuards || !rootVm.$router) {
|
||||||
/* istanbul ignore next */
|
/* istanbul ignore next */
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
vm.$root._vueMeta.navGuards = true
|
rootVm[rootConfigKey].navGuards = true
|
||||||
|
|
||||||
const $router = vm.$root.$router
|
const $router = rootVm.$router
|
||||||
const $meta = vm.$root.$meta()
|
const $meta = rootVm.$meta()
|
||||||
|
|
||||||
$router.beforeEach((to, from, next) => {
|
$router.beforeEach((to, from, next) => {
|
||||||
$meta.pause()
|
$meta.pause()
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
export function pause (vm, refresh = true) {
|
import { rootConfigKey } from './constants'
|
||||||
vm.$root._vueMeta.paused = true
|
|
||||||
|
export function pause (rootVm, refresh = true) {
|
||||||
|
rootVm[rootConfigKey].paused = true
|
||||||
|
|
||||||
return () => resume(refresh)
|
return () => resume(refresh)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resume (vm, refresh = true) {
|
export function resume (rootVm, refresh = true) {
|
||||||
vm.$root._vueMeta.paused = false
|
rootVm[rootConfigKey].paused = false
|
||||||
|
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
return vm.$root.$meta().refresh()
|
return rootVm.$meta().refresh()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user