3

I have implemented JSONStore sync process as follows:
1.Push the local changes to the server
2.If pushing data is successful then wipe out all existing local data.
3.Load the fresh copy of data from server.
I need to know is this process of data sync a good way ?
If not then what is the standard and optimized way to do that.

Thanks in Advance

Sanket K.
  • 197
  • 12

1 Answers1

2

That is a perfectly valid way of working with external data. Good job.

cnandreu
  • 5,113
  • 3
  • 25
  • 50
  • ok. But what should be the approach if, i want to load any new data from server to device, without affecting the existing data on device. – Sanket K. Jun 12 '14 at 06:32
  • if `x` was deleted from server -> call the remove API with push false, if `x` was modified on the server -> call the replace API with push false, if `x` was added on the server -> call the add API with push false. The option `{push: false}` means JSONStore won't try to push that change when you call the push API, which is what you want because that change already exists on the server. Some backends make this easier than others, for example CouchDB has a [_changes API](http://couchdb.readthedocs.org/en/latest/api/database/changes.html) that will give you the metadata you need. – cnandreu Jun 12 '14 at 08:02