-
-
Notifications
You must be signed in to change notification settings - Fork 262
Open
Labels
Milestone
Description
Preface - valibot is awesome
Thank you all for developing this library.
It is the most type-safe library, I have ever used.
It comes with great DX & the docs become better and better.
Use Case
Forms:
- Sometimes we need to validate certain fields asynchronously.
- It would be nice if the schema could cache certain inputs and the results of the asynchronous validations to not trigger asynchronous operations if not needed.
New action memoize
Wouldn't it be nice if we could memoize
the executions inside a schema, where it is needed?
We could provide a synchronous and an asynchronous version...
memoize
memoizeAsync
Example
v.pipeAsync(
v.string(),
v.memoizeAsync(
v.customAsync(input => fetch(`/api/email/${input}`).then(() => /* ... */)), {
buffer: 10, // default 1 - tells how many inputs with their respective result are cached
itemExpiryInMs: 30_000 // default 5_000
})
)
fabian-hiller, JustGreg, EltonLobo07 and HymanZHAN
Metadata
Metadata
Assignees
Labels
Projects
Milestone
Relationships
Development
Select code repository
Activity
fabian-hiller commentedon Nov 13, 2024
Great idea! What is
buffer
doing? We could work onmemoize
while also working on adebounce
function.GregOnNet commentedon Nov 13, 2024
Oh, yeah
buffer
… I thought it would be handy to be able to tell how many items are cached...Example:
gregor@domain.de
which triggers an API call from the async validatorgregor@domain.uk
which is calling the API againgregor@domain.de
which is not calling the API because the outcome of the validation is still cached and not outdated.I hope clarifies the use-case a bit better.
I also like the idea of having
debounce
for certain values. 💪🏻GregOnNet commentedon Nov 14, 2024
After writing the example above, I started thinking if we are talking about
cache & cacheAsync
instead of Memoization…fabian-hiller commentedon Nov 15, 2024
I posted this issue on X to get more feedback and ideas from other users. I am currently focusing on Valibot v1 and Standard Schema and think I will work on this issue after our stable v1 is out.
dosubot commentedon Aug 6, 2025
Hi, @GregOnNet. I'm Dosu, and I'm helping the Valibot team manage their backlog and am marking this issue as stale.
Issue Summary:
Next Steps:
Thanks for your understanding and contribution!
GregOnNet commentedon Aug 8, 2025
Hi,
it might be relevant especially for form validation with async validations.
But Fabian is also working on formish, that might solve this use-case.
So maybe double check with Fabian.
It is fine to close it unless there is a bigger need.