This module helps you set up an Elm program with automatic message-replay.
{ encodeMsg : msg -> Json.Encode.Value
, msgDecoder : Json.Decode.Decoder msg
, fromCache : flags -> Maybe String
, toCache : String -> Platform.Cmd.Cmd msg
}
This is the configuration required for automatic message-replay.
Let's say your program is initialized in HTML like this:
<script>
const app = Elm.Main.init({
node: document.body,
flags: {
amr : localStorage.getItem("app-amr")
}
})
app.ports.toCache.subscribe(output =>
localStorage.setItem("app-amr", output)
)
</script>
The configuration for that script would be like this:
port toCache : Maybe String -> Cmd msg
fromCache =
.amr
encodeMsg
and msgDecoder
depends how messages are defined. You can find an example here.
This API mirrors elm/browser.
sandbox : 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.
element : Config flags msg -> { init : flags -> ( model, Platform.Cmd.Cmd msg ), view : model -> Html msg, update : msg -> model -> ( model, Platform.Cmd.Cmd msg ), subscriptions : model -> Platform.Sub.Sub msg } -> Program flags model msg
Create an HTML element managed by Elm. More about that here.
document : Config flags msg -> { init : flags -> ( model, Platform.Cmd.Cmd msg ), subscriptions : model -> Platform.Sub.Sub msg, update : msg -> model -> ( model, Platform.Cmd.Cmd msg ), view : model -> Browser.Document msg } -> Program flags model msg
Create an HTML document managed by Elm. More about that here.
application : Config flags msg -> { init : flags -> Url -> Browser.Navigation.Key -> ( model, Platform.Cmd.Cmd msg ), update : msg -> model -> ( model, Platform.Cmd.Cmd msg ), subscriptions : model -> Platform.Sub.Sub msg, view : model -> Browser.Document msg, onUrlChange : Url -> msg, onUrlRequest : Browser.UrlRequest -> msg } -> Program flags model msg
Create an application that manages Url changes. More about that here.
Platform.Program flags (Main.Model model) msg
A program with automatic message-replay enabled.