Hi. Sqldelight allows you to keep track of databas...
# mvikotlin
n
Hi. Sqldelight allows you to keep track of database changes via flow. But how should i integrate this flow with store? And most importantly, should i? For small feature - list of something that user can add/delete it seems like a good idea. Best i can think of is subscribing to flow in bootstrapper and spamming actions to update stores inner list. Feels like I'm missing some point. Thanks
a
Hello! There are three ways: • Pass the database to the
Store
and subscribe in the
Bootstrapper
• Bind the database to the
Store
intents using
binder
(or manually) • Explicitly notify from other places where database is updated (e.g. bind writing
Stores
labels to listening
Stores
intents) Basically you should choose one of them
The second option looks cleaner on my opinion, but the first one is also good. Third option looks like overhead, but explicitness might give some benefits.
Like there will be clear side effects when the database is updated. Might be good for debugging.
n
I'll try all three to see what works best, i think. So with second approach user will send intent to add something in store. Intent will be processed by executor, but instead of dispatching result from there, database flow will pass another intent with updated data. Is that correct?
a
If database can be updated from different places (different
Stores
) and you want to reflect database changes by listening to it in the
Store
, then yes - correct. But if you are doing all the changes in a single
Store
(just one
Store
writing and reading the database), then I would go with either the first approach or manually inserting data to the state.
Overall, I don't think there are any best practices here. Just apply common sense, try different approaches.