Skip to content

Instantly share code, notes, and snippets.

@richardscarrott
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardscarrott/8f14481d61a7b358e087 to your computer and use it in GitHub Desktop.
Save richardscarrott/8f14481d61a7b358e087 to your computer and use it in GitHub Desktop.
Choreographing view rendering
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