исправление ошибки с размонтированием

This commit is contained in:
Alexey Kasyanchuk 2017-01-04 12:44:48 +03:00
parent 7101487269
commit dd15bc0ad1
2 changed files with 16 additions and 8 deletions

View File

@ -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)

View File

@ -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 = {