Idiomatic usage of dictionaries in state?

Hi!

I'm getting used to TCA and am really enjoying it so far, thank you for your work on it.

The examples I've worked through so far have used arrays as their main state construct. This combines nicely with ForEachStore, scoping, and combining reducers using .forEach.
I now find myself wanting to use a Dictionary in my state (Dictionary<Int, Todo>, let's say). I can't tell whether this is idiomatic for the ForEachStore/.forEach pullback. Are there any examples or Point-Free videos out there of someone using a Dictionary in this way?

The reason I want to do this is that my state is persisted in a Sqlite DB through GRDB, and I'm listening to subscriptions in the reducers in order to refresh my TCA state structs. I want to combine ephemeral UI state with the DB models in the TCA structs and efficiently update only the DB model that they contain without throwing away all the on-going UI state. My intuition is to store the TodoState keyed by their underlying DB ID and diff/patch the AppState accordingly.

Perhaps my desire to use a Dictionary in this way is a sign of an unidiomatic pattern going on, I'd appreciate any pointers that would help with this as well.

Thank you!

Edit: Of course, right after posting this I realised I could work around this by subscribing to individual model changes inside of each TodoState. This way I don't need to work out my own diff'ing and can avoid the Dictionary for now. I'd still like any advice for the general case though.

Terms of Service

Privacy Policy

Cookie Policy