Sie in Daten passieren können Ihre Elm-Anwendung mit der programWithFlags
Funktion zum Starten der App zu initialisieren.
Elm:
module Main exposing (..)
import Html exposing (Html, div, h1, text)
main =
Html.programWithFlags
{ init = init
, view = view
, update = update
, subscriptions = (\_ -> Sub.none)
}
-- MODEL
type alias Model =
{ userId : Int
}
init : { userId : Int } -> (Model, Cmd Msg)
init flags =
-- This is the key piece. You can use the passed in "flags"
-- record to build the initial state of your Model
(Model flags.userId, Cmd.none)
-- UPDATE
type Msg
= NoOp
update : Msg -> Model -> (Model, Cmd Msg)
update NoOp model =
(model, Cmd.none)
-- VIEW
view : Model -> Html Msg
view model =
div [] [ h1 [] [ text ("User ID: " ++ toString model.userId) ] ]
Html:
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="elm.js"></script>
</head>
<body>
</body>
<script type="text/javascript">
// The flags get passed in here
Elm.Main.fullscreen({ userId: 42 });
</script>
</html>
Sie wahrscheinlich benötigen Ports https://guide.elm-lang.org/interop/javascript zum Beispiel mit einer Benutzer-ID zu initialisieren. html – rofrol
@LukaJacobowitz Ich weiß nicht, wo ich anfangen soll. – steel
@rofrol es sieht aus wie Flaggen könnte die nächste Ähnlichkeit sein, aber ähnliches Konzept zu Häfen. Ich habe es in deinem Link gefunden. Wenn Sie eine vollständige Antwort posten möchten, würde ich Ihnen gerne Kredit geben. – steel