opvasger/msg-replay/1.0.0

NOTE: the latest version is 1.0.1

Rerouted (cache, needs approval). The original is gone. This copy comes from a Lamdera package cache made before it went. The Lamdera package server serves a copy recovered from a Lamdera package cache from 2021-02-13.

What we checked: Rebuilt from the unpacked sources in a Lamdera package cache (5 copies agree), which Elm only writes after the published SHA-1 checked out; elm.json differs from package.elm-lang.org's; the exposed modules match docs.json; the zip is our own, so its SHA-1 is not the published one.

We could not verify this copy against what was published, so the Lamdera compiler asks before using it (y/n). Without a terminal, as in CI, it stops with an error unless approved:

  • lamdera make --auto-approve-package-rerouting approves rerouted versions for that run,
  • LAMDERA_AUTO_APPROVE_PACKAGE_REROUTING=1 does the same for every run in that environment,
  • LAMDERA_CACHE=off skips the Lamdera package server altogether: packages come from package.elm-lang.org and GitHub only, as with elm, and a rerouted version then fails to download.

Details · package.elm-lang.org's zip: https://github.com/opvasger/msg-replay/zipball/1.0.0/

MsgReplay

This module helps you set up an Elm program with automatic message-replay.

Configuration

type alias Config flags msg =
{ encodeMsg : msg -> Value
, msgDecoder : Decoder msg
, fromCache : flags -> Maybe String
, toCache : String -> Cmd msg
}

This is the configuration required for automatic message-MsgReplay.

Let's say your program is initialized in HTML like this:

<script>
    const app = Elm.Main.init({
        node: document.body,
        flags: {
            messages : localStorage.getItem("msg-replay")
        }
    })


    app.ports.toCache.subscribe(messages =>
        localStorage.setItem("msg-replay", messages)
    )
</script>

The configuration for that script would be like this:

port toCache : Maybe String -> Cmd msg


fromCache =
    .messages

encodeMsg and msgDecoder depends on how messages are defined.

Programs

This API mirrors elm/browser.

Config flags msg
-> { init : model
, view : model -> Html msg
, update : msg -> model -> model
}
-> Program flags model msg

Create a “sandboxed” program that cannot communicate with the outside world. More about that here.

Config flags msg
-> { init : flags -> ( model, Cmd msg )
, view : model -> Html msg
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
}
-> Program flags model msg

Create an HTML element managed by Elm. More about that here.

Config flags msg
-> { init : flags -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, update : msg -> model -> ( model, Cmd msg )
, view : model -> Document msg
}
-> Program flags model msg

Create an HTML document managed by Elm. More about that here.

Config flags msg
-> { init : flags -> Url -> Key -> ( model, Cmd msg )
, update : msg -> model -> ( model, Cmd msg )
, subscriptions : model -> Sub msg
, view : model -> Document msg
, onUrlChange : Url -> msg
, onUrlRequest : UrlRequest -> msg
}
-> Program flags model msg

Create an application that manages Url changes. More about that here.

type alias Program flags model msg =
Program flags (Model model) msg

A program with automatic message-replay enabled.