File tree 2 files changed +15
-10
lines changed
2 files changed +15
-10
lines changed Original file line number Diff line number Diff line change @@ -206,18 +206,26 @@ export function watch(
206
206
getter = ( ) => traverse ( baseGetter ( ) , depth )
207
207
}
208
208
209
+ const scope = getCurrentScope ( )
210
+ const watchHandle : WatchHandle = ( ) => {
211
+ effect . stop ( )
212
+ if ( scope ) {
213
+ remove ( scope . effects , effect )
214
+ }
215
+ }
216
+
209
217
if ( once ) {
210
218
if ( cb ) {
211
219
const _cb = cb
212
220
cb = ( ...args ) => {
213
221
_cb ( ...args )
214
- effect . stop ( )
222
+ watchHandle ( )
215
223
}
216
224
} else {
217
225
const _getter = getter
218
226
getter = ( ) => {
219
227
_getter ( )
220
- effect . stop ( )
228
+ watchHandle ( )
221
229
}
222
230
}
223
231
}
@@ -317,14 +325,6 @@ export function watch(
317
325
effect . run ( )
318
326
}
319
327
320
- const scope = getCurrentScope ( )
321
- const watchHandle : WatchHandle = ( ) => {
322
- effect . stop ( )
323
- if ( scope ) {
324
- remove ( scope . effects , effect )
325
- }
326
- }
327
-
328
328
watchHandle . pause = effect . pause . bind ( effect )
329
329
watchHandle . resume = effect . resume . bind ( effect )
330
330
watchHandle . stop = watchHandle
Original file line number Diff line number Diff line change @@ -1771,6 +1771,11 @@ describe('api: watch', () => {
1771
1771
expect ( scope . effects . length ) . toBe ( 1 )
1772
1772
unwatch ! ( )
1773
1773
expect ( scope . effects . length ) . toBe ( 0 )
1774
+
1775
+ scope . run ( ( ) => {
1776
+ watch ( num , ( ) => { } , { once : true , immediate : true } )
1777
+ } )
1778
+ expect ( scope . effects . length ) . toBe ( 0 )
1774
1779
} )
1775
1780
1776
1781
// simplified case of VueUse syncRef
You can’t perform that action at this time.
0 commit comments