athanclark / elm-debouncer / Debounce

This is a delay-based debouncer, where given a minimum delay and an action to issue, we'll build a stateful component that will eventually issue the action once, after being given a slew of requests within the delay timeframe.

Debouncer State


type alias Model a =
{ elapsed : Maybe (Elapsed a) }

The state of the debouncer

init : Model a

The initial debouncer

Starting the Debouncer


type Msg a
    = Bounce (Platform.Cmd.Cmd a)
    | Assign (Platform.Cmd.Cmd a) Time.Posix
    | Finish Time.Posix

To bounce the debouncer, just make multiple calls to Bounce.

Evaluating the Debouncer

update : Time.Posix -> Msg a -> Model a -> ( Model a, Platform.Cmd.Cmd (Result (Msg a) a) )

The main logic of the debouncer.