Skip to content

Commit 33ce2cb

Browse files
author
Andrew Turgeon
committed
unsubscribe on component destroy
1 parent 389c24c commit 33ce2cb

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

force-app/main/default/aura/Redux/Redux.cmp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<aura:component description="Redux">
22
<ltng:require scripts="{!$Resource.redux}"/>
3+
<aura:handler name="destroy" value="{!this}" action="{!c.handleUnsubscribe}"/>
34
<aura:attribute name="name" type="string" default="redux" />
45
<aura:method name="createStore" action="{!c.createStore}">
56
<aura:attribute name="name" type="string" />

force-app/main/default/aura/Redux/ReduxController.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@
163163

164164
handleChanges();
165165

166-
window.reduxStore[reduxName].subscribe(handleChanges);
166+
component.unsubscribe = window.reduxStore[reduxName].subscribe(handleChanges);
167167
target.dispatch = window.reduxStore[reduxName].dispatch;
168168
} else {
169169
if(window.subscriberQueue && window.subscriberQueue[reduxName]) {
@@ -179,6 +179,11 @@
179179
}];
180180
}
181181
}
182+
},
183+
handleUnsubscribe: function(component) {
184+
if (component.unsubscribe) {
185+
component.unsubscribe();
186+
}
182187
}
183188

184189
})

0 commit comments

Comments
 (0)