Skip to content

Instantly share code, notes, and snippets.

@trotha01
Created February 2, 2018 16:52
Show Gist options
  • Save trotha01/a8e8e1b2db8472477c78571b7c52d901 to your computer and use it in GitHub Desktop.
Save trotha01/a8e8e1b2db8472477c78571b7c52d901 to your computer and use it in GitHub Desktop.
Elm 0.18 Initial Window Size
module Main exposing (main)
import Html exposing (Html, text)
import Window
import Task
main =
Html.program
{ init = init
, update = update
, view = view
, subscriptions = subscriptions
}
-- MODEL
type alias Model =
{ window : Window.Size
}
init =
( { window = initWindow
}
, Task.perform WindowResize Window.size
)
initWindow =
{ height = 0
, width = 0
}
-- UPDATE
type Msg
= WindowResize Window.Size
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
WindowResize size ->
( { model | window = size }, Cmd.none )
-- VIEW
view : Model -> Html Msg
view model =
text <| toString model.window
-- SUBSCRIPTION
subscriptions : Model -> Sub Msg
subscriptions model =
Window.resizes WindowResize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment