peterszerzo/elm-porter/2.1.2

NOTE: the latest version is 3.0.0

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 =
Config req res msg

Porter configuration, containing:

  • ports
  • message encoders/decoders.
  • the message that porter will use for its internal communications

The setup

type Model req res msg

Porter model, used to keep track of response handlers.

type alias Msg req res msg =
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

Subscribe to messages from ports.

Send messages

type alias Request req res =
Request req res

Opaque type of a 'request'. Use the request function to create one, chain them using andThen and finally send it using send.

request : req -> Request req res

Starts a request that can be sent at a later time using send, and that can be combined using andThen.

andThen : (res -> Request req res) -> Request req res -> Request req res

Chains two Porter requests together: Run a second one right away when the first returns using its result in the request.

send : Config req res msg -> (res -> msg) -> Request req res -> Cmd msg

Sends a request earlier started using request.