eco-pro / elm-phoenix-ports / 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 : Json.Encode.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 : (Json.Encode.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 : (Json.Encode.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