Fresheyeball / elm-return

Writer powered pipelining for `(model, Cmd msg)`

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Function for pushing in component's Return into the main Return while maintaining the Cmds

toastal opened this issue · comments

If a component is also using return, you can use mapBoth in the library fine without having to pattern match out the tuple, but if you're trying to merge that component's Return with the top-most Return, you can't do that cleanly without.

Currently a way to do this now is like this, but it goes against the mantra of the library which is to cut down on pattern matching, point-free, and verbosity:

import Return exposing (..)

update : Msg -> Model -> Return Msg Model
update msg model =
    singleton model
        |> map (\m -> { m | alwaysResetThisBool = False })
        |> case msg of
            FooMsg msg' ->
                let
                    ( fooModel, fooCmd ) =
                        FooComponent.update msg' model.foo
                            |> mapBoth FooMsg (\m -> { model | foo = m })
                in
                    mapBoth (always fooModel) (always fooCmd)
            ...

You can pipe the component's mapBoth into always which'll toss away the top-level's Return, but you lose built up model and command stuff that you're trying to pipe into this.

This is what I ended up doing: https://github.com/toastal/return-optics