Created
November 11, 2016 16:33
-
-
Save chancyk/4415f3c0c8f245716d01dea42a5bf00a to your computer and use it in GitHub Desktop.
Runtime Error from Clearing a contenteditable DIV
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
{-| This code will reproduce issue https://github.com/elm-lang/core/issues/749 | |
when the text from either div is cleared. | |
-} | |
import Html exposing (text) | |
import Html.App as App | |
import Html.Attributes exposing (contenteditable) | |
import Html.Events exposing (on) | |
import Json.Decode as Json | |
type Msg = HelloUpdate String | WorldUpdate String | |
update msg model = | |
case msg of | |
HelloUpdate txt -> | |
( { model | hello = txt }, Cmd.none ) | |
WorldUpdate txt -> | |
( { model | world = txt }, Cmd.none ) | |
initModel = | |
{ hello = "hello" | |
, world = "world" | |
} | |
view model = | |
Html.div | |
[] | |
[ Html.div | |
[ contenteditable True | |
, onInput HelloUpdate | |
] | |
[ text model.hello ] | |
, Html.div | |
[ contenteditable True | |
, onInput WorldUpdate | |
] | |
[ text model.world ] | |
] | |
onInput msg = | |
on "input" (Json.map msg innerHtmlDecoder) | |
innerHtmlDecoder = | |
Json.at ["target", "innerHTML"] Json.string | |
main = | |
App.program | |
{ init = (initModel, Cmd.none) | |
, update = update | |
, view = view | |
, subscriptions = (\_ -> Sub.none) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment