Last active
April 26, 2016 21:49
-
-
Save rohanorton/ef6df3ce56e83645287a to your computer and use it in GitHub Desktop.
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 StartApp.Simple exposing (start) | |
import Html exposing (Html, div, text) | |
import Html.Attributes exposing (contenteditable) | |
import Html.Events exposing (on, targetValue) | |
-- Model | |
type alias Model = String | |
init : Model | |
init = "Foo" | |
-- Update | |
type Action | |
= Update String | |
update : Action -> Model -> Model | |
update action model = | |
case action of | |
Update content -> content | |
-- View | |
targetText : Json.Decode.Decoder String | |
targetText = | |
Json.Decode.at [ "target", "innerText" ] Json.Decode.string | |
view : Signal.Address Action -> Model -> Html | |
view address model = | |
div [] | |
[ | |
div [ contenteditable True | |
, on "blur" targetText (Signal.message address << Update) | |
] [ text model ] | |
, div [] [ text model ] | |
] | |
main = | |
start | |
{ model = init | |
, update = update | |
, view = view | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment