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

The definition of debouncing does not match its actual meaning #36064

Open
TinaMorskaya opened this issue Sep 26, 2024 · 3 comments
Open

The definition of debouncing does not match its actual meaning #36064

TinaMorskaya opened this issue Sep 26, 2024 · 3 comments
Labels
Content:Glossary Glossary entries

Comments

@TinaMorskaya
Copy link

TinaMorskaya commented Sep 26, 2024

MDN URL

https://developer.mozilla.org/en-US/docs/Glossary/Debounce

What specific section or headline is this issue about?

Definition: The first paragraph and part of the second paragraph

What information was incorrect, unhelpful, or incomplete?

Debouncing, in the context of programming, means to "batch" all operations requested during a specific interval into a single invocation.

consolidate many noisy invocations into one single invocation.

What did you expect to see?

Debouncing is a programming practice used to ensure that time-consuming tasks do not fire so often, typically by delaying the execution of a function until after a certain amount of time has passed since it was last invoked. The timer is reset if the function is invoked again during this wait time.

Key points about debouncing:

1. It delays the execution of a function.
2. It does not accumulate or "batch" multiple calls.
3. Only the last call within the specified time frame is executed.

Do you have any supporting links, references, or citations?

I've googled and found no resources where debouncing means batching, except MDN.
As I know, In programming, "batching" typically refers to grouping multiple operations together for processing, which is not what debouncing does.

The first resources which you can find by googling about debouncing:

Do you have anything more you want to share?

The simplest version of the debounce function in JS:

export const debounce = (callback, wait) => {
    let timeout = null;

    const cancel = () => {
        if (timeout) {
            clearTimeout(timeout);
        }
    }

    const debouncedFunction = (...args) => {
        cancel();
        timeout = setTimeout(() => {
            callback(...args);
        }, wait);
    };

    return {debouncedFunction, cancel};
};

MDN metadata

Page report details
@TinaMorskaya TinaMorskaya added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Sep 26, 2024
@github-actions github-actions bot added the Content:Glossary Glossary entries label Sep 26, 2024
@Josh-Cena
Copy link
Member

Sure, I see how the current wording is non-ideal, but it would be a bit hard to rephrase. The idea is that there's no "aggregation"; previous calls are simply ignored.

@Josh-Cena Josh-Cena removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Sep 26, 2024
@bsmth
Copy link
Member

bsmth commented Sep 26, 2024

Thanks for raising. There's some other hints from the dictionary:

  • To discard events or signals that should not be processed because they occurred too close together

Regarding this point "It delays the execution of a function" - this might not always be true, and it depends on your implementation / usage. You might let the first event through, for instance, and debounce everything afterwards, or this could kick in when there's a certain frequency occurring AFAIK.

@TinaMorskaya
Copy link
Author

@bsmth You are right, it depends on the implementation. I'll remove this point.

@Josh-Cena Yeah, it might be, but the current description is misleading, and I think it will be better to correct it.

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

No branches or pull requests

3 participants