@@ -29,7 +29,6 @@ import {
29
29
callWithErrorHandling ,
30
30
callWithAsyncErrorHandling
31
31
} from './errorHandling'
32
- import { onBeforeUnmount } from './apiLifecycle'
33
32
import { queuePostRenderEffect } from './renderer'
34
33
import { warn } from './warning'
35
34
@@ -134,7 +133,8 @@ export function watch<T = any>(
134
133
function doWatch (
135
134
source : WatchSource | WatchSource [ ] | WatchEffect ,
136
135
cb : WatchCallback | null ,
137
- { immediate, deep, flush, onTrack, onTrigger } : WatchOptions = EMPTY_OBJ
136
+ { immediate, deep, flush, onTrack, onTrigger } : WatchOptions = EMPTY_OBJ ,
137
+ instance = currentInstance
138
138
) : WatchStopHandle {
139
139
if ( __DEV__ && ! cb ) {
140
140
if ( immediate !== undefined ) {
@@ -160,8 +160,6 @@ function doWatch(
160
160
)
161
161
}
162
162
163
- const instance = currentInstance
164
-
165
163
let getter : ( ) => any
166
164
if ( isArray ( source ) ) {
167
165
getter = ( ) =>
@@ -316,9 +314,7 @@ export function instanceWatch(
316
314
const getter = isString ( source )
317
315
? ( ) => publicThis [ source ]
318
316
: source . bind ( publicThis )
319
- const stop = watch ( getter , cb . bind ( publicThis ) , options )
320
- onBeforeUnmount ( stop , this )
321
- return stop
317
+ return doWatch ( getter , cb . bind ( publicThis ) , options , this )
322
318
}
323
319
324
320
function traverse ( value : unknown , seen : Set < unknown > = new Set ( ) ) {
0 commit comments