Skip to content
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

feat: add diff support for DebounceOptions #18

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

171h
Copy link

@171h 171h commented Jul 3, 2023

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

  • 📖 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)
  • ✨ 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.
  • I have updated the documentation accordingly.

171h added 3 commits July 3, 2023 22:00
Call the `fn` all the way with different arguments. When `different` is true, `leading` and `trailing` will be ignored.
@171h
Copy link
Author

171h commented Jul 6, 2023

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

@afrijaldz
Copy link

when will this PR be merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants