Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Commit

Permalink
Plt 8299- updated removeEventEmmiters to addEE's so they work (#702)
Browse files Browse the repository at this point in the history
* Fix ModalListener ‘memory leak’ issue

* switched to arrow functions

* matched removes to adds

* remove unused func
  • Loading branch information
stephenkiers authored and saturninoabril committed Feb 2, 2018
1 parent 2e0beb5 commit 8c7f189
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
13 changes: 5 additions & 8 deletions components/navbar/navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export default class Navbar extends React.Component {
ModalStore.addModalListener(ActionTypes.TOGGLE_CHANNEL_NAME_UPDATE_MODAL, this.showRenameChannelModal);
WebrtcStore.addChangedListener(this.onChange);
WebrtcStore.addBusyListener(this.onBusy);
$('.inner-wrap').click(this.hideSidebars);
document.addEventListener('keydown', this.handleQuickSwitchKeyPress);
$('.inner-wrap').on('click', this.hideSidebars);
}

componentWillUnmount() {
Expand All @@ -92,12 +92,13 @@ export default class Navbar extends React.Component {
UserStore.removeChangeListener(this.onChange);
PreferenceStore.removeChangeListener(this.onChange);
ModalStore.removeModalListener(ActionTypes.TOGGLE_QUICK_SWITCH_MODAL, this.toggleQuickSwitchModal);
ModalStore.removeModalListener(ActionTypes.TOGGLE_CHANNEL_HEADER_UPDATE_MODAL, this.hideEditChannelHeaderModal);
ModalStore.removeModalListener(ActionTypes.TOGGLE_CHANNEL_PURPOSE_UPDATE_MODAL, this.hideChannelPurposeModal);
ModalStore.removeModalListener(ActionTypes.TOGGLE_CHANNEL_NAME_UPDATE_MODAL, this.hideRenameChannelModal);
ModalStore.removeModalListener(ActionTypes.TOGGLE_CHANNEL_HEADER_UPDATE_MODAL, this.showEditChannelHeaderModal);
ModalStore.removeModalListener(ActionTypes.TOGGLE_CHANNEL_PURPOSE_UPDATE_MODAL, this.showChannelPurposeModal);
ModalStore.removeModalListener(ActionTypes.TOGGLE_CHANNEL_NAME_UPDATE_MODAL, this.showRenameChannelModal);
WebrtcStore.removeChangedListener(this.onChange);
WebrtcStore.removeBusyListener(this.onBusy);
document.removeEventListener('keydown', this.handleQuickSwitchKeyPress);
$('.inner-wrap').off('click', this.hideSidebars);
}

getStateFromStores = () => {
Expand Down Expand Up @@ -788,10 +789,6 @@ export default class Navbar extends React.Component {
return null;
}

hideEditChannelHeaderModal = () => {
this.setState({showEditChannelHeaderModal: false});
}

showChannelInviteModalButton = () => {
if (this.refs.channelInviteModalButton) {
this.refs.channelInviteModalButton.show();
Expand Down
10 changes: 3 additions & 7 deletions stores/modal_store.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,18 @@ class ModalStoreClass extends EventEmitter {
constructor() {
super();

this.addModalListener = this.addModalListener.bind(this);
this.removeModalListener = this.removeModalListener.bind(this);

this.handleEventPayload = this.handleEventPayload.bind(this);
this.dispatchToken = AppDispatcher.register(this.handleEventPayload);
}

addModalListener(action, callback) {
addModalListener = (action, callback) => {
this.on(action, callback);
}

removeModalListener(action, callback) {
removeModalListener = (action, callback) => {
this.removeListener(action, callback);
}

handleEventPayload(payload) {
handleEventPayload = (payload) => {
// toggle event handlers should accept a boolean show/hide value and can accept a map of arguments
const {type, value, ...args} = payload.action; //eslint-disable-line no-use-before-define

Expand Down

0 comments on commit 8c7f189

Please sign in to comment.