扩展Backbone.sync批量同步? [英] extend Backbone.sync to batch sync?
问题描述
什么技术,必有人用它来实现批量插入/更新Backbone.sync?
What technique shall one use to implement batch insert/update for Backbone.sync?
推荐答案
我想这取决于你的使用场景,多少要改变调用code。我认为你有两个选择:
I guess it depends on your usage scenarios, and how much you want to change the calling code. I think you have two options:
选项1:不改变客户端(呼叫)code
奇怪的是为Backbone.sync 注解源给出了配料为一个可能的原因重写同步
方法:
Oddly enough the annotated source for Backbone.sync gives 'batching' as a possible reason for overriding the sync
method:
使用的setTimeout批量速射更新到一个单一的请求。
Use setTimeout to batch rapid-fire updates into a single request.
而不是实际节省同步,请求加入到队列中,只有批量保存每隔一段时间。 。 _油门
或的 _延时
可以帮助你在这里。
Instead of actually saving on sync, add the request to a queue, and only batch-save every so often. _.throttle
or _.delay
might help you here.
选项2:更改客户端code
此外,而不是调用保存
您的模型,您可以保存方法添加某种来集合。你必须跟踪哪些车型实际上修改,因此需要更新,因为据我所知,只有主干知道它们是否是新的或不(但我可能是错了)。
Alternatively, instead of calling save
on your models, you could add some sort of save
method 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).
这篇关于扩展Backbone.sync批量同步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!