File tree 2 files changed +39
-5
lines changed
2 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ import {
27
27
shallowRef ,
28
28
Ref
29
29
} from '@vue/reactivity'
30
+ import { watchPostEffect } from '../src/apiWatch'
30
31
31
32
// reference: https://vue-composition-api-rfc.netlify.com/api.html#watch
32
33
@@ -363,6 +364,32 @@ describe('api: watch', () => {
363
364
expect ( result ) . toBe ( true )
364
365
} )
365
366
367
+ it ( 'watchPostEffect' , async ( ) => {
368
+ const count = ref ( 0 )
369
+ let result
370
+ const assertion = jest . fn ( count => {
371
+ result = serializeInner ( root ) === `${ count } `
372
+ } )
373
+
374
+ const Comp = {
375
+ setup ( ) {
376
+ watchPostEffect ( ( ) => {
377
+ assertion ( count . value )
378
+ } )
379
+ return ( ) => count . value
380
+ }
381
+ }
382
+ const root = nodeOps . createElement ( 'div' )
383
+ render ( h ( Comp ) , root )
384
+ expect ( assertion ) . toHaveBeenCalledTimes ( 1 )
385
+ expect ( result ) . toBe ( true )
386
+
387
+ count . value ++
388
+ await nextTick ( )
389
+ expect ( assertion ) . toHaveBeenCalledTimes ( 2 )
390
+ expect ( result ) . toBe ( true )
391
+ } )
392
+
366
393
it ( 'flush timing: sync' , async ( ) => {
367
394
const count = ref ( 0 )
368
395
const count2 = ref ( 0 )
Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ import {
3
3
Ref ,
4
4
ComputedRef ,
5
5
ReactiveEffect ,
6
- ReactiveEffectOptions ,
7
6
isReactive ,
8
7
ReactiveFlags ,
9
- EffectScheduler
8
+ EffectScheduler ,
9
+ DebuggerOptions
10
10
} from '@vue/reactivity'
11
11
import { SchedulerJob , queuePreFlushCb } from './scheduler'
12
12
import {
@@ -58,10 +58,8 @@ type MapSources<T, Immediate> = {
58
58
59
59
type InvalidateCbRegistrator = ( cb : ( ) => void ) => void
60
60
61
- export interface WatchOptionsBase {
61
+ export interface WatchOptionsBase extends DebuggerOptions {
62
62
flush ?: 'pre' | 'post' | 'sync'
63
- onTrack ?: ReactiveEffectOptions [ 'onTrack' ]
64
- onTrigger ?: ReactiveEffectOptions [ 'onTrigger' ]
65
63
}
66
64
67
65
export interface WatchOptions < Immediate = boolean > extends WatchOptionsBase {
@@ -79,6 +77,15 @@ export function watchEffect(
79
77
return doWatch ( effect , null , options )
80
78
}
81
79
80
+ export function watchPostEffect (
81
+ effect : WatchEffect ,
82
+ options ?: DebuggerOptions
83
+ ) {
84
+ return doWatch ( effect , null , ( __DEV__
85
+ ? Object . assign ( options || { } , { flush : 'post' } )
86
+ : { flush : 'post' } ) as WatchOptionsBase )
87
+ }
88
+
82
89
// initial value for watchers to trigger on undefined initial values
83
90
const INITIAL_WATCHER_VALUE = { }
84
91
You can’t perform that action at this time.
0 commit comments