Phoenix.Push

A message to push informations to a channel.

Definition

type alias Push msg = { topic : String , event : String , payload : Value , onOk : Maybe (Value -> msg) , onError : Maybe (Value -> msg) }

The message abstraction

Note: You should use the helper functions to construct a Push message.

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"
        , Json.Encode.string "Hello Phoenix"
        )
      ]

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

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

type Msg = MessageArrived | ...

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

init "room:lobby" "new_msg"
    |> withPayload payload
    |> 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"
      , Json.Encode.string "Hello Phoenix"
      )
    ]

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

Applies the function on the onOk and onError callback