4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Backbone.Viewの不要な再描画を避けるようにする

Last updated at Posted at 2013-08-30

前回の続きでもあるんですが、複数の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されない

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?