-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(useLens): new function #4657
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
base: main
Are you sure you want to change the base?
Conversation
Hi maintainers! 👋 I noticed that the Netlify deploy preview is failing (e.g., "netlify/vueuse/deploy-preview" and related checks). After investigating, it seems this issue is not related to my changes in Could you please take a look at the Netlify logs to confirm? I’d be happy to assist if there’s anything on my side that needs adjustment, but I suspect this might be a pre-existing issue in the base branch. Thanks for your time and support! 🙏 |
Hello, thank you very much for your PR! I don't understand the purpose of this function: what's the difference with a writable computed property? |
Hello! Thanks for your feedback and for reviewing my PR. I’ll clarify how useLens differs from a writable computed property. const source = reactive({ profile: { name: 'Alice' } });
const name = useLens(source, (s) => s.profile.name, { fallback: 'Guest' }); // Concise and flexible useLens fits VueUse’s goal of providing reusable reactive utilities, addressing nested reactivity challenges with a robust API. I’d be happy to adjust based on your feedback. Looking forward to your thoughts! |
Co-authored-by: Robin <robin.kehl@singular-it.de>
Co-authored-by: Robin <robin.kehl@singular-it.de>
Before submitting the PR, please make sure you do the following
fixes #123
).Description
This PR introduces
useLens
, a new composable that provides a reactive, type-safe way to access and modify nested properties inRef
orreactive
objects. It solves the problem of verbose and error-prone nested property management by offering a singleWritableComputedRef
with support for fallbacks and transformations.obj.a.b.c
) without manual path handling or reactivity boilerplate.fallback
,transform
,onGet
, andonSet
for customization.Changes: Adds useLens implementation, tests, and documentation in packages/core/useLens/.
Additional context
Motivation: Nested property access in Vue often requires repetitive code. useLens offers a reusable, reactive solution tailored for Vue’s ecosystem.
Implementation: Uses Proxy to parse selectors, computed for reactivity, and overloads for type flexibility.
Tests: Covers basic usage, fallbacks, transformations, arrays, and errors using Vitest.
Fit for VueUse: Enhances the Reactivity category with a lightweight, type-safe utility.
Reviewer Focus: Please check type overloads, test coverage, and documentation clarity. Given the "Slowing down new functions" note, I’d value input on its community value.