Skip to content

Commit 1237d52

Browse files
authored
Merge pull request #246 from AprilArcus/cleanup-subscription
unsubscribe from provided store when AngularJS app is destroyed
2 parents 243ec51 + fbfb2cc commit 1237d52

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/components/ngRedux.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export default function ngReduxProvider() {
107107

108108
const mergedStore = assign({}, store, { connect: Connector(store) });
109109

110-
if (_providedStore) wrapStore(_providedStore, mergedStore);
110+
if (_providedStore) wrapStore(_providedStore, mergedStore, injector.get('$rootScope'));
111111

112112
return mergedStore;
113113
};

src/components/storeWrapper.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
export default function wrapStore(providedStore, ngReduxStore) {
2-
providedStore.subscribe(() => {
1+
export default function wrapStore(providedStore, ngReduxStore, $rootScope) {
2+
const unsubscribe = providedStore.subscribe(() => {
33
let newState = providedStore.getState();
44
ngReduxStore.dispatch({
55
type: '@@NGREDUX_PASSTHROUGH',
66
payload: newState
77
});
88
});
99
providedStore.dispatch({ type: '@@NGREDUX_PASSTHROUGH_INIT' })
10+
$rootScope.$on('$destroy', unsubscribe)
1011
}

0 commit comments

Comments
 (0)