Title: [199676] trunk/Source/WebInspectorUI
- Revision
- 199676
- Author
- [email protected]
- Date
- 2016-04-18 10:28:36 -0700 (Mon, 18 Apr 2016)
Log Message
Web Inspector: Fix the debounce function
https://bugs.webkit.org/show_bug.cgi?id=156696
rdar://problem/25778133
Reviewed by Brian Burg.
* UserInterface/Base/Utilities.js:
(Function.prototype.debounce): Store the timeout on the original function instead
of the bound function. Also simplify the implementation with arrow functions
and eliminate the bind altogether.
Modified Paths
Diff
Modified: trunk/Source/WebInspectorUI/ChangeLog (199675 => 199676)
--- trunk/Source/WebInspectorUI/ChangeLog 2016-04-18 17:13:33 UTC (rev 199675)
+++ trunk/Source/WebInspectorUI/ChangeLog 2016-04-18 17:28:36 UTC (rev 199676)
@@ -1,3 +1,17 @@
+2016-04-18 Timothy Hatcher <[email protected]>
+
+ Web Inspector: Fix the debounce function
+
+ https://bugs.webkit.org/show_bug.cgi?id=156696
+ rdar://problem/25778133
+
+ Reviewed by Brian Burg.
+
+ * UserInterface/Base/Utilities.js:
+ (Function.prototype.debounce): Store the timeout on the original function instead
+ of the bound function. Also simplify the implementation with arrow functions
+ and eliminate the bind altogether.
+
2016-04-16 Matt Baker <[email protected]>
Web Inspector: Adopt Number.prototype.toLocaleString For All Sizes and Times
Modified: trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js (199675 => 199676)
--- trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js 2016-04-18 17:13:33 UTC (rev 199675)
+++ trunk/Source/WebInspectorUI/UserInterface/Base/Utilities.js 2016-04-18 17:28:36 UTC (rev 199676)
@@ -1194,17 +1194,23 @@
});
(function() {
+ // The `debounce` function lets you call a function with a delay and
+ // if the function keeps getting called, the delay gets reset.
+ // Note: The last call's arguments end being the ones that get used.
+ // Use: foo.bar.debounce(200, foo)("Argument 1", "Argument 2")
+
const debounceSymbol = Symbol("function-debounce-timeout");
+
Object.defineProperty(Function.prototype, "debounce",
{
value: function(delay, thisObject)
{
- 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);
};
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes