1
1
import { triggerUpdate } from '../client/update'
2
2
import { isUndefined , isFunction } from '../utils/is-type'
3
3
import { find } from '../utils/array'
4
- import { ensuredPush } from '../utils/ensure'
5
4
import { rootConfigKey } from './constants'
6
5
import { hasMetaInfo } from './meta-helpers'
7
6
import { addNavGuards } from './nav-guards'
@@ -80,7 +79,7 @@ export default function createMixin (Vue, options) {
80
79
// if computed $metaInfo exists, watch it for updates & trigger a refresh
81
80
// when it changes (i.e. automatically handle async actions that affect metaInfo)
82
81
// credit for this suggestion goes to [Sébastien Chopin](https://github.com/Atinux)
83
- ensuredPush ( $options , ' created', function ( ) {
82
+ this . $on ( 'hook: created', function ( ) {
84
83
this . $watch ( '$metaInfo' , function ( ) {
85
84
triggerUpdate ( options , this [ rootKey ] , 'watcher' )
86
85
} )
@@ -99,7 +98,7 @@ export default function createMixin (Vue, options) {
99
98
if ( ! $root [ rootConfigKey ] . initializedSsr ) {
100
99
$root [ rootConfigKey ] . initializedSsr = true
101
100
102
- ensuredPush ( $options , ' beforeMount', function ( ) {
101
+ this . $on ( 'hook: beforeMount', function ( ) {
103
102
const $root = this
104
103
// if this Vue-app was server rendered, set the appId to 'ssr'
105
104
// only one SSR app per page is supported
@@ -110,7 +109,7 @@ export default function createMixin (Vue, options) {
110
109
}
111
110
112
111
// we use the mounted hook here as on page load
113
- ensuredPush ( $options , ' mounted', function ( ) {
112
+ this . $on ( 'hook: mounted', function ( ) {
114
113
const $root = this [ rootKey ]
115
114
116
115
if ( ! $root [ rootConfigKey ] . initialized ) {
@@ -150,6 +149,36 @@ export default function createMixin (Vue, options) {
150
149
}
151
150
}
152
151
152
+ this . $on ( 'hook:destroyed' , function ( ) {
153
+ // do not trigger refresh:
154
+ // - when user configured to not wait for transitions on destroyed
155
+ // - when the component doesnt have a parent
156
+ // - doesnt have metaInfo defined
157
+ if ( ! this . $parent || ! hasMetaInfo ( this ) ) {
158
+ return
159
+ }
160
+ delete this . _hasMetaInfo
161
+
162
+ this . $nextTick ( ( ) => {
163
+ if ( ! options . waitOnDestroyed || ! this . $el || ! this . $el . offsetParent ) {
164
+ triggerUpdate ( options , this . $root , 'destroyed' )
165
+ return
166
+ }
167
+
168
+ // Wait that element is hidden before refreshing meta tags (to support animations)
169
+ const interval = setInterval ( ( ) => {
170
+ if ( this . $el && this . $el . offsetParent !== null ) {
171
+ /* istanbul ignore next line */
172
+ return
173
+ }
174
+
175
+ clearInterval ( interval )
176
+
177
+ triggerUpdate ( options , this . $root , 'destroyed' )
178
+ } , 50 )
179
+ } )
180
+ } )
181
+
153
182
// do not trigger refresh on the server side
154
183
if ( this . $isServer ) {
155
184
/* istanbul ignore next */
@@ -158,40 +187,10 @@ export default function createMixin (Vue, options) {
158
187
159
188
// no need to add this hooks on server side
160
189
updateOnLifecycleHook . forEach ( ( lifecycleHook ) => {
161
- ensuredPush ( $options , lifecycleHook , function ( ) {
190
+ this . $on ( `hook: ${ lifecycleHook } ` , function ( ) {
162
191
triggerUpdate ( options , this [ rootKey ] , lifecycleHook )
163
192
} )
164
193
} )
165
- } ,
166
- // TODO: move back into beforeCreate when Vue issue is resolved
167
- destroyed ( ) {
168
- // do not trigger refresh:
169
- // - when user configured to not wait for transitions on destroyed
170
- // - when the component doesnt have a parent
171
- // - doesnt have metaInfo defined
172
- if ( ! this . $parent || ! hasMetaInfo ( this ) ) {
173
- return
174
- }
175
- delete this . _hasMetaInfo
176
-
177
- this . $nextTick ( ( ) => {
178
- if ( ! options . waitOnDestroyed || ! this . $el || ! this . $el . offsetParent ) {
179
- triggerUpdate ( options , this . $root , 'destroyed' )
180
- return
181
- }
182
-
183
- // Wait that element is hidden before refreshing meta tags (to support animations)
184
- const interval = setInterval ( ( ) => {
185
- if ( this . $el && this . $el . offsetParent !== null ) {
186
- /* istanbul ignore next line */
187
- return
188
- }
189
-
190
- clearInterval ( interval )
191
-
192
- triggerUpdate ( options , this . $root , 'destroyed' )
193
- } , 50 )
194
- } )
195
194
}
196
195
}
197
196
}
0 commit comments