https://github.com/athanclark/elm-debouncer
Debouncification for elm-ness
https://github.com/athanclark/elm-debouncer
debounce elm
Last synced: 10 months ago
JSON representation
Debouncification for elm-ness
- Host: GitHub
- URL: https://github.com/athanclark/elm-debouncer
- Owner: athanclark
- License: bsd-3-clause
- Created: 2016-05-12T20:40:00.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2019-08-22T15:03:33.000Z (almost 7 years ago)
- Last Synced: 2025-04-02T07:11:48.436Z (about 1 year ago)
- Topics: debounce, elm
- Language: Elm
- Size: 17.6 KB
- Stars: 8
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elm-Debouncer
Use continutations for deboucing!
```elm
import Debounce
import Task exposing (Task)
import Time exposing (millisToPosix)
type Msg
= PingFoo
| PungFoo
| DebouncerMsg (Debounce.Msg Msg)
type alias Model =
{ something : Foo
, myDebouncer : Debounce.Model Msg
}
init : Model
init =
{ something = initFoo
, myDebouncer = Debounce.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 <| Debounce.Bounce <| mkCmd PungFoo]
PungFoo -> pang model ! [] -- the past tense of ping or something
DebouncerMsg a ->
let (newDebouncer, eff) = updateDebouncer
(millisToPosix 500)
a
model.myDebouncer
in { model | myDebouncer = newDebouncer }
! [ Cmd.map (\r -> case r of
Err a' -> DebouncerMsg a'
Ok a' -> a') eff ]
```