Thanks @pdamoc and @joelq for your help! The way I tried to design this is so messy that its hard to explain, huge red flag! I am still experimenting with Elm and FP.
So maybe its better to explain what I would like to do and maybe you can share with me how you’d design this?
Main.Model holds data decoded from 5 different HTTP requests, that I got it to work well thanks to your advice in this chat:
type Model =
Loading {
dataA: Maybe DataA
,dataB: Maybe DataB
, ....etc...
}
| Success {
dataA: DataA
,dataB: DataB
, .... etc...
}
| Error String
That works beautifully… but of course I don’t want to hold the whole API response or data I dont need in Main.Model.
So, Main.init
initiates the API calls, then I import the decoders from the respective modules DataA.elm
etc… to parse the responses.
The responses I will get back are nested timeseries data, with hourly timestamps, and for each I am only interested in the value matching the next hour’s timestamp.
... [
{timestamp: 1231243124, value: 23},
{timestamp: 1231243453, value: 12},
]
So I get this array back, at the decoder level, now how can I “filter in” only the value I am interested in, (the one corresponding to the next hour after I ran the app) ? I just want to update the model with, lets say, 23.
First I will have to first compute the timestamp corresponding to the next hour in my local timezone. I think I am good with that part but where should this timestamp be computed? Main or separate module?
And then, most importantly, how do I share this timestamp with all the 5 decoders?
*Is it possible or a good idea to pass it as an argument to the decoders?
Or should I make a function that takes the time and return a Decoder?
How can I make sure the timestamp will be ready for the decoder?
Init would have to have something like that I assume: getNextHourTimestamp |> andThen Cmd.batch [requests] even if I cant pass it to the actual requests *
I hope it’s more clear… thank you.