diff --git a/src/components/ngRedux.js b/src/components/ngRedux.js index 1b17dde..e34b2d1 100644 --- a/src/components/ngRedux.js +++ b/src/components/ngRedux.js @@ -107,7 +107,7 @@ export default function ngReduxProvider() { const mergedStore = assign({}, store, { connect: Connector(store) }); - if (_providedStore) wrapStore(_providedStore, mergedStore); + if (_providedStore) wrapStore(_providedStore, mergedStore, injector.get('$rootScope')); return mergedStore; }; diff --git a/src/components/storeWrapper.js b/src/components/storeWrapper.js index ae03797..e87e251 100644 --- a/src/components/storeWrapper.js +++ b/src/components/storeWrapper.js @@ -1,5 +1,5 @@ -export default function wrapStore(providedStore, ngReduxStore) { - providedStore.subscribe(() => { +export default function wrapStore(providedStore, ngReduxStore, $rootScope) { + const unsubscribe = providedStore.subscribe(() => { let newState = providedStore.getState(); ngReduxStore.dispatch({ type: '@@NGREDUX_PASSTHROUGH', @@ -7,4 +7,5 @@ export default function wrapStore(providedStore, ngReduxStore) { }); }); providedStore.dispatch({ type: '@@NGREDUX_PASSTHROUGH_INIT' }) + $rootScope.$on('$destroy', unsubscribe) }