Created
February 2, 2018 16:52
-
-
Save trotha01/a8e8e1b2db8472477c78571b7c52d901 to your computer and use it in GitHub Desktop.
Elm 0.18 Initial Window Size
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 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