Skip to content

Commit

Permalink
fix(computedWithControl): trigger only work in Vue 3
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jul 6, 2022
1 parent 01fca3b commit a107776
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/shared/computedWithControl/index.md
Expand Up @@ -37,6 +37,8 @@ console.log(computedRef.value) // 1

### Manual Triggering

> This only works in Vue 3

This comment has been minimized.

Copy link
@adrianjost

adrianjost Sep 8, 2022

Contributor

@antfu This limitation also broke the useActiveElement implementation in Vue 2, because it's now also using computedWithControl for reactivity. I think this should be documented or fixed somewhere.

https://github.com/vueuse/vueuse/releases/tag/v9.1.1

This comment has been minimized.

Copy link
@vaakian

vaakian Sep 9, 2022

Contributor

did a fix #2186

You can also manually trigger the update of the computed by:

```ts
Expand Down
4 changes: 2 additions & 2 deletions packages/shared/computedWithControl/index.test.ts
@@ -1,4 +1,4 @@
import { ref } from 'vue-demi'
import { isVue3, ref } from 'vue-demi'
import { computedWithControl } from '.'

describe('computedWithControl', () => {
Expand All @@ -19,7 +19,7 @@ describe('computedWithControl', () => {
expect(computed.value).toBe('BAR')
})

it('custom trigger', () => {
it.runIf(isVue3)('custom trigger', () => {
let count = 0
const computed = computedWithControl(() => {}, () => count)

Expand Down
4 changes: 3 additions & 1 deletion packages/shared/computedWithControl/index.ts
Expand Up @@ -67,7 +67,9 @@ export function computedWithControl<T, S>(
}
}) as ComputedRefWithControl<T>

result.trigger = update
if (Object.isExtensible(result))
result.trigger = update

return result
}

Expand Down

0 comments on commit a107776

Please sign in to comment.