peterszerzo / elm-porter / 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 =
Internals.Config req res msg

Porter configuration, containing:

The setup


type Model req res msg

Porter model, used to keep track of response handlers.


type alias Msg req res msg =
Internals.Msg req res msg

Module messages.

init : Model req res msg

Initialize model

update : Config req res msg -> Msg req res msg -> Model req res msg -> ( Model req res msg, Platform.Cmd.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 -> Platform.Sub.Sub msg

Subscribe to messages from ports.

Transform messages

map : (outputResA -> outputResB) -> Request req res outputResA -> Request req res outputResB

Turns the request's specialized response type into a different type.

map2 : (a -> b -> c) -> Request req res a -> Request req res b -> Request req res c

Chains two requests, and then combines their two responses into one new c.

map3 : (a -> b -> c -> d) -> Request req res a -> Request req res b -> Request req res c -> Request req res d

Chains three requests, and then combines their three responses into one new c.

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

Combines together multiple Porter.Multi requests

Send messages


type alias Request req res outputRes =
Internals.MultiRequest req res outputRes

Opaque type for porter requests, where we can either:

request : (res -> outputRes) -> req -> Request req res outputRes

Creates a new request, specifying:

simpleRequest : req -> Request req res res

A simpler version of request where the end result is not converted into a specialized type, but left the same.

succeed : outputRes -> Request req res outputRes

Succeed with an outputRes value without making an actual request. This is especially useful inside andThen, where the request chain may need to shortcircuit because of the return value (e.g. should not update a record that hasn't been found).

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

Actually sends a (chain of) request(s).

A final handler needs to be specified that turns the final result into a msg. This msg will be called with the final resulting a once the final response has returned.