Created
December 19, 2018 00:35
-
-
Save maybe-joe/ebe2476d94606e53f20d5fbd4e1a4550 to your computer and use it in GitHub Desktop.
Example of a basic elm app using flags
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main exposing (main) | |
import Browser exposing (..) | |
import Html exposing (..) | |
type alias Model = | |
{ url : String | |
, title : String | |
} | |
-- Our Flags type alias must match the data passed to it from the index.html | |
type alias Flags = | |
{ url : String | |
} | |
initialModel : Model | |
initialModel = | |
{ url = "" | |
, title = "This is the current URL: " | |
} | |
-- main : Program Flags Model Msg | |
-- main = | |
-- programWithFlags | |
-- { init = init | |
-- , view = view | |
-- , update = update | |
-- , subscriptions = subscriptions | |
-- } | |
main : Program Flags Model Msg | |
main = | |
Browser.element | |
{ init = init | |
-- , onUrlChange = ChangedUrl | |
-- , onUrlRequest = ClickedLink | |
, subscriptions = subscriptions | |
, update = update | |
, view = view | |
} | |
-- init function to take the initial model but change url to the url flag passed to it | |
init : Flags -> ( Model, Cmd Msg ) | |
init flags = | |
( { initialModel | |
| url = flags.url | |
} | |
, Cmd.none | |
) | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ span [] | |
[ text model.title ] | |
, span [] [ text model.url ] | |
] | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.none | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
Example -> | |
( model, Cmd.none ) | |
type Msg | |
= Example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment