Skip to content

Commit

Permalink
fix(runtime-core): make watchEffect ignore deep option (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangying000 authored Feb 24, 2020
1 parent c11905f commit 19a799c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
18 changes: 18 additions & 0 deletions packages/runtime-core/__tests__/apiWatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
)
}
}
Expand Down Expand Up @@ -186,7 +186,7 @@ function doWatch(
}
}

if (deep) {
if (cb && deep) {
const baseGetter = getter
getter = () => traverse(baseGetter())
}
Expand Down

0 comments on commit 19a799c

Please sign in to comment.