Recommended way to incorporate local persistence updating and observing? #333
-
Per React, when two children need to display and update common data, they delegate the updating to their closest common ancestor, and receive updates from said common ancestor https://reactjs.org/docs/lifting-state-up.html How does the addition of a database, which can be thought of as global state, work into this? Since local persistence is much less common in the web compared to mobile world, I couldn't find anything about how to treat it in React; my apologies if my question has already been answered. I also didn't see any local persistence in the sample apps.
Lastly, regardless of whether it's done in the child or parent, what's the recommended way to do this database updating in Workflows? It seems excessive and overly verbose to have an explicit state or field |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Lifting state: generally a good thing, as it makes the children workflows more testable and reusable. Updating DB: I would recommend your third bullet point. It works great with SqlDelight/Room, Dropbox Store, etc. How to do side effects: Use Workers, which effectively give you a coroutine that is scoped to the workflow. It's not released yet (should be within the week) but we just introduced a more fundamental primitive for side effects, see |
Beta Was this translation helpful? Give feedback.
-
Thank you, I appreciate the guidance. If we're to update the database from a worker (for which the Semi-related question - since a full-fledged Worker and |
Beta Was this translation helpful? Give feedback.
-
I would probably lean towards using I think you're on the right track with storing a list of updates in the state. Every time an update finishes, a |
Beta Was this translation helpful? Give feedback.
-
Closing since there's been no activity in a few days, feel free to re-open if you have more to discuss. |
Beta Was this translation helpful? Give feedback.
I would probably lean towards using
runningSideEffect
if it meets your needs, i.e. your doing work inline.Worker
s are a little simpler if you already have a stream, since you can just call.asWorker()
.I think you're on the right track with storing a list of updates in the state. Every time an update finishes, a
WorkflowAction
should remove that update from the list. The library doesn't do any serializing of tasks for you, if you want to execute tasks serially instead of concurrently, you need to implement that yourself (e.g. by using a queue in your state).