parent
d39c03771b
commit
288b4eab9e
@ -69,6 +69,16 @@ describe('api: watch', () => {
|
|||||||
expect(dummy).toMatchObject([1, 0])
|
expect(dummy).toMatchObject([1, 0])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('watching single source: array', async () => {
|
||||||
|
const array = reactive([] as number[])
|
||||||
|
const spy = jest.fn()
|
||||||
|
watch(array, spy)
|
||||||
|
array.push(1)
|
||||||
|
await nextTick()
|
||||||
|
expect(spy).toBeCalledTimes(1)
|
||||||
|
expect(spy).toBeCalledWith([1], expect.anything(), expect.anything())
|
||||||
|
})
|
||||||
|
|
||||||
it('watching single source: computed ref', async () => {
|
it('watching single source: computed ref', async () => {
|
||||||
const count = ref(0)
|
const count = ref(0)
|
||||||
const plus = computed(() => count.value + 1)
|
const plus = computed(() => count.value + 1)
|
||||||
|
@ -159,7 +159,12 @@ function doWatch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let getter: () => any
|
let getter: () => any
|
||||||
if (isArray(source)) {
|
if (isRef(source)) {
|
||||||
|
getter = () => source.value
|
||||||
|
} else if (isReactive(source)) {
|
||||||
|
getter = () => source
|
||||||
|
deep = true
|
||||||
|
} else if (isArray(source)) {
|
||||||
getter = () =>
|
getter = () =>
|
||||||
source.map(s => {
|
source.map(s => {
|
||||||
if (isRef(s)) {
|
if (isRef(s)) {
|
||||||
@ -172,11 +177,6 @@ function doWatch(
|
|||||||
__DEV__ && warnInvalidSource(s)
|
__DEV__ && warnInvalidSource(s)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else if (isRef(source)) {
|
|
||||||
getter = () => source.value
|
|
||||||
} else if (isReactive(source)) {
|
|
||||||
getter = () => source
|
|
||||||
deep = true
|
|
||||||
} else if (isFunction(source)) {
|
} else if (isFunction(source)) {
|
||||||
if (cb) {
|
if (cb) {
|
||||||
// getter with cb
|
// getter with cb
|
||||||
|
Loading…
Reference in New Issue
Block a user