Last active
August 29, 2015 14:02
-
-
Save richardscarrott/8f14481d61a7b358e087 to your computer and use it in GitHub Desktop.
Choreographing view rendering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var MyCollectionView = Backbone.View.extend({ | |
initialize: function() { | |
this.listenTo(this.collection, 'request', this.showLoader); | |
this.listenTo(this.collection, 'reset', this.render); | |
this.listenTo(this.collection, 'add', this.renderItem); | |
this.listenTo(this.collection, 'remove', this.removeItem); | |
if (this.collection.isReady()) { | |
this.render(); | |
} else { | |
this.showLoader(); | |
} | |
} | |
}); | |
var MyModelView = Backbone.View.extend({ | |
initialize: function() { | |
this.listenTo(this.model, 'request', this.showLoader); | |
this.listenTo(this.model, 'change', this.render); | |
this.listenTo(this.model, 'remove', this.remove); | |
if (this.model.isReady()) { | |
this.render(); | |
} else { | |
this.showLoader(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment