chazsconi/elm-phoenix-ports/1.1.2

NOTE: the latest version is 2.1.0

Phoenix.Push

A message to push informations to a channel.

Definition

type alias Push msg =
PhoenixPush msg

The message abstraction

Helpers

init : Topic -> Event -> Push msg

Initialize a message with a topic and an event.

init "room:lobby" "new_msg"
withPayload : Value -> Push msg -> Push msg

Attach a payload to a message

payload =
    Json.Encode.object [("msg", "Hello Phoenix")]


init "room:lobby" "new_msg"
    |> withPayload
onOk : (Value -> msg) -> Push msg -> Push msg

Callback if the server replies with an "ok" status.

type Msg = MessageArrived | ...


payload =
    Json.Encode.object [("msg", "Hello Phoenix")]


init "room:lobby" "new_msg"
    |> withPayload
    |> onOk (\_ -> MessageArrived)
onError : (Value -> msg) -> Push msg -> Push msg

Callback if the server replies with an "error" status.

type Msg = MessageFailed Value | ...


payload =
    Json.Encode.object [("msg", "Hello Phoenix")]


init "room:lobby" "new_msg"
    |> withPayload
    |> onError MessageFailed
map : (a -> b) -> Push a -> Push b

Applies the function on the onOk and onError callback