elm-community/undo-redo/3.0.0

UndoList.Decode

Decode UndoList submodule.

Provides JSON decoders for Timelines and UndoList Messages.

Decoders

undolist : Decoder state -> Decoder (UndoList state)

Decode an undo-list given a decoder of state.

import Json.Decode


json : String
json = """{
    "past": [ 1, 2 ],
    "present": 3,
    "future": [ 4, 5 ]
}"""


Json.Decode.decodeString (undolist Json.Decode.int) json
--> Ok { past = [ 1, 2 ], present = 3, future = [ 4, 5 ] }
msg : Decoder msg -> Decoder (Msg msg)

Decode an undo-list msg given a decoder of messages.

import Json.Decode
import UndoList exposing (Msg(..))


Json.Decode.decodeString (msg Json.Decode.string) "{ \"New\": \"Hello!\" }"
--> Ok (New "Hello!")


json : String
json = """[ "Reset", "Redo", "Undo", "Forget", { "New": 1 } ]"""


Json.Decode.decodeString (Json.Decode.list <| msg Json.Decode.int) json
--> Ok [ Reset, Redo, Undo, Forget, New 1 ]