Last active
May 26, 2016 06:58
-
-
Save gdotdesign/b5d0a64523a3e32460f2eec2b1bad484 to your computer and use it in GitHub Desktop.
Event handlers cannot be reattached after removing them.
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 (..) | |
import Html.Events exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.App as App | |
import String | |
type alias Model = | |
{ haveEvent : Bool | |
, text : String | |
} | |
init : Model | |
init = | |
{ haveEvent = True | |
, text = "" | |
} | |
type Msg | |
= Change | |
| SetText | |
update : Msg -> Model -> Model | |
update msg model = | |
case msg of | |
SetText -> | |
{ model | text = "Hello There" } | |
Change -> | |
{ model | haveEvent = not model.haveEvent | |
, text = "" } | |
view : Model -> Html Msg | |
view model = | |
div | |
[] | |
[ div | |
(if model.haveEvent then | |
[ onClick SetText ] | |
else | |
[] | |
) | |
[ text "Click Me" ] | |
, button [ onClick Change ] [ text "setValue" ] | |
, text model.text | |
, br [] [] | |
, text ("Have event attched:" ++ (toString model.haveEvent)) | |
] | |
main : Program Never | |
main = | |
App.beginnerProgram | |
{ model = init | |
, update = update | |
, view = view | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment