ui.util.throttle
Wraps a function to allow it to be called, at most, twice per interval. If the wrapper function is called multiple times before the delay elapses, only the first and the last calls will go through.
Example use: For the callback to a slide event on a ui.Slider. The callback will run immediately, making the slide action feel responsive. The callback is also guaranteed to run after the user has finished interacting with the slider, ensuring that the final callback invocation has access to the slider's final value.
Returns the wrapped function.
Usage | Returns |
---|
ui.util.throttle(func, delay, scope) | Function |
Argument | Type | Details |
---|
func | Function | The function to call. |
delay | Number | The delay, in milliseconds, for the throttle. The function can only be called once after the initial invocation until after the delay has elapsed. |
scope | Object, optional | The object in whose scope to call the function. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[[["Limits a function's execution to at most twice per specified interval, ensuring responsiveness and capturing the final state."],["Useful for scenarios like UI slider events where immediate feedback and final value processing are crucial."],["Wraps the original function and returns a new function that manages the throttling behavior."],["Customizable with a delay parameter (in milliseconds) and an optional scope for execution context."]]],[]]