Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toRefs not working correctly with writable computed refs #885

Closed
wtykirby opened this issue Oct 26, 2021 · 0 comments · Fixed by #895
Closed

toRefs not working correctly with writable computed refs #885

wtykirby opened this issue Oct 26, 2021 · 0 comments · Fixed by #895

Comments

@wtykirby
Copy link
Contributor

If you use toRefs with a writable computed the set method is never executed.

Here is an example:

import { ref, computed } from 'vue';
import { toRefs } from '@vueuse/core';

const x = ref({ bar: 'Bar' });

const foo = computed<{ bar: string }>({
  get() {
    return x.value;
  },
  set(v) {
    console.log('Setting value', v); // Never called
    x.value = v;
  }
});

const { bar } = toRefs(foo);
bar.value = 'Baz';

Although both bar and x will have their underlying values updated in this example, it does not go through the set method as expected. This prevents toRefs from being used with other methods that return writable computed refs like useVModel. In one of the example use cases with useVModel the "update:data" is never actually emitted like it shows.

If this sounds like a legitimate issue I would like to open a PR to resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant