From 274a2a58f0cb420b1b24495dcaa7ae2d2ffd7bec Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Wed, 4 May 2016 10:10:19 -0400 Subject: Performance improvments (#2869) --- webapp/components/sidebar.jsx | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'webapp/components/sidebar.jsx') diff --git a/webapp/components/sidebar.jsx b/webapp/components/sidebar.jsx index 4ce89d37c..71091f12b 100644 --- a/webapp/components/sidebar.jsx +++ b/webapp/components/sidebar.jsx @@ -47,7 +47,6 @@ export default class Sidebar extends React.Component { this.onScroll = this.onScroll.bind(this); this.updateUnreadIndicators = this.updateUnreadIndicators.bind(this); this.handleLeaveDirectChannel = this.handleLeaveDirectChannel.bind(this); - this.handleResize = this.handleResize.bind(this); this.showMoreChannelsModal = this.showMoreChannelsModal.bind(this); this.showNewChannelModal = this.showNewChannelModal.bind(this); @@ -64,7 +63,6 @@ export default class Sidebar extends React.Component { state.newChannelModalType = ''; state.showDirectChannelsModal = false; state.loadingDMChannel = -1; - state.windowWidth = Utils.windowWidth(); this.state = state; } getTotalUnreadCount() { @@ -150,8 +148,6 @@ export default class Sidebar extends React.Component { this.updateTitle(); this.updateUnreadIndicators(); - - window.addEventListener('resize', this.handleResize); } shouldComponentUpdate(nextProps, nextState) { if (!Utils.areObjectsEqual(nextState, this.state)) { @@ -173,20 +169,12 @@ export default class Sidebar extends React.Component { } } componentWillUnmount() { - window.removeEventListener('resize', this.handleResize); - ChannelStore.removeChangeListener(this.onChange); UserStore.removeChangeListener(this.onChange); UserStore.removeStatusesChangeListener(this.onChange); TeamStore.removeChangeListener(this.onChange); PreferenceStore.removeChangeListener(this.onChange); } - handleResize() { - this.setState({ - windowWidth: Utils.windowWidth(), - windowHeight: Utils.windowHeight() - }); - } onChange() { this.setState(this.getStateFromStores()); } @@ -492,6 +480,7 @@ export default class Sidebar extends React.Component { return (
); } + this.lastBadgesActive = this.badgesActive; this.badgesActive = false; // keep track of the first and last unread channels so we can use them to set the unread indicators @@ -508,21 +497,23 @@ export default class Sidebar extends React.Component { }); // update the favicon to show if there are any notifications - var link = document.createElement('link'); - link.type = 'image/x-icon'; - link.rel = 'shortcut icon'; - link.id = 'favicon'; - if (this.badgesActive) { - link.href = redFavicon; - } else { - link.href = favicon; - } - var head = document.getElementsByTagName('head')[0]; - var oldLink = document.getElementById('favicon'); - if (oldLink) { - head.removeChild(oldLink); + if (this.lastBadgesActive !== this.badgesActive) { + var link = document.createElement('link'); + link.type = 'image/x-icon'; + link.rel = 'shortcut icon'; + link.id = 'favicon'; + if (this.badgesActive) { + link.href = redFavicon; + } else { + link.href = favicon; + } + var head = document.getElementsByTagName('head')[0]; + var oldLink = document.getElementById('favicon'); + if (oldLink) { + head.removeChild(oldLink); + } + head.appendChild(link); } - head.appendChild(link); var directMessageMore = (
  • -- cgit v1.2.3-1-g7c22