The Wayback Machine - https://web.archive.org/web/20210706191000/https://github.com/vueuse/vueuse/issues/585
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

useToggle: add more methods #585

Closed
revyh opened this issue Jun 21, 2021 · 3 comments
Closed

useToggle: add more methods #585

revyh opened this issue Jun 21, 2021 · 3 comments

Comments

@revyh
Copy link

@revyh revyh commented Jun 21, 2021

The proposition

How about adding more methods to the useToggle and make ref readonly? Like

const showModal = useToggle(initialValue);

showModal.state // readonly ref
showModal.enable() // the same as showModal.value = true
showModal.disable() // the same as showModal.value = false
showModal.toggle() // the same as showModal.value = !showModal.value

Why

  1. currently, users can change ref value, like const [toggler] = useToggle(); toggler.value = 'string value'
  2. it's not aligned with other APIs. E.g. useCouter has set method instead of const counter = useCounter(); counter.counter.value = 10
  3. it's debatable, but I think that showModal.enable() is nicer, terser, and more explicit than showModal.value = true

I can author the PR if needed.

@wheatjs
Copy link
Member

@wheatjs wheatjs commented Jul 4, 2021

This would be a breaking change though, right? Not sure if the tradeoffs are worth it

@revyh
Copy link
Author

@revyh revyh commented Jul 4, 2021

Yes, it would be a breaking change. I can make a pr that you can label by something like "6.0 release" and merge it when you decide to release the next major version.

@antfu
Copy link
Member

@antfu antfu commented Jul 5, 2021

I would prefer toggle(true) for force enabling, just like the classList.toggle(true) in DOM

@antfu antfu closed this in 14f2e28 Jul 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants