An example echo funnel, with a simulator.
Since this is a simple echo example, the messages are just strings.
A MessageResponse
encapsulates a message.
NoResponse
is currently unused, but many PortFunnel-aware modules will need it.
CmdResponse
denotes a message that needs to be sent through the port. This is done by the commander
function.
ListResponse
allows us to return multiple responses. commander
descends a ListResponse
looking for CmdResponse
responses. findMessages
descends a list of Response
records, collecting the MessageResponse
messages.
Our internal state.
Just tracks all incoming messages.
PortFunnel.FunnelSpec
moduleName : String
The name of this module: "Echo".
moduleDesc : PortFunnel.ModuleDesc Message State Response
Our module descriptor.
commander : (PortFunnel.GenericMessage -> Platform.Cmd.Cmd msg) -> Response -> Platform.Cmd.Cmd msg
Responsible for sending a CmdResponse
back througt the port.
Called by PortFunnel.appProcess
for each response returned by process
.
State
initialState : State
The initial, empty state, so the application can initialize its state.
Message
out the Cmd
PortmakeMessage : String -> Message
Make a message to send out through the port.
send : (Json.Encode.Value -> Platform.Cmd.Cmd msg) -> Message -> Platform.Cmd.Cmd msg
Send a Message
through a Cmd
port.
toString : Message -> String
Convert a Message
to a nice-looking human-readable string.
toJsonString : Message -> String
Convert a Message
to the same JSON string that gets sent
over the wire to the JS code.
makeSimulatedCmdPort : (Json.Encode.Value -> msg) -> Json.Encode.Value -> Platform.Cmd.Cmd msg
Make a simulated Cmd
port.
isLoaded : State -> Basics.Bool
Returns true if a Startup
message has been processed.
This is sent by the port code after it has initialized.
findMessages : List Response -> List Message
When it needs to send the tail of a message beginning with a dollar sign
through the port, the Echo
module returns a ListResponse
. This function recursively descends a ListResponse, and returns a list of the Message
s from any MessageResponse
s it finds.
stateToStrings : State -> List String
Convert our State
to a list of strings.