11import config from '../config'
2- import Watcher from '../observer/watcher'
2+ import Watcher , { WatcherOptions } from '../observer/watcher'
33import { mark , measure } from '../util/perf'
44import VNode , { createEmptyVNode } from '../vdom/vnode'
55import { updateComponentListeners } from './events'
@@ -192,20 +192,27 @@ export function mountComponent(
192192 }
193193 }
194194
195+ const watcherOptions : WatcherOptions = {
196+ before ( ) {
197+ if ( vm . _isMounted && ! vm . _isDestroyed ) {
198+ callHook ( vm , 'beforeUpdate' )
199+ }
200+ }
201+ }
202+
203+ if ( __DEV__ ) {
204+ watcherOptions . onTrack = e => callHook ( vm , 'renderTracked' , [ e ] )
205+ watcherOptions . onTrigger = e => callHook ( vm , 'renderTriggered' , [ e ] )
206+ }
207+
195208 // we set this to vm._watcher inside the watcher's constructor
196209 // since the watcher's initial patch may call $forceUpdate (e.g. inside child
197210 // component's mounted hook), which relies on vm._watcher being already defined
198211 new Watcher (
199212 vm ,
200213 updateComponent ,
201214 noop ,
202- {
203- before ( ) {
204- if ( vm . _isMounted && ! vm . _isDestroyed ) {
205- callHook ( vm , 'beforeUpdate' )
206- }
207- }
208- } ,
215+ watcherOptions ,
209216 true /* isRenderWatcher */
210217 )
211218 hydrating = false
@@ -365,7 +372,7 @@ export function deactivateChildComponent(vm: Component, direct?: boolean) {
365372 }
366373}
367374
368- export function callHook ( vm : Component , hook : string ) {
375+ export function callHook ( vm : Component , hook : string , args ?: any [ ] ) {
369376 // #7573 disable dep collection when invoking lifecycle hooks
370377 pushTarget ( )
371378 const prev = currentInstance
@@ -374,7 +381,7 @@ export function callHook(vm: Component, hook: string) {
374381 const info = `${ hook } hook`
375382 if ( handlers ) {
376383 for ( let i = 0 , j = handlers . length ; i < j ; i ++ ) {
377- invokeWithErrorHandling ( handlers [ i ] , vm , null , vm , info )
384+ invokeWithErrorHandling ( handlers [ i ] , vm , args || null , vm , info )
378385 }
379386 }
380387 if ( vm . _hasHookEvent ) {
0 commit comments