Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrewmacmurray/elm-delay
Utilities to delay updates after a set period of time
https://github.com/andrewmacmurray/elm-delay
delay elm sequence settimeout
Last synced: 9 days ago
JSON representation
Utilities to delay updates after a set period of time
- Host: GitHub
- URL: https://github.com/andrewmacmurray/elm-delay
- Owner: andrewMacmurray
- License: bsd-3-clause
- Created: 2017-05-07T11:50:17.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2023-01-07T23:26:47.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T20:08:56.049Z (24 days ago)
- Topics: delay, elm, sequence, settimeout
- Language: Elm
- Homepage: http://package.elm-lang.org/packages/andrewMacmurray/elm-delay/latest
- Size: 1.33 MB
- Stars: 28
- Watchers: 2
- Forks: 4
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Elm Delay
Elm utilities to trigger updates after a delay
**example**: https://elm-delay-examples.surge.sh/
### Why?
Sometimes you need to trigger updates after a period of time (i.e. to wait for a css transition or animation to complete) or maybe you need to chain a sequence of these updates (for more complex states).
This library provides utilities to express this more tidily.
### How?
#### Send a single delayed `Msg`
To trigger a single update after a period of time pass `Delay.after` as a command to the elm runtime:
```elm
FirstMessage ->
( model
, Delay.after 500 SecondMessage
)
```After triggering `FirstMessage`, `500ms` later update will be called with `SecondMessage`
#### Send a sequence of delayed `Msg`s
```elm
Trigger ->
( model
, Delay.sequence
[ ( 1000, FirstMessage )
, ( 2000, SecondMessage )
, ( 1000, ThirdMessage )
]
)
```by sending a `Trigger` `Msg`:
- after `1000ms` update will be called with `FirstMessage`
- then after `2000ms` update will be called with `SecondMessage`
- then after `1000ms` update will be called with `ThirdMessage`As a convenience if you'd only like to start a sequence if the model is in a particular shape you can use `Delay.sequenceIf`
```elm
Trigger ->
( model
, Delay.sequenceIf (not model.updating)
[ ( 1000, FirstMessage )
, ( 2000, SecondMessage )
, ( 1000, ThirdMessage )
]
)
```If you'd like all the steps to have the same unit of time, use the `Delay.withUnit` helper
```elm
Trigger ->
( model
, Delay.sequence
Delay.withUnit Delay.seconds
[ ( 1, FirstMessage )
, ( 2, SecondMessage )
, ( 1, ThirdMessage )
]
)
```