Skip to content

Instantly share code, notes, and snippets.

@freakingawesome
Created April 3, 2016 18:50
Show Gist options
  • Select an option

  • Save freakingawesome/2204a8ec1d0bb794abb1b30ffa5bb7ed to your computer and use it in GitHub Desktop.

Select an option

Save freakingawesome/2204a8ec1d0bb794abb1b30ffa5bb7ed to your computer and use it in GitHub Desktop.
import Html exposing (..)
import Html.Events exposing (..)
import Html.Attributes exposing (value)
import StartApp
import Effects exposing (Never)
import Task
import Signal
app =
StartApp.start
{ init = init
, view = view
, update = update
, inputs = [ ]
}
main =
app.html
type alias Model =
{ id : Int
, title : String
, content : String
}
init =
({ id = 0, title = "", content = "" }, Effects.none)
view address model =
div []
[ div [] [ text <|"ID : " ++ toString model.id ]
, form
[]
[ input
[ value model.title
, on "input" targetValue (Signal.message address << UpdateTitle)
] []
, textarea
[ value model.content
, on "input" targetValue (Signal.message address << UpdateContent)
] []
, button [ onClick address SubmitPost ] [ text "Submit" ]
]
]
type Action
= SubmitPost
| UpdateTitle String
| UpdateContent String
update action model =
case action of
SubmitPost ->
(model, Effects.none) -- perhaps here you can return a task that submits the form
UpdateTitle s ->
({ model | title = s }, Effects.none)
UpdateContent s ->
({ model | content = s }, Effects.none)
port tasks : Signal (Task.Task Never ())
port tasks =
app.tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment