Skip to content

Commit

Permalink
unsubscribe from Redux when AngularJS app is destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
AprilArcus committed Apr 18, 2022
1 parent 243ec51 commit 8bf7818
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/ngRedux.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down
5 changes: 3 additions & 2 deletions src/components/storeWrapper.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
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',
payload: newState
});
});
providedStore.dispatch({ type: '@@NGREDUX_PASSTHROUGH_INIT' })
$rootScope.$on('$destroy', unsubscribe)
}

0 comments on commit 8bf7818

Please sign in to comment.