Skip to content

Instantly share code, notes, and snippets.

@brian-watkins
Created June 11, 2017 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brian-watkins/d8d88343f7bf45c99ae8c3a2aebfdf01 to your computer and use it in GitHub Desktop.
Save brian-watkins/d8d88343f7bf45c99ae8c3a2aebfdf01 to your computer and use it in GitHub Desktop.
module App exposing
( Model
, defaultModel
, view
, update
)
import Html exposing (Html)
import Html.Attributes as Attr
import Html.Events as Event
import WebSocket
type Msg
= SendMessage
| MessageUpdate String
type alias Model =
{ items : List String
, message : String
}
defaultModel : Model
defaultModel =
{ items = []
, message = ""
}
view : Model -> Html Msg
view model =
Html.div []
[ Html.input [ Attr.id "message-field", Event.onInput MessageUpdate ] []
, Html.button [ Attr.id "send-button", Event.onClick SendMessage ] []
, Html.ul [ Attr.id "items" ] []
]
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
MessageUpdate message ->
( { model | message = message }, Cmd.none )
SendMessage ->
( model, WebSocket.send "ws://testserver.com" model.message )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment