This module is used for plugging submodules into a host module. If you're working on the submodule itself, check out SubCmd.
Enables you to handle the updates of submodules that can send effects.
type Msg
= GotSubMsg SubWidget.Msg
| GotSubEffect SubWidget.Effect
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
GotSubMsg subMsg ->
SubWidget.update subMsg model.subModel
|> SubWidget.updateWithEffect
{ toMsg = GotSubMsg
, effectToMsg = GotSubEffect
, toModel =
\subModel -> { model | subModel = subModel }
}
GotSubEffect subEffect ->
case subEffect of
SubWidget.SendValue value ->
( { model | subValue = Just value }
, Cmd.none
)We also provide a few functions to help you deal with modules that can't send effects so you have a similar API across your host module. Note that the same could be achieved without this package at all.
Enables you to initialize multiple submodules that cannot send effects.
let
( subModule, initSubModule ) =
SubModule.init
|> SubModule.init
{ toMsg = SubModuleMsg
}
( subModule2, initSubModule2 ) =
SubModule2.init
|> SubModule.init
{ toMsg = SubModule2Msg
}
in
( { subModule = subModule, subModule2 = subModule2 }, Cmd.none )
|> initSubModule
|> initSubModule2Enables you to handle the updates of submodules that cannot send effects.
type Msg
= GotSubMsg SubWidget.Msg
| ...
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
GotSubMsg subMsg ->
SubModule.update subMsg model.subModule
|> SubModule.update
{ toMsg = GotSubMsg
, toModel = \subModule -> { model | subModule = subModule }
}
...
Enables you to initialize submodules that can send effects.