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