What technique shall one use to implement batch insert/update for Backbone.sync?
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.
I guess it depends on your usage scenarios, and how much you want to change the calling code. I think you have two options:
Option 1: No Change to client (calling) code
Oddly enough the annotated source for Backbone.sync gives ‘batching’ as a possible reason for overriding the
syncmethod:Instead of actually saving on sync, add the request to a queue, and only batch-save every so often.
_.throttleor_.delaymight help you here.Option 2: Change client code
Alternatively, instead of calling
saveon your models, you could add some sort ofsavemethod to collections. You’d have to track which models were actually modified and hence in need of update, since as far as I can tell, Backbone only knows whether they’re new or not (but I could be wrong about that).