Bug 156696 - Web Inspector: Fix the debounce function
Summary: Web Inspector: Fix the debounce function
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: WebKit Local Build
Hardware: All All
: P2 Normal
Assignee: Timothy Hatcher
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2016-04-18 07:52 PDT by Timothy Hatcher
Modified: 2016-04-18 13:43 PDT (History)
7 users (show)

See Also:


Attachments
Patch (2.05 KB, patch)
2016-04-18 08:15 PDT, Timothy Hatcher
bburg: review+
timothy: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Timothy Hatcher 2016-04-18 07:52:04 PDT
It puts the symbol on the bound function, not the original.
Comment 1 Radar WebKit Bug Importer 2016-04-18 07:52:19 PDT
<rdar://problem/25778133>
Comment 2 Timothy Hatcher 2016-04-18 08:15:43 PDT
Created attachment 276638 [details]
Patch
Comment 3 BJ Burg 2016-04-18 08:53:44 PDT
Comment on attachment 276638 [details]
Patch

r=me

Could you include a short description of how to use this function? I had to go over to underscore.js to confirm what I thought was going on.
Comment 4 Timothy Hatcher 2016-04-18 10:29:07 PDT
https://trac.webkit.org/changeset/199676
Comment 5 Joseph Pecoraro 2016-04-18 13:43:38 PDT
Comment on attachment 276638 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=276638&action=review

> Source/WebInspectorUI/UserInterface/Base/Utilities.js:1210
> -            let callback = this.bind(thisObject);
> -            return function() {
> -                clearTimeout(callback[debounceSymbol]);
> +            return () => {
> +                clearTimeout(this[debounceSymbol]);
> +
>                  let args = arguments;
> -                callback[debounceSymbol] = setTimeout(() => {
> -                    callback.apply(null, args);
> +                this[debounceSymbol] = setTimeout(() => {
> +                    this.apply(thisObject, args);
>                  }, delay);
>              };

I don't think this works. Because the "arguments" here are not the correct arguments.

Looking back at the original bug:
https://bugs.webkit.org/show_bug.cgi?id=152655

Maybe this can be reduced to:

    value: function(delay, thisObject)
    {
        return (...args) => {
            clearTimeout(this[debounceSymbol]);
            this[debounceSymbol] = setTimeout(this.bind(thisObject), delay, ...args);
        }
    }

We could add a unit-test for this.