Skip to content

Commit

Permalink
just call forceUpdate if component is mounted
Browse files Browse the repository at this point in the history
  • Loading branch information
layflags committed Sep 23, 2015
1 parent d39ea1c commit 2ced004
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ampersand-react-mixin.js
Expand Up @@ -16,6 +16,12 @@ var deferbounce = function (fn) {
}
};

var safeForceUpdate = function () {
if (this.isMounted()) {
this.forceUpdate();
}
};

module.exports = events.createEmitter({

watch: function (modelOrCollection, opts) {
Expand All @@ -33,9 +39,9 @@ module.exports = events.createEmitter({
return;
}

this.listenTo(modelOrCollection, events, deferbounce(bind(this.forceUpdate, this)));
this.listenTo(modelOrCollection, events, deferbounce(bind(safeForceUpdate, this)));

if (opts.reRender) this.forceUpdate();
if (opts.reRender) safeForceUpdate.call(this);
},

componentDidMount: function () {
Expand Down

0 comments on commit 2ced004

Please sign in to comment.