Skip to content

Instantly share code, notes, and snippets.

@chrisbuttery
Last active October 20, 2016 10:59
Show Gist options
  • Save chrisbuttery/f3b235293e3dfb75b27242c244853bdc to your computer and use it in GitHub Desktop.
Save chrisbuttery/f3b235293e3dfb75b27242c244853bdc to your computer and use it in GitHub Desktop.
elm-lang equivalent of 2 second SetTimeout.
module Main exposing (..)
import Html exposing (..)
import Html.Events exposing (..)
import Html.App as App
import Task
import Process
import Time
type alias Model =
String
model : Model
model =
"not clicked"
myTask : Cmd Msg
myTask =
Task.perform NoOp Foo
<| Process.sleep (2 * Time.second)
`Task.andThen` \_ -> Task.succeed "not clicked"
type Msg
= Foo String
| Bar
| NoOp ()
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
Foo str ->
( str, Cmd.none )
Bar ->
let
txt =
if model == "not clicked" then
"clicked"
else
"not clicked"
in
( txt, myTask )
NoOp _ ->
( model, Cmd.none )
view : Model -> Html Msg
view model =
div []
[ button [ onClick Bar ] [ text "Click" ]
, text model
]
main : Program Never
main =
App.program
{ init = ( model, myTask )
, view = view
, update = update
, subscriptions = \_ -> Sub.none
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment