Call the update function from the component without using a task

I have an elm project with a main application and component.

I would like the component to have its own internal updates, and also be able to update the main model.

I would like the updatecomponent function to be able to run Cmd, which transfers data to the main application and changes the main URL of the application.

The only way I found this is to use Task.performand Task.succeed.

Is it possible to do this without using Task.performand Task.succeed? What are the negative aspects of patterns of use Task.performand Task.succeedin this scenario?

+4
source share
1 answer

Short answer:

. . IE:

--In Parent
type alias ParentModel = {
    childModel : ChildModel
}

Type Msg 
    = ChildMsg Child.Msg

case ParentMsg parentMsg ->
    let
        ( newChildModel, childMsg ) =
            Child.update parentMsg model.childModel
    in
        ( { model | childModel = newChildModel }, Cmd.map ParentMsg childMsg )

view model =
    Html.map ParentMsg (Child.view model.childModel)
    ...

: - - , . , - . , . , , , git repo Richard created

+5
source

Source: https://habr.com/ru/post/1693882/


All Articles