From f13437b880fcea99b4750047d1279f0737a4a3f3 Mon Sep 17 00:00:00 2001 From: Denis Raslov Date: Sun, 14 Jan 2018 00:59:21 +0300 Subject: [PATCH] Fix shouldComponentUpdate --- src/grid/row/index.js | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/grid/row/index.js b/src/grid/row/index.js index c46238b..2fd6bf9 100644 --- a/src/grid/row/index.js +++ b/src/grid/row/index.js @@ -7,16 +7,34 @@ import SpreadsheetCell from './cell'; class SpreadsheetRow extends React.Component { shouldComponentUpdate(nextProps) { - const currentActiveCell = this.props.activeCell || this.props.focusedCell; - const nextActiveCell = nextProps.activeCell || nextProps.focusedCell; + const currentActiveCell = this.props.activeCell; + const nextActiveCell = nextProps.activeCell; + const currentFocusedCell = this.props.focusedCell; + const nextFocusedCell = nextProps.focusedCell; + + const isActiveCellChanged = + (currentActiveCell && !nextActiveCell) + || (!currentActiveCell && nextActiveCell) + || (currentActiveCell && nextActiveCell + && (currentActiveCell.x !== nextActiveCell.x || currentActiveCell.y !== nextActiveCell.y)); + + const isFocusedCellChanged = + (currentFocusedCell && !nextFocusedCell) + || (!currentFocusedCell && nextFocusedCell) + || (currentFocusedCell && nextFocusedCell + && (currentFocusedCell.x !== nextFocusedCell.x || currentFocusedCell.y !== nextFocusedCell.y)); return this.props.row !== nextProps.row || this.props.x !== nextProps.x - || (currentActiveCell && currentActiveCell.x === this.props.x) - || (nextActiveCell && nextActiveCell.x === this.props.x) - || this.props.disabledCells !== nextProps.disabledCells + || JSON.stringify(this.props.disabledCells) !== JSON.stringify(nextProps.disabledCells) || this.props.columns !== nextProps.columns - || this.props.columnWidthValues !== nextProps.columnWidthValues; + || this.props.columnWidthValues !== nextProps.columnWidthValues + || (isActiveCellChanged && + ((currentActiveCell && currentActiveCell.x === this.props.x) + || (nextActiveCell && nextActiveCell.x === this.props.x))) + || (isFocusedCellChanged && + ((currentFocusedCell && currentFocusedCell.x === this.props.x) + || (nextFocusedCell && nextFocusedCell.x === this.props.x))); } render() {