Skip to content

Commit

Permalink
unsubscribe on component destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Turgeon committed Aug 30, 2018
1 parent 389c24c commit 33ce2cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions force-app/main/default/aura/Redux/Redux.cmp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<aura:component description="Redux">
<ltng:require scripts="{!$Resource.redux}"/>
<aura:handler name="destroy" value="{!this}" action="{!c.handleUnsubscribe}"/>
<aura:attribute name="name" type="string" default="redux" />
<aura:method name="createStore" action="{!c.createStore}">
<aura:attribute name="name" type="string" />
Expand Down
7 changes: 6 additions & 1 deletion force-app/main/default/aura/Redux/ReduxController.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@

handleChanges();

window.reduxStore[reduxName].subscribe(handleChanges);
component.unsubscribe = window.reduxStore[reduxName].subscribe(handleChanges);
target.dispatch = window.reduxStore[reduxName].dispatch;
} else {
if(window.subscriberQueue && window.subscriberQueue[reduxName]) {
Expand All @@ -179,6 +179,11 @@
}];
}
}
},
handleUnsubscribe: function(component) {
if (component.unsubscribe) {
component.unsubscribe();
}
}

})

0 comments on commit 33ce2cb

Please sign in to comment.