Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bowbahdoe/elm-history
A History Data Structure for the Elm Programming Language
https://github.com/bowbahdoe/elm-history
datastructure elm frontend
Last synced: 7 days ago
JSON representation
A History Data Structure for the Elm Programming Language
- Host: GitHub
- URL: https://github.com/bowbahdoe/elm-history
- Owner: bowbahdoe
- License: apache-2.0
- Created: 2019-02-24T07:08:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-03-18T15:34:08.000Z (over 5 years ago)
- Last Synced: 2023-08-08T20:38:16.941Z (over 1 year ago)
- Topics: datastructure, elm, frontend
- Language: Elm
- Size: 11.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-history
This library provides a data structure for managing the "History"
of some values. It is useful for making features that are along
the lines of undo and redo.[Try it on Ellie][1]
[1]: https://ellie-app.com/52ctv8T5Q2Sa1
```elm
module Main exposing (main)import Browser exposing (sandbox)
import History exposing (History)
import Html exposing (Html, br, button, div, text)
import Html.Events exposing (onClick)type alias Model =
History Inttype Msg
= Increment
| Decrement
| TimesFive
| Redo
| Undoinit : Model
init =
History.new 0update : Msg -> Model -> Model
update msg model =
case msg of
Increment ->
History.to (History.current model + 1) modelDecrement ->
History.to (History.current model - 1) modelTimesFive ->
History.to (History.current model * 5) modelUndo ->
History.back modelRedo ->
History.forward modelview : Model -> Html Msg
view model =
div []
[ text (String.fromInt (History.current model))
, br [] []
, button [ onClick Increment ] [ text "Increment" ]
, br [] []
, button [ onClick Decrement ] [ text "Decrement" ]
, br [] []
, button [ onClick TimesFive ] [ text "Time Five" ]
, br [] []
, button [ onClick Redo ] [ text "Redo" ]
, br [] []
, button [ onClick Undo ] [ text "Undo" ]
]main =
sandbox { init = init, update = update, view = view }
```