Anyways using sync method only in collection or only in model can suffice, then why do they have to sync at both the places?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Actually both
sync()methods are just proxies to a commonBackbone.sync()method:Collection always delegate in the
Model.sync()for individual operations over its individual models like:create,removeand so on. But Collection uses its ownsync()in thefetch()operation due it is very different tofetcha Model or a Collection, for example: the URL follows another patter and the backend layer should respond different.In the other hand I see the
Backbone.sync()as a private method and I try to not use it directly, if I’m doing this I don’t feel well. I think thesync()method is a handler point to allow you to overwrite completely the backend synchronization a method that you can overwrite to implement different persistance layers as for example using LocalStorage. But not for be called directly.As @JMM has said in the comments, the
Model.sync()andCollection.sync()is also a good point to be overwrote to make it “does something custom and then callsBackbone.sync()to carry on as usual”.