This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
simple method for time-throttling action / message propogation
version 3.0.1
license BSD3
native-modules False
elm-version 0.18.0 <= v < 0.19.0
Tag 3.0.2
Committed At 2016-12-25 07:08:54 UTC
elm-lang/core 5.0.0 <= v < 6.0.0 5.1.1

Modules

README

Elm-Debouncer

Use continutations for deboucing!

import Debouncer
import Task exposing (Task)

type Msg
  = PingFoo
  | PungFoo
  | DebouncerMsg (Debouncer.Msg Msg)

type alias Model =
  { something   : Foo
  , myDebouncer : Debouncer.Model Msg
  }

init : Model
init =
  { something   = initFoo
  , myDebouncer = Debouncer.init
  }

mkCmd : a -> Cmd a
mkCmd = Task.perform (Debug.crash << toString) identity << Task.succeed


update : Msg
      -> Model
      -> (Model, Cmd Msg)
update action model =
  case action of
    PingFoo -> model ! [mkCmd <| DebouncerMsg <| Debouncer.Bounce <| mkCmd PungFoo]
    PungFoo -> pang model ! [] -- the past tense of ping or something
    DebouncerMsg a ->
      let (newDebouncer, eff) = updateDebouncer
                                  (500 * millisecond)
                                  a
                                  model.myDebouncer
      in  { model | myDebouncer = newDebouncer }
        ! [ Cmd.map (\r -> case r of
                             Err a' -> DebouncerMsg a'
                             Ok  a' -> a') eff ]