Debounce or throttle your actions.
The configuration for a debouncer.
The configuration options used by the trailing,
leading, and throttle configuration constructors.
wait: A non-negative (>= 0) integer that represents the number of
milliseconds to delay. Its exact meaning depends on the configuration
constructor you've used.onReady: The message constructor to use to create the message that will be
sent to your update function when it's time to perform the action you've been
delaying.onChange: Convert Msg to your message type. Basically, say
how to Cmd.map the commands that will be returned from call and
update.Create the configuration for a trailing edge debouncer.
Suppose wait = 400ms, then you can expect the following behaviour:
--aaa--a-a--a-----b---b-bb--b-------c-------
-----------------a---------------b-------c--Note: Each - represents 100ms.
Play with the trailing edge demo to better understand how this configuration really works.
Create the configuration for a leading edge debouncer.
Suppose wait = 400ms, then you can expect the following behaviour:
--aaa--a-a--a-----b---b-bb--b-------c-------
--a---------------b-----------------c-------Note: Each - represents 100ms.
Play with the leading edge demo to better understand how this configuration really works.
Create the configuration for a throttler.
Suppose wait = 400ms, then you can expect the following behaviour:
--aaa--a-a--a-----b---b-bb--b-------c-------
--a---a----a----a-b---b----b----b---c-------Note: Each - represents 100ms.
Play with the throttle demo to better understand how this configuration really works.
The configuration options used by the custom configuration constructor.
invokeOnLeading: Whether or not to send the onReady constructed message
immediately upon calling call.invokeOnTrailing: Whether or not to send the onReady constructed message
wait milliseconds after you last called call.maxWait: If it's Just n then n is a non-negative integer (>= wait)
that represents the maximum number of milliseconds to delay. Once that time is
up the onReady constructed message is sent.Note 1: wait, onReady, and onChange are the same as in
SimpleConfigOptions.
Note 2: The custom configuration options were heavily influenced by Lodash's debounce function.
Call this function instead of performing the action which you want to
delay. It will update the debouncer and determine when to send the onReady arg
message.
onReady: The message constructor you set when creating your configuration.arg: The argument, of type a, you passed to call.You handle the onReady arg message by performing the action which you've been
delaying.
Update the debouncer and determine when to send the onReady lastArg
message.
onReady: The message constructor you set when creating your configuration.lastArg: The argument, of type a, that you passed the last time you
invoked call.You handle the onReady lastArg message by performing the action which you've
been delaying.
The type variable
arepresents the type of the argument the action depends upon.For e.g. if you're debouncing a search field, your ability to perform the search will most likely depend upon a query string. So, in this case,
awill beString.