perfect-debounce icon indicating copy to clipboard operation
perfect-debounce copied to clipboard

feat: add `diff` support for `DebounceOptions`

Open 171h opened this issue 1 year ago โ€ข 2 comments

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.

171h avatar Jul 03 '23 14:07 171h

Hi @pi0 , is it possible for this PR to be merged?

171h avatar Jul 06 '23 11:07 171h

when will this PR be merged?

afrijaldz avatar Sep 13 '24 06:09 afrijaldz