Closed dmattia closed 6 years ago
Thanks for offering your advice and willing to help @dmattia ! I am not sure whether introducing additional combinators for this kind of updates is any more readable than just using the plain record update syntax.
In your example, the "plain" version would look like
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
SomeMsg someStr someLong ->
( { model
| stringField = someStr
, longField = someLong
}
, Cmd.none )
which seems pretty readable to me?
It does to me as well. The bigger issue that I am hoping to help with is updating nested records, where helper functions can make code considerably more concise and readable (subjective).
I really like the asXIn
syntax alongside the setX
methods, as described here:
https://medium.com/elm-shorts/updating-nested-records-in-elm-15d162e80480
I feel the same about nested records, and I wish elm had something like the lens package in Haskell for that. The closest I could find is https://github.com/bChiquet/elm-accessors , perhaps we could add support for generating those combinators in proto, but AFAICT the elm community (or at least @evancz) seems to discourage that pattern (see the message when typing lens
into https://package.elm-lang.org/).
That's fair. I'm convinced enough that this isn't needed for now then.
I am wondering your thoughts on creating chainable
updateX
methods for each message. This is something I often do in elm for types I create.There is a history of such methods on proto objects:
setX
methods.setX
methods, though they are unchainable.Example:
Example Proto Output (only new functions shown):
Example Usage:
I would gladly offer to help with this if you're interested in the idea