Skip to content

Instantly share code, notes, and snippets.

@jalandis
Created July 14, 2020 13:13
Show Gist options
  • Save jalandis/d8d1b0027df2358e51a23bcd9b2be717 to your computer and use it in GitHub Desktop.
Save jalandis/d8d1b0027df2358e51a23bcd9b2be717 to your computer and use it in GitHub Desktop.
example of message passing stage bug
-- 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