Skip to content

Commit

Permalink
Merge pull request #135 from STRML/removeIsMounted
Browse files Browse the repository at this point in the history
Remove isMounted()
  • Loading branch information
BinaryMuse committed Sep 17, 2015
2 parents 0537787 + bc70bb9 commit 6c4579e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/store_watch_mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,24 @@ var StoreWatchMixin = function() {
return {
componentDidMount: function() {
var flux = this.props.flux || this.context.flux;
this.mounted = true;
// No autobinding in ES6 classes
this._setStateFromFlux = this._setStateFromFlux.bind(this);
_each(storeNames, function(store) {
flux.store(store).on("change", this._setStateFromFlux);
}, this);
},

componentWillUnmount: function() {
var flux = this.props.flux || this.context.flux;
this.mounted = false;
_each(storeNames, function(store) {
flux.store(store).removeListener("change", this._setStateFromFlux);
}, this);
},

_setStateFromFlux: function() {
if(this.isMounted()) {
if(this.mounted) {
this.setState(this.getStateFromFlux());
}
},
Expand Down

0 comments on commit 6c4579e

Please sign in to comment.