fix(runtime-core): make watchEffect ignore deep option (#765)

This commit is contained in:
djy0 2020-02-25 01:03:02 +08:00 committed by GitHub
parent c11905fe36
commit 19a799c28b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View File

@ -410,6 +410,24 @@ describe('api: watch', () => {
expect(dummy).toBe(1)
})
it('warn and not respect deep option when using effect', async () => {
const arr = ref([1, [2]])
let spy = jest.fn()
watchEffect(
() => {
spy()
return arr
},
// @ts-ignore
{ deep: true }
)
expect(spy).toHaveBeenCalledTimes(1)
;(arr.value[1] as Array<number>)[0] = 3
await nextTick()
expect(spy).toHaveBeenCalledTimes(1)
expect(`"deep" option is only respected`).toHaveBeenWarned()
})
it('onTrack', async () => {
const events: DebuggerEvent[] = []
let dummy

View File

@ -139,13 +139,13 @@ function doWatch(
if (immediate !== undefined) {
warn(
`watch() "immediate" option is only respected when using the ` +
`watch(source, callback) signature.`
`watch(source, callback, options?) signature.`
)
}
if (deep !== undefined) {
warn(
`watch() "deep" option is only respected when using the ` +
`watch(source, callback) signature.`
`watch(source, callback, options?) signature.`
)
}
}
@ -186,7 +186,7 @@ function doWatch(
}
}
if (deep) {
if (cb && deep) {
const baseGetter = getter
getter = () => traverse(baseGetter())
}