Skip to content

Instantly share code, notes, and snippets.

@rohanorton
Last active April 26, 2016 21:49
Show Gist options
  • Save rohanorton/ef6df3ce56e83645287a to your computer and use it in GitHub Desktop.
Save rohanorton/ef6df3ce56e83645287a to your computer and use it in GitHub Desktop.
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