peterszerzo/elm-porter/1.0.1

NOTE: this package is not compatible with Elm 0.19.1

Porter

Port message manager to emulate a request-response style communication through ports, a'la Http.send ResponseHandler request.

Configuration

type alias Config req res msg =
{ outgoingPort : Value -> Cmd msg
, incomingPort : (Value -> Msg req res msg) -> Sub (Msg req res msg)
, encodeRequest : req -> Value
, decodeResponse : Decoder res
}

Porter configuration, containing ports and message encoders/decoders.

The setup

type Model req res msg

Porter model, used to keep track of response handlers.

type Msg req res msg

Module messages.

init : Model req res msg

Initialize model.

Config req res msg
-> Msg req res msg
-> Model req res msg
-> ( Model req res msg, Cmd msg )

Update port model based on local messages. Returns a new port model and a local command that must be mapped to the parent message.

subscriptions : Config req res msg -> Sub (Msg req res msg)

Subscribe to messages from ports.

Send messages

send : (res -> msg) -> req -> Cmd (Msg req res msg)

Initiate a message send.