Created
July 14, 2020 13:13
-
-
Save jalandis/d8d1b0027df2358e51a23bcd9b2be717 to your computer and use it in GitHub Desktop.
example of message passing stage bug
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
-- https://ellie-app.com/9pLFFWd4m7wa1 | |
module Main exposing (..) | |
import Browser | |
import Html exposing (Html, button, div, text) | |
import Html.Events exposing (onClick) | |
import Process | |
import Task | |
main = | |
Browser.element | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
type alias Model = | |
{ simple : Int | |
, passed : Int | |
} | |
init : () -> (Model, Cmd Msg) | |
init _ = | |
( { simple = 0, passed = 0 }, Cmd.none ) | |
type Msg | |
= ModifyState Int | |
| FinishState Int | |
update : Msg -> Model -> (Model, Cmd Msg) | |
update msg model = | |
case msg of | |
ModifyState i -> | |
( model, Task.perform (\_ -> FinishState i) ((Process.sleep (400))) ) | |
FinishState i -> | |
( { model | simple = model.simple + 1, passed = i } | |
, Cmd.none | |
) | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ button [ onClick (ModifyState (model.passed + 1)) ] [ text "+" ] | |
, div [] [ text (String.fromInt model.simple) ] | |
, div [] [ text (String.fromInt model.passed) ] | |
] | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.none |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment