Skip to content

Instantly share code, notes, and snippets.

@gdotdesign
Last active May 26, 2016 06:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdotdesign/b5d0a64523a3e32460f2eec2b1bad484 to your computer and use it in GitHub Desktop.
Save gdotdesign/b5d0a64523a3e32460f2eec2b1bad484 to your computer and use it in GitHub Desktop.
Event handlers cannot be reattached after removing them.
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