1

Consider you have two todo list apps for the same service, using the same database - a webapp and a react native app. A user can be logged in to their account on both and create/update/delete their notes from both.

Consider those apps are using redux-persist, e.g. the native app persists the store to AsyncStorage and hydrates it when the app starts, so users could see their notes faster.

Consider a user has 2 todo items and is logged in with both apps, two todo items are present in the db, and in redux stores of both webapp and react native app. Then the user shuts down the react native app and deletes one todo item from the webapp. Since it was the webapp which initiated deletion, an action was dispatched and the item was purged from the store and from the persistence layer (say, localstorage) of the webapp. But, the react native app was offline, so, when the user starts the react native app, its store gets hydrated from AsyncStorage, and the deleted todo item gets shown to the user. How can such a situation be fixed?

If the user deleted a todo item from the app, it's easy to track that the item was deleted (because an action was dispatched) and to purge it from the persistence layer, but what if that action was dispatched by another app (as in the example - by the webapp, opposed to the react native app), or even was manually deleted from the db by an admin? I'd have to somehow distinguish deleted items from not deleted. How?

I've thought about an approach like: "when todos are fetched, purge them all from the persistence layer" but this doesn't look like a good fit in case if I have several ways to fetch them - e.g. by tag, by date, etc, in such case I'd end up purging stuff I need.

What solution/pattern could you suggest to solve such problem?

tristantzara
  • 5,597
  • 6
  • 26
  • 40

0 Answers0