File tree 2 files changed +16
-6
lines changed
2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -69,6 +69,16 @@ describe('api: watch', () => {
69
69
expect ( dummy ) . toMatchObject ( [ 1 , 0 ] )
70
70
} )
71
71
72
+ it ( 'watching single source: array' , async ( ) => {
73
+ const array = reactive ( [ ] as number [ ] )
74
+ const spy = jest . fn ( )
75
+ watch ( array , spy )
76
+ array . push ( 1 )
77
+ await nextTick ( )
78
+ expect ( spy ) . toBeCalledTimes ( 1 )
79
+ expect ( spy ) . toBeCalledWith ( [ 1 ] , expect . anything ( ) , expect . anything ( ) )
80
+ } )
81
+
72
82
it ( 'watching single source: computed ref' , async ( ) => {
73
83
const count = ref ( 0 )
74
84
const plus = computed ( ( ) => count . value + 1 )
Original file line number Diff line number Diff line change @@ -159,7 +159,12 @@ function doWatch(
159
159
}
160
160
161
161
let getter : ( ) => any
162
- if ( isArray ( source ) ) {
162
+ if ( isRef ( source ) ) {
163
+ getter = ( ) => source . value
164
+ } else if ( isReactive ( source ) ) {
165
+ getter = ( ) => source
166
+ deep = true
167
+ } else if ( isArray ( source ) ) {
163
168
getter = ( ) =>
164
169
source . map ( s => {
165
170
if ( isRef ( s ) ) {
@@ -172,11 +177,6 @@ function doWatch(
172
177
__DEV__ && warnInvalidSource ( s )
173
178
}
174
179
} )
175
- } else if ( isRef ( source ) ) {
176
- getter = ( ) => source . value
177
- } else if ( isReactive ( source ) ) {
178
- getter = ( ) => source
179
- deep = true
180
180
} else if ( isFunction ( source ) ) {
181
181
if ( cb ) {
182
182
// getter with cb
You can’t perform that action at this time.
0 commit comments