From bd4eacc07eea6b7f4d4cb866eb6f1905f91ec0ab Mon Sep 17 00:00:00 2001 From: Michael Ridgway Date: Mon, 11 May 2015 16:35:23 -0700 Subject: [PATCH] Avoid calling setState when component is being unmounted --- addons/connectToStores.js | 4 +++- tests/unit/lib/FluxibleContext.js | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/connectToStores.js b/addons/connectToStores.js index eeb5f355..1034206c 100644 --- a/addons/connectToStores.js +++ b/addons/connectToStores.js @@ -58,7 +58,9 @@ module.exports = function connectToStores(Component, stores, getStateFromStores) return state; }, _onStoreChange: function onStoreChange() { - this.setState(this.getStateFromStores()); + if (this.isMounted()) { + this.setState(this.getStateFromStores()); + } }, render: function render() { return React.createElement(Component, objectAssign({}, this.props, this.state)); diff --git a/tests/unit/lib/FluxibleContext.js b/tests/unit/lib/FluxibleContext.js index 5987b84f..b1a2e6a6 100644 --- a/tests/unit/lib/FluxibleContext.js +++ b/tests/unit/lib/FluxibleContext.js @@ -344,7 +344,6 @@ describe('FluxibleContext', function () { handlers: { 'TEST': function () { - console.log('Emitting change'); this.emitChange(); } } @@ -377,7 +376,6 @@ describe('FluxibleContext', function () { var storeInstance = actionContext.getStore(store); storeInstance.addChangeListener(function () { - console.log('Got change from store, executing action'); actionContext.executeAction(action2, payload, function () { try { expect(warningCalls.length).to.equal(1);