Why is my message not being sent/data not loaded?

Full code runnable: fitness-tracker/src at main · nsadeh/fitness-tracker · GitHub

I am building a login workflow in Elm. Once a user logs in, the app should perform a fetch to a server for their data. It’s currently separated into a login page and workouts page, each with their own model/view/update. When a LoginSucceeded message arrives, then the Main update function calls the Workouts update function which is how the login works.

The problem: while I see a view of my Workouts page, I don’t see any of the seed data there. Using the awesome Elm debugger, I can see that the FetchedData message, which is supposed to be received right after executing update on the LoggedIn message

Here is the line in Main.elm where we “switch” from the Login page to the Workouts page: fitness-tracker/Main.elm at 9412fee5a9bf23b029de16685f9714bb4435add6 · nsadeh/fitness-tracker · GitHub. We get a LoginSucceeded message and call the Workouts.update function with the payload on a default Unauthenticated workouts page.

Here is where Workouts.updated get the LoggedIn message with an Unauthenticated model: https://github.—com/nsadeh/fitness-tracker/blob/9412fee5a9bf23b029de16685f9714bb4435add6/src/Pages/Workouts.elm#L86. It’s supposed to change the model to an Authenticated with some seed data (this part works), then execute a command to get the data (dummy data in memory for now), and map the resulting Cmd through https://github.—com/nsadeh/fitness-tracker/blob/9412fee5a9bf23b029de16685f9714bb4435add6/src/Pages/Workouts.elm#L143 to get a message with the actual data (that I don’t see). This part doesn’t work; I expect FetchedData to be recorded in the Elm debugger but it isn’t.

Note that I don’t expect LoggedIn to be recorded, since we invoked update on it without actually receiving it in the main update method.

EDIT: the last two links have been tampered with to get around the 2 links or fewer requirement. I think since I am linking code and not spam I am adhering to it in spirit.

I figured it out.

Turns out that Cmd.none is equivalent to Cmd.batch [], that is, an empty list of commands. Thus my map had no effect.

The action - mocking an endpoint - was achieved using Task:

Task.succeed (Result.Ok dummy)
            |> Task.perform identity

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.