Hello!

I have an app that loads some JSON from a website and displays it. The 
state of the app could be modelled a bit like this:

type State =
    Loading |
    Displaying Stuff

type alias Stuff = { … }

Now I am writing the update function to handle messages:

update : Msg -> State -> (State, Cmd Msg)
update msg state = case msg of
    UpdateThis -> …
    UpdateThat -> …

My problem is that the state can be either Loading or Displaying, but most 
of the messages only make sense in the Displaying state, leading me to code 
like this:

update : Msg -> State -> (State, Cmd Msg)
update msg state = case msg of
    UpdateThis -> case state of
        Displaying stuff -> …
        _ -> (Failed "Invalid state", Cmd.none)
    UpdateThat -> case state of
        Displaying stuff -> …
        _ -> (Failed "Invalid state", Cmd.none)

Obviously, this is dumb. How can I “divide” the loading and the displaying 
part of the app? (Assuming that UpdateThis and UpdateThat can only arrive 
in the correct, Displaying state.)

Thank you!

T.

-- 
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.

Reply via email to