])
})
+ it('watching multiple sources: undefined initial values and immediate: true', async () => {
+ const a = ref()
+ const b = ref()
+ let called = false
+ watch(
+ [a, b],
+ (newVal, oldVal) => {
+ called = true
+ expect(newVal).toMatchObject([undefined, undefined])
+ expect(oldVal).toBeUndefined()
+ },
+ { immediate: true }
+ )
+ await nextTick()
+ expect(called).toBe(true)
+ })
+
it('watching multiple sources: readonly array', async () => {
const state = reactive({ count: 1 })
const status = ref(false)
return NOOP
}
- let oldValue = isMultiSource ? [] : INITIAL_WATCHER_VALUE
+ let oldValue: any = isMultiSource
+ ? new Array((source as []).length).fill(INITIAL_WATCHER_VALUE)
+ : INITIAL_WATCHER_VALUE
const job: SchedulerJob = () => {
if (!effect.active) {
return
callWithAsyncErrorHandling(cb, instance, ErrorCodes.WATCH_CALLBACK, [
newValue,
// pass undefined as the old value when it's changed for the first time
- oldValue === INITIAL_WATCHER_VALUE ? undefined : oldValue,
+ oldValue === INITIAL_WATCHER_VALUE ||
+ (isMultiSource && oldValue[0] === INITIAL_WATCHER_VALUE)
+ ? undefined
+ : oldValue,
onCleanup
])
oldValue = newValue