billstclair / elm-port-funnel / 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.


type Response
    = 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".

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.

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 : Basics.Int -> Basics.Int -> Message

Make an AddMessage

makeMultiplyMessage : Basics.Int -> Basics.Int -> Message

Make a MultiplyMessage

send : (Json.Encode.Value -> Platform.Cmd.Cmd msg) -> Message -> Platform.Cmd.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 : (Json.Encode.Value -> msg) -> Json.Encode.Value -> Platform.Cmd.Cmd msg

Make a simulated Cmd port.

Non-standard Functions

stateToStrings : State -> List String

Convert our State to a list of strings.