-
-
Save eiriklv/611f08af01b156bc238a to your computer and use it in GitHub Desktop.
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 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