Skip to content

How to debounce a global validator? #3605

Answered by logaretm
laferte-tech asked this question in Q&A
Discussion options

You must be logged in to vote

A regular debounce won't work because you need to preserve the return value of the validation function. Most debounce functions in libraries like lodash and others are not built to handle this.

What you actually need is not a debounce function per se, but more of a "promise-batcher". as In you combine multiple calls to the async function into a single call within a timeframe which is kinda what you want here. And because promises are chainable and nestable, you could batch them using a function like this one.

Here is an example:

https://codesandbox.io/s/flamboyant-field-d2220?file=/src/main.js

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@laferte-tech
Comment options

Answer selected by laferte-tech
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants