Skip to content

Instantly share code, notes, and snippets.

@jweir
Last active March 11, 2023 14:05
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jweir/79af678adf6bce4be3bd91fec2f471fa to your computer and use it in GitHub Desktop.
Save jweir/79af678adf6bce4be3bd91fec2f471fa to your computer and use it in GitHub Desktop.
Work around for Elm Reactor programWithFlags (elm 0.18)

To work around running a programWithFlags with elm-reactor create a separate application entry point.

In the below example there is App.elm – the main application which uses flags. Reactor.elm will run this this app, but initializes the model with static values to simulate the flags.

module App exposing (..)
import Html
type alias Flags =
{ name : String }
type alias Model =
{ name : String }
type Msg
= None
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
model ! []
init : Flags -> ( Model, Cmd Msg )
init flags =
Model flags.name ! []
main : Program Flags Model Msg
main =
Html.programWithFlags
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}
view : Model -> Html.Html Msg
view model =
Html.div [] [ Html.text model.name ]
subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none
module Reactor exposing (..)
import App exposing (..)
import Html
main : Program Never Model Msg
main =
Html.program
{ init = init { name = "Reactor" }
, view = view
, update = update
, subscriptions = subscriptions
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment