A Worker is a headless Actor, it has no User Interface.
This is great if you want to use an Actor as the “brain” for something else.
type alias Model =
String
type MsgIn
= OnStuff
type MsgOut
= DoStuff
component : Worker Model MsgIn MsgOut
component =
{ init =
\_ ->
( "Worker Model"
, []
, Cmd.none
)
, update =
\msgIn model ->
case msgIn of
onStuff ->
( model
, [ DoStuff ]
, Cmd.none
)
, subscriptions = always Sub.none
, events = System.Event.ignoreAll
}
{ init : ( System.Process.PID
, Json.Decode.Value ) -> ( componentModel
, List componentMsgOut
, Platform.Cmd.Cmd componentMsgIn )
, update : componentMsgIn -> componentModel -> ( componentModel
, List componentMsgOut
, Platform.Cmd.Cmd componentMsgIn )
, subscriptions : componentModel -> Platform.Sub.Sub componentMsgIn
, events : System.Event.ComponentEventHandlers componentMsgIn
}
The Type of a Worker Component
toActor : Worker componentModel componentMsgIn componentMsgOut -> { wrapModel : componentModel -> model, wrapMsg : componentMsgIn -> appMsg, mapIn : appMsg -> Maybe componentMsgIn, mapOut : System.Process.PID -> componentMsgOut -> System.Internal.Message.SystemMessage address actorName appMsg } -> System.Actor.Actor componentModel model output (System.Internal.Message.SystemMessage address actorName appMsg)
Create an Actor from a Worker