Skip to content

Commit

Permalink
fix(useCloned): check for getter function to watch (#3142)
Browse files Browse the repository at this point in the history
  • Loading branch information
ydcjeff committed Jun 7, 2023
1 parent 9d34afc commit 6d63027
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/core/useCloned/index.test.ts
Expand Up @@ -29,6 +29,18 @@ describe('useCloned', () => {
expect(cloned.value).toEqual(data.value)
})

it('works with getter function', async () => {
const data = ref({ test: 'test' })

const { cloned } = useCloned(() => data.value)

data.value.test = 'success'

await nextTick()

expect(cloned.value).toEqual(data.value)
})

it('works with refs and manual sync', async () => {
const data = ref({ test: 'test' })

Expand Down
2 changes: 1 addition & 1 deletion packages/core/useCloned/index.ts
Expand Up @@ -53,7 +53,7 @@ export function useCloned<T>(
cloned.value = clone(toValue(source))
}

if (!manual && isRef(source)) {
if (!manual && (isRef(source) || typeof source === 'function')) {
watch(source, sync, {
...options,
deep,
Expand Down

0 comments on commit 6d63027

Please sign in to comment.