eco-pro/elm-phoenix-ports/1.0.0

Rerouted (archive, verified). The original repository is gone. This copy comes from an archive (Software Heritage). The Lamdera package server serves a copy recovered from swh:1:rev:1944ed1c5ca26cf275cdf9c8775ec7beb06f860c (Software Heritage, origin https://github.com/eco-pro/elm-phoenix-ports).

What we checked: Software Heritage archived tag 1.0.0 of github.com/eco-pro/elm-phoenix-ports at commit 1944ed1c5ca2; its commit 1944ed1c5ca2 is from 2021-09-10 15:19 UTC, before the version was published (2021-09-10 15:22 UTC); elm.json is byte-identical to package.elm-lang.org's; the exposed modules match docs.json; the zip is our own, made from Software Heritage's copy of the files Elm uses, so its SHA-1 is not the published one.

The Lamdera compiler uses this copy and prints a one-line notice saying so. elm itself fails to download this version.

Details · package.elm-lang.org's zip: https://github.com/eco-pro/elm-phoenix-ports/zipball/1.0.0/

Phoenix.Channel

A channel declares which topic should be joined, registers event handlers and has various callbacks for possible lifecycle events.

Definition

type alias Channel msg =
PhoenixChannel msg

Representation of a Phoenix Channel

type alias Topic =
String

Topic of channel

Helpers

init : Topic -> Channel msg

Initialize a channel to a given topic.

init "room:lobby"
withPayload : Value -> Channel msg -> Channel msg

Attach a payload to the join message. You can use this to submit e.g. a user id or authentication infos. This will be the second argument in your join/3 callback on the server.

payload =
    Json.Encode.object [("user_id", "123")]


init "room:lobby"
    |> withPayload payload
on : String -> (Value -> msg) -> Channel msg -> Channel msg

Register an event handler for a event.

type Msg = NewMsg Value | ...


init "roomy:lobby"
    |> on "new_msg" NewMsg
onJoin : (Value -> msg) -> Channel msg -> Channel msg

Set a callback which will be called after you sucessfully joined the channel. It will also be called after you rejoined the channel after a disconnect unless you specified an onRejoin handler.

type Msg =
    IsOnline Json.Encode.Value | ...


init "room:lobby"
    |> onJoin IsOnline
onRequestJoin : msg -> Channel msg -> Channel msg

Set a callback which will be called after you request to join the channel.

type Msg =
    JoinLobbyRequested


init "room:lobby"
    |> onRequestJoin JoinLobbyRequested
onJoinError : (Value -> msg) -> Channel msg -> Channel msg

Set a callback which will be called if the server declined your request to join the channel.

type Msg =
    CouldNotJoin Json.Encode.Value | ...


init "room:lobby"
    |> onJoinError CouldNotJoin

Note: If a channel declined a request to join a topic the effect manager won_t try again.

onError : msg -> Channel msg -> Channel msg

Set a callback which will be called if the channel process on the server crashed. The effect manager will automatically rejoin the channel after a crash.

type Msg =
     ChannelCrashed | ...


init "room:lobby"
    |> onError ChannelCrashed
onLeave : (Value -> msg) -> Channel msg -> Channel msg

Set a callback which will be called after you sucessfully left a channel.

type Msg =
    LeftLobby Json.Encode.Value | ...


init "room:lobby"
    |> onLeave LeftLobby
onLeaveError : (Value -> msg) -> Channel msg -> Channel msg

Set a callback which will be called if the server declined your request to left a channel. _(It seems that Phoenix v1.2 doesn_t send this)_

withDebug : Channel msg -> Channel msg

Print all status changes.

withPresence : Presence msg -> Channel msg -> Channel msg

Set a callback which will be called when there is a change in the presence state caused by "presence_state" and "presence_diff" events.

type Msg =
    PresenceChange (Dict String (List Json.Encode.Value)) | ...


init "room:lobby"
    |> onPresenceChange PresenceChange
map : (a -> b) -> Channel a -> Channel b

Composes each callback with the function a -> b.