perfect-debounce
perfect-debounce copied to clipboard
feat: add `diff` support for `DebounceOptions`
If you want to always execute functions with different parameters, please set diff: true
option. Note that when diff
is true, leading
and trailing
will be ignored.
const debounced = debounce(async (args) => {
// Some heavy stuff
}, 25, { diff: false })
test.concurrent("multiple calls with option.dirrence = true", async () => {
let count = 0;
const end = timeSpan();
const debounced = debounce(async (value) => {
count++;
await delay(50);
return value;
}, 100, { diff: true });
const results = await Promise.all(
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 1, 1, 2, 3].map((value) => debounced(value))
);
expect(results).toMatchObject([1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 6, 1, 1, 2, 3]);
expect(count).toBe(6);
await delay(110);
expect(await debounced(10)).toBe(10);
});
๐ Linked issue
โ Type of change
- [x] ๐ Documentation (updates to the documentation, readme, or JSdoc annotations)
- [ ] ๐ Bug fix (a non-breaking change that fixes an issue)
- [ ] ๐ Enhancement (improving an existing functionality like performance)
- [x] โจ New feature (a non-breaking change that adds functionality)
- [ ] ๐งน Chore (updates to the build process or auxiliary tools and libraries)
- [ ] โ ๏ธ Breaking change (fix or feature that would cause existing functionality to change)
๐ Description
๐ Checklist
- [ ] I have linked an issue or discussion.
- [x] I have updated the documentation accordingly.
Hi @pi0 , is it possible for this PR to be merged?
when will this PR be merged?