A Layout is a component that can render other components.
type alias Model =
{ instances : List System.Process.PID
}
type MsgIn
= AddProcess System.Process.PID
| OnClickKillProcess System.Process.PID
| ProcessKilled System.Process.PID
type MsgOut
= KillProcess System.Process.PID
component : Layout (Html msg) Model MsgIn MsgOut msg
component =
{ init =
\_ ->
( { instances = [] }
, []
, Cmd.none
)
, update =
\msgIn model ->
case msgIn of
AddProcess pid ->
( { model
| instances = pid :: model.instances
}
, []
, Cmd.none
)
OnClickKillProcess pid ->
( model
, [ KillProcess pid ]
, Cmd.none
)
ProcessKilled pid ->
( { model
| instances = List.filter (not << System.Process.equals pid)
}
, []
, Cmd.none
)
, view =
\toSelf model renderPid ->
model.instances
|> List.map
(\pid ->
Html.div []
[ Html.button [ Html.Events.onClick (OnClickKillProcess pid) ] [ Html.text "kill process" ]
|> Html.map toSelf
, renderPid pid
|> Maybe.withDefault (Html.text "")
]
)
|> Html.div []
, 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
, view : (componentMsgIn -> msg) -> componentModel -> (System.Process.PID -> Maybe output) -> output
}
The Type of a Layout Component
toActor : Layout output componentModel componentMsgIn componentMsgOut (System.Internal.Message.SystemMessage address actorName appMsg) -> { wrapModel : componentModel -> appModel, wrapMsg : componentMsgIn -> appMsg, mapIn : appMsg -> Maybe componentMsgIn, mapOut : System.Process.PID -> componentMsgOut -> System.Internal.Message.SystemMessage address actorName appMsg } -> System.Actor.Actor componentModel appModel output (System.Internal.Message.SystemMessage address actorName appMsg)
Create an Actor from a Layout Component