Skip to content

Instantly share code, notes, and snippets.

@ecancino
Created August 6, 2015 19:03
Show Gist options
  • Select an option

  • Save ecancino/342b3edc06d966e87e41 to your computer and use it in GitHub Desktop.

Select an option

Save ecancino/342b3edc06d966e87e41 to your computer and use it in GitHub Desktop.
BackboneMixin
var BackboneMixin = {
componentDidMount: function () {
// Whenever there may be a change in the Backbone data, trigger a
// reconcile.
this.getBackboneCollections().forEach(function (collection) {
// explicitly bind `null` to `forceUpdate`, as it demands a callback and
// React validates that it's a function. `collection` events passes
// additional arguments that are not functions
collection.on('add remove change', this.forceUpdate.bind(this, null));
}, this);
},
componentWillUnmount: function () {
// Ensure that we clean up any dangling references when the component is
// destroyed.
this.getBackboneCollections().forEach(function (collection) {
collection.off(null, null, this);
}, this);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment