前回の続きでもあるんですが、複数のViewが連携して再描画(render)するとき、再描画のきっかけとなったViewは再描画しなくてもいいということがあります。
色々試した結果、view.cidをrenderを呼び出すtriggerに渡してあげてcidをチェックすることで不要な再描画が避けれました。
逆にcidを管理してcidが一致したら処理といったことにも使えるかも
view.ts
class View extends Backbone.View{
constructor(options?){
super(options)
this.listentTo(this.event,'render',this.render);
}
render(cid?){
//cidが一致すれば何もしない
if(this.cid == cid) return this;
…//処理内容
return this;
}
}
View.prototype.event=_.extend({},Backbone.Events);
呼び出し側
var view1 = new View();
var view2 = new View();
view1.event.trigger('render',view1.cid);
//view1はrenderされない