Last active
May 18, 2016 05:51
-
-
Save chrisbuttery/bf4d50c822df56db6013ac12b82cea4f to your computer and use it in GitHub Desktop.
Elm 0.17. A simple Window.resizes example.
This file contains 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
{ | |
"version": "1.0.0", | |
"summary": "let people do a cool thing in a fun way", | |
"repository": "https://github.com/user/project.git", | |
"license": "BSD3", | |
"source-directories": [ | |
"." | |
], | |
"exposed-modules": [], | |
"dependencies": { | |
"elm-lang/core": "4.0.0 <= v < 5.0.0", | |
"elm-lang/html": "1.0.0 <= v < 2.0.0", | |
"elm-lang/window": "1.0.0 <= v < 2.0.0" | |
}, | |
"elm-version": "0.17.0 <= v < 0.18.0" | |
} |
This file contains 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
import Html exposing (Html, text, div) | |
import Html.App as Html | |
import Window exposing (..) | |
main = | |
Html.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
-- MODEL | |
type alias Model = { | |
height: Int | |
, width : Int | |
} | |
initialModel: Model | |
initialModel = | |
{ height = 0 | |
, width = 0 | |
} | |
init : (Model, Cmd Msg) | |
init = | |
(initialModel, Cmd.none) | |
-- UPDATE | |
type Msg | |
= Resize Int Int | |
update: Msg -> Model -> (Model, Cmd Msg) | |
update msg model = | |
case msg of | |
Resize h w -> | |
({model | height = h, width = w} , Cmd.none) | |
-- SUBSCRIPTIONS | |
subscriptions: Model -> Sub Msg | |
subscriptions model = | |
Window.resizes (\{height, width} -> Resize height width) | |
-- VIEW | |
view: Model -> Html Msg | |
view model = | |
let | |
str = | |
if model.height == 0 && model.width == 0 then | |
"Resize the window" | |
else | |
toString model | |
in | |
Html.text str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment