Created
October 3, 2014 21:58
-
-
Save hasdavidc/2dc1b87f500d63278f05 to your computer and use it in GitHub Desktop.
This file contains 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 StoreListenerMixin = function(...stores) { | |
var StoreMixin = { | |
getInitialState() { | |
return this.getStateFromStores(this.props); | |
}, | |
componentDidMount() { | |
stores.forEach(store => store.addChangeListener(this.handleStoresChanged)); | |
this.setState(this.getStateFromStores(this.props)); | |
}, | |
componentWillUnmount() { | |
stores.forEach(store => store.removeChangeListener(this.handleStoresChanged)); | |
}, | |
handleStoresChanged() { | |
if (this.isMounted()) { | |
this.setState(this.getStateFromStores(this.props)); | |
} | |
} | |
}; | |
return StoreMixin; | |
}; | |
module.exports = StoreListenerMixin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment