chazsconi / elm-phoenix-ports / Phoenix.Config

Defines the Config for Phoenix

Definition


type alias Config msg parentModel channelsModel =
{ parentMsg : Phoenix.Internal.Types.Msg msg -> msg
, ports : Maybe (Phoenix.PortsAPI.Ports msg)
, socket : parentModel -> Phoenix.Socket.Socket msg
, modelGetter : parentModel -> Phoenix.Internal.Types.Model msg channelsModel
, modelSetter : Phoenix.Internal.Types.Model msg channelsModel -> parentModel -> parentModel
, channelsBuilder : ChannelsBuilder msg channelsModel
, channelsModelComparator : ChannelsModelComparator channelsModel
, channelsModelBuilder : parentModel -> channelsModel
, debug : Basics.Bool 
}

The config for Phoenix


type alias PushConfig msg =
{ parentMsg : Phoenix.Internal.Types.Msg msg -> msg
, debug : Basics.Bool 
}

Minimal config needed for Phoenix.push


type alias PushableConfig msg a =
{ a | parentMsg : Phoenix.Internal.Types.Msg msg -> msg }

Extensible config type used by Phoenix.push

Helpers

new : (Phoenix.Internal.Types.Msg msg -> msg) -> Phoenix.PortsAPI.Ports msg -> (parentModel -> Phoenix.Socket.Socket msg) -> (parentModel -> Phoenix.Internal.Types.Model msg channelsModel) -> (Phoenix.Internal.Types.Model msg channelsModel -> parentModel -> parentModel) -> { parentMsg : Phoenix.Internal.Types.Msg msg -> msg, ports : Maybe (Phoenix.PortsAPI.Ports msg), socket : parentModel -> Phoenix.Socket.Socket msg, modelGetter : parentModel -> Phoenix.Internal.Types.Model msg channelsModel, modelSetter : Phoenix.Internal.Types.Model msg channelsModel -> parentModel -> parentModel }

Creates a new config. The output of this must be piped into withStaticChannels or withDynamicChannels

withStaticChannels : List (Phoenix.Channel.Channel msg) -> { parentMsg : Phoenix.Internal.Types.Msg msg -> msg, ports : Maybe (Phoenix.PortsAPI.Ports msg), socket : parentModel -> Phoenix.Socket.Socket msg, modelGetter : parentModel -> Phoenix.Internal.Types.Model msg (), modelSetter : Phoenix.Internal.Types.Model msg () -> parentModel -> parentModel } -> Config msg parentModel ()

Sets the config to connect to a list of static channels.

withDynamicChannels : ChannelsBuilder msg channelsModel -> (parentModel -> channelsModel) -> { parentMsg : Phoenix.Internal.Types.Msg msg -> msg, ports : Maybe (Phoenix.PortsAPI.Ports msg), socket : parentModel -> Phoenix.Socket.Socket msg, modelGetter : parentModel -> Phoenix.Internal.Types.Model msg channelsModel, modelSetter : Phoenix.Internal.Types.Model msg channelsModel -> parentModel -> parentModel } -> Config msg parentModel channelsModel

Sets the config to allow the use of dynamic channels

withChannelsModelComparator : ChannelsModelComparator channelsModel -> Config msg parentModel channelsModel -> Config msg parentModel channelsModel

As an optimisation, the library compares the passed channels model with the version from the previous functional call and then only calls the provided channels function if the model has changed. This comparison is done by default with == and due to an issue in Elm, comparing a model with a contained Json.Encode.Value can cause a runtime exception. (See https://github.com/elm/core/issues/1058). To solve this, you can provide a custom function that will compare channels models safely.

withDebug : Config msg parentModel channelsModel -> Config msg parentModel channelsModel

Enable debug logs. Every incoming and outgoing message will be printed.

toPushConfig : Config msg parentModel channelsModel -> PushConfig msg

Create a config that can be used for Phoenix.push from the config. This has a simple type and is useful if used in a multi-page app with delegating update functions.

mapPushConfig : (Phoenix.Internal.Types.Msg m2 -> m2) -> PushConfig m1 -> PushConfig m2

Maps the push config