0

We're developing an app using React Native and MobX for the state stores, and also using a Web API REST service for the GETs and POSTs. All is going well, so far we're able to use FETCH to get the data, persist it in the relevant store using MobX and populate ListViews etc from that store...

Where I'd like some guidance now is how best to handle updates and posting the changes back to the server?

How do people normally do it? My thinking was updating the item in the store, marking that record as 'dirty' and having some sort of background timed loop going through all the 'dirty' records and syncing them up via a POST then resetting that 'dirty' flag on a successful post completion and then both the client and the server would have identical data?

Any help/advice is most appreciated!

Cheers, Adam.

3
  • 1
    please don't cross-post: stackoverflow.com/questions/48991796/… "Cross-posting is frowned upon as it leads to fragmented answers splattered all over the network..."
    – gnat
    Feb 28, 2018 at 10:09
  • @gnat I've just deleted my original question from StackOverflow. I've posted it here instead as I feel it's probably more of a software-engineering question...
    – API
    Feb 28, 2018 at 10:12
  • Not sure if this could help - softwareengineering.stackexchange.com/questions/132735/… Not technology specific but 'a-way' of doing the sync aspect. If anyone has any technology specific answers it would be great - I am also very interested in a specific solution/
    – ree6
    Feb 28, 2018 at 10:18

1 Answer 1

4

The best practice is to use persistent storage which facilitates offline-first development and offers built-in client/server data sync, such as PouchDB/CouchDB:

The PouchDB API provides a method for bidirectional data replication. It accepts the live option, so that all changes continue to be replicated, and the retry option, to attempt replications if the application goes offline.

We can also subscribe to the changes feed so that after receiving a change — either from the remote server or the local user — the UI is updated, either by creating, updating or deleting a document.

Use SQLite to store the data locally in the React Native app and add an adapter which matches one of the APIs supported by PouchDB to push data back to the server.

PouchDB Adapters

References

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.