>
> Thank you for this example. But I don't see how to properly trigger my
> "ratings" storage reload action if user state changed.
However you please! The caller has the necessary User info now, so UserInfo
is out of the picture and you can do whatever would normally make sense.
Here's one way you could modify the earlier example to do this:
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
UserInfoMsg subMsg ->
let
( userInfoState, subCmd, user ) =
UserInfo.update model.user subMsg model.userInfoState
fetchRatingsCmd =
if model.user == Nothing && user /= Nothing then
-- user was previously Nothing, but now isn't; we
just logged in.
-- that means we should fetch new ratings from
storage!
fetchRatingsCmdGoesHere
else
Cmd.none
in
( { model | userInfoState = userInfoState, user = user }
, Cmd.batch [ fetchRatingsCmd, Cmd.map UserInfoMsg subCmd ]
)
Even more, it is exactly like described here
> https://gist.github.com/evancz/2b2ba366cae1887fe621
> <https://www.google.com/url?q=https%3A%2F%2Fgist.github.com%2Fevancz%2F2b2ba366cae1887fe621&sa=D&sntz=1&usg=AFQjCNGa0I93bqfcXgbvsL9nfTsQK8GW7A>
> by
> the author of Elm
>
This is a gem. Not seen it before but there are some really useful ideas in
> there.
> It had not occurred to me that we can create record types with a 'hole' in
> them, which can then be used to compose them together to build larger
> records, but at the same time we can write functions that just operate on
> whatever components of the record we choose as the level of abstraction to
> re-use. I'm talking about the "Reusable Actions" section.
Yikes, definitely don't do that! That link is from Elm 0.13 - back when
everything was based around Signals, the Elm Architecture did not exist
yet, and Evan was still trying out different approaches to figure out what
worked best.
That section is one of the experiments that *did not work out* in practice,
and was rejected in favor of the approach he recommends today in the Guide.
(There's a very good reason he didn't talk about this pattern in the Guide
- and it's not that it was awesome but he somehow forgot about it!)
On of the interesting solutions https://github.com/folkertdev/outmessage
> another http://package.elm-lang.org/packages/prozacchiwawa/effmodel/2.0.0/
> and elm-parts
I never use these libraries. If installing one ever sounds appealing, I
have almost certainly overcomplicated my state management and a better
course of action would be to refactor. ;)
How would you do this differently?
I don't have strong feelings about module organization conventions in
general. I basically feel like if I'm not happy with how my application's
modules are organized, it's easy to reorganize them, so it's not something
I spend a lot of time thinking about. I'm more concerned with which values
a given module does or does not expose (especially in libraries) than file
and folder structure. :)
Hope this helps!
--
You received this message because you are subscribed to the Google Groups "Elm
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.