I see that Backbone.JS offers two methods of syncing the data from backend: fetch and sync. From their documentation, fetch can also be used as sync:
The behavior of fetch can be customized by using the available set options. For example, to fetch a collection, getting an "add" event for every new model, and a "change" event for every changed existing model, without removing anything: collection.fetch({remove: false})
Can someone please explain when to use which?
Sync is an underlying method used to interact (create/read/update/delete) with the server. Fetch
is a subset of sync
, used only to pull (read) data from the server. You can use sync
exclusively, but you'd find that you'd need to do extra work every time you wanted to simply retrieve the model/collection.
In practice, I rarely need to use sync
. Instead, I rely on fetch
, save
and destroy
- all of which delegate to the underlying sync
method.