So I made this terrible code yesterday: https://git.ahlcode.fi/nicd/aurinko/src/commit/05b7a81139f78a6c8b35ed210b9fd24cdc43c817/backend/src/aurinko/updater.gleam
The problem is that I have at least three states:
- when the actor is started with only the credentials (
InitialState), - when the initial login and module fetch is done so that we have the auth cookies (
LoadedState), and - when we have loaded measurement data (
LoadedStatewithDatasetset to something).
Due to having multiple states, I need to keep checking the shape of the state at every turn, or do what I did here and unwrap the values into separate variables that I pass around. But that's very verbose, and I keep writing username, password, cookies, cookies_acquired, ... over and over again.
If you have a suggestion how this could be cleaned up, I'd love to hear it. 🙂 But it's a bunch of code to read.