Created
August 6, 2015 19:03
-
-
Save ecancino/342b3edc06d966e87e41 to your computer and use it in GitHub Desktop.
BackboneMixin
This file contains hidden or 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 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