billstclair/elm-port-funnel/1.2.0

PortFunnel.AddXY

An example add/multiply funnel, with a simulator.

Types

type Message
= AddMessage Question
| MultiplyMessage Question
| SumMessage Answer
| ProductMessage Answer

AddMessage and MultiplyMessage go out from Elm to the JS.

SumMessage and ProductMessage come back in.

= NoResponse
| MessageResponse Message

A MessageResponse encapsulates a message.

NoResponse is currently unused, but many PortFunnel-aware modules will need it.

type alias State =
List Message

Our internal state.

Just tracks all incoming messages.

Components of a PortFunnel.FunnelSpec

moduleName : String

The name of this module: "AddXY".

Our module descriptor.

commander : (GenericMessage -> Cmd msg) -> Response -> Cmd msg

Responsible for sending a CmdResponse back througt the port.

Called by PortFunnel.appProcess for each response returned by process.

The AddXY module doesn't send itself messages, so this is just PortFunnel.emptyCommander.

Initial State

initialState : State

The initial, empty state, so the application can initialize its state.

Sending a Message out the Cmd Port

makeAddMessage : Int -> Int -> Message

Make an AddMessage

Make a MultiplyMessage

send : (Value -> Cmd msg) -> Message -> Cmd msg

Send a Message through a Cmd port.

Conversion to Strings

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.

Simulator

makeSimulatedCmdPort : (Value -> msg) -> Value -> Cmd msg

Make a simulated Cmd port.

Non-standard Functions

stateToStrings : State -> List String

Convert our State to a list of strings.