Skip to content

Instantly share code, notes, and snippets.

@publickeating
Created January 28, 2013 18:39
Show Gist options
  • Save publickeating/4657940 to your computer and use it in GitHub Desktop.
Save publickeating/4657940 to your computer and use it in GitHub Desktop.
Allow a collection view to reload if the status of its content changes even if the content's length doesn't change (like with RecordArray's).
myStack: SC.StackedView.extend({
// Observes changes to our content.
contentDidChange: function () {
var previousContent = this.previousContent,
this.get('content');
// Clean up observer on previous content
if (previousContent) {
previousContent.removeObserver('status', this, 'contentStatusDidChange');
}
if (content) {
content.addObserver('status', this, 'contentStatusDidChange');
}
// Reset the previousContent (whether null or not). If this view is destroyed, content should be set to null, clearing out this value.
this.previousContent = content;
}.observes('content'),
// Observes changes in the status of our content.
contentStatusDidChange: function () {
var status = this.getPath('content.status');
// Reload each time that the content's status goes READY again.
if (status & SC.Record.READY) {
this.reload();
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment