From dd15bc0ad1897bf28b0b641bdb66a0209fe2baf2 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Wed, 4 Jan 2017 12:44:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=81=20=D1=80=D0=B0=D0=B7=D0=BC=D0=BE=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/recent-torrents.js | 9 +++++++-- src/search.js | 15 +++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/recent-torrents.js b/src/recent-torrents.js index c565bfd..3c8f04b 100644 --- a/src/recent-torrents.js +++ b/src/recent-torrents.js @@ -152,12 +152,17 @@ export default class RecentTorrents extends Component { this.torrents = data; this.forceUpdate(); }); - window.torrentSocket.on('newTorrent', (torrent) => { + this.newTorrentFunc = (torrent) => { this.torrents.unshift(torrent); if(this.torrents.length > 10) this.torrents.pop() this.forceUpdate(); - }); + }; + window.torrentSocket.on('newTorrent', this.newTorrentFunc); + } + componentWillUnmount() { + if(this.newTorrentFunc) + window.torrentSocket.off('newTorrent', this.newTorrentFunc); } render() { if(!this.torrents || this.torrents.length == 0) diff --git a/src/search.js b/src/search.js index 276075b..ab2f320 100644 --- a/src/search.js +++ b/src/search.js @@ -46,14 +46,17 @@ export default class Search extends Component { }); } componentDidMount() { - window.torrentSocket.emit('statistic', (statistic) => { + this.newStatisticFunc = (statistic) => { this.stats = statistic; this.forceUpdate(); - }); - window.torrentSocket.on('newStatistic', (statistic) => { - this.stats = statistic; - this.forceUpdate(); - }); + }; + window.torrentSocket.emit('statistic', this.newStatisticFunc); + window.torrentSocket.on('newStatistic', this.newStatisticFunc); + } + componentWillUnmount() + { + if(this.newStatisticFunc) + window.torrentSocket.off('newStatistic', this.newStatisticFunc); } render() { const style = {