Skip to content

Instantly share code, notes, and snippets.

@justinmimbs
Created June 12, 2017 12:26
Show Gist options
  • Save justinmimbs/9db97d86ac4c5bd10a9cfd0a21412b27 to your computer and use it in GitHub Desktop.
Save justinmimbs/9db97d86ac4c5bd10a9cfd0a21412b27 to your computer and use it in GitHub Desktop.
module Main exposing (..)
import Html exposing (Html)
import Html.Events
import Html.Lazy
{-
Click the text three times.
Each click is expected to toggle the view (between a div and a button). The
first click toggles the view as expected (from div to button); the second
click does not (the button remains, though it seems its tagger has been
replaced); and the third click sends a Float value through the
String.toUpper tagger.
-}
main : Program Never Bool String
main =
Html.beginnerProgram
{ model = True
, update = always not
, view = view
}
view : Bool -> Html String
view showStr =
if showStr |> Debug.log "showStr" then
-- The problem does not occur when the nodes have a different number of
-- taggers, so adding, e.g., `|> Html.map identity` to one of the cases
-- below will prevent the problem.
Html.Lazy.lazy viewStr "a" |> Html.map String.toUpper
else
Html.Lazy.lazy viewNum 1.0 |> Html.map toString
viewStr : String -> Html String
viewStr string =
Html.div
[ Html.Events.onClick string
]
[ Html.text ("Str " ++ string)
]
viewNum : Float -> Html Float
viewNum float =
Html.button
[ Html.Events.onClick float
]
[ Html.text ("Num " ++ toString float)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment