From 7f8a2f6d8500de94466cbf3ad15d99834805d13a Mon Sep 17 00:00:00 2001 From: Luminarys Date: Sun, 25 Feb 2018 16:18:39 -0800 Subject: [PATCH] Implement shouldComponentUpdate for torrent table --- src/ui/torrent_table.js | 99 ++++++++++++++++++++++++++--------------- 1 file changed, 63 insertions(+), 36 deletions(-) diff --git a/src/ui/torrent_table.js b/src/ui/torrent_table.js index c51cc6d..c80d5de 100644 --- a/src/ui/torrent_table.js +++ b/src/ui/torrent_table.js @@ -5,15 +5,16 @@ import { formatBitrate } from '../bitrate'; import Ratio from './ratio'; import TorrentProgress from './torrent_progress'; +const name_style = { + maxWidth: `${window.innerWidth * 0.25}px`, + textOverflow: 'ellipsis', + overflowX: 'hidden', + whiteSpace: 'nowrap' +}; + class TorrentTable extends Component { render() { const { selection, torrents, dispatch } = this.props; - const name_style = { - maxWidth: `${window.innerWidth * 0.25}px`, - textOverflow: 'ellipsis', - overflowX: 'hidden', - whiteSpace: 'nowrap' - }; return ( @@ -46,37 +47,12 @@ class TorrentTable extends Component { {Object.values(torrents).slice().sort((a, b) => a.name.localeCompare(b.name)).map(t => - - - - - - - - + /> )}
- - dispatch(selectTorrent([t.id], e.target.checked ? UNION : SUBTRACT)) - } - /> - - { - e.preventDefault(); - dispatch(selectTorrent([t.id], EXCLUSIVE)); - }} - >{t.name} - {formatBitrate(t.rate_up)}{formatBitrate(t.rate_down)}
@@ -84,6 +60,57 @@ class TorrentTable extends Component { } } +class Torrent extends Component { + shouldComponentUpdate(nextProps, _) { + const { selection, torrent } = this.props; + const nt = nextProps.torrent; + const active = selection.indexOf(torrent.id); + const nActive = nextProps.selection.indexOf(torrent.id); + return active !== nActive + || torrent.id !== nt.id + || torrent.status !== nt.status + || torrent.rate_down !== nt.rate_down + || torrent.rate_up !== nt.rate_up; + } + + render() { + const { dispatch, selection, torrent } = this.props; + const t = torrent; + return ( + + + + dispatch(selectTorrent([t.id], e.target.checked ? UNION : SUBTRACT)) + } + /> + + + { + e.preventDefault(); + dispatch(selectTorrent([t.id], EXCLUSIVE)); + }} + >{t.name} + + {formatBitrate(t.rate_up)} + {formatBitrate(t.rate_down)} + + + + ); + } +} + export default connect(state => ({ torrents: state.torrents, selection: state.selection,