Remove SessionStore listener on unmount

pull/21833/head
Luke Barnard 2017-05-15 17:17:32 +01:00
parent eb0041d21a
commit 269fd51130
2 changed files with 15 additions and 2 deletions

View File

@ -79,12 +79,17 @@ export default React.createClass({
document.addEventListener('keydown', this._onKeyDown); document.addEventListener('keydown', this._onKeyDown);
this._sessionStore = sessionStore; this._sessionStore = sessionStore;
this._sessionStore.addListener(this._setStateFromSessionStore); this._removeSSListener = this._sessionStore.addListener(
this._setStateFromSessionStore,
).remove;
this._setStateFromSessionStore(); this._setStateFromSessionStore();
}, },
componentWillUnmount: function() { componentWillUnmount: function() {
document.removeEventListener('keydown', this._onKeyDown); document.removeEventListener('keydown', this._onKeyDown);
if (this._removeSSListener) {
this._removeSSListener();
}
}, },
getScrollStateForRoom: function(roomId) { getScrollStateForRoom: function(roomId) {

View File

@ -69,11 +69,19 @@ module.exports = React.createClass({
componentWillMount: function() { componentWillMount: function() {
this._sessionStore = sessionStore; this._sessionStore = sessionStore;
this._sessionStore.addListener(this._setStateFromSessionStore); this._removeSSListener = this._sessionStore.addListener(
this._setStateFromSessionStore,
).remove;
this._setStateFromSessionStore(); this._setStateFromSessionStore();
}, },
componentWillUnmount: function() {
if (this._removeSSListener) {
this._removeSSListener();
}
},
_setStateFromSessionStore: function() { _setStateFromSessionStore: function() {
this.setState({ this.setState({
cachedPassword: this._sessionStore.getCachedPassword(), cachedPassword: this._sessionStore.getCachedPassword(),