Skip to content

Commit

Permalink
Add shouldComponentUpdate (closes #13)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanem committed Dec 29, 2015
1 parent b2ec3b4 commit bb0a0a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -93,4 +93,4 @@
"clamp": "^1.0.1",
"lodash.isfunction": "^3.0.6"
}
}
}
14 changes: 9 additions & 5 deletions src/Salvager.js
Expand Up @@ -11,7 +11,8 @@ export default class Salvager extends Component {
bufferStart: 0,
isUpdating: false,
rowHeight: 0,
rowWrapperTransform: ''
rowWrapperTransform: '',
visibleAreaOffsetHeight: 0
};
}

Expand Down Expand Up @@ -52,6 +53,13 @@ export default class Salvager extends Component {
});
}

shouldComponentUpdate(nextProps, nextState) {
return (
nextState.bufferStart !== this.state.bufferStart ||
nextState.rowHeight !== this.state.rowHeight
);
}

_buildRows() {
let RenderedRow = Row;
if (this.props.getRow) RenderedRow = this.props.getRow();
Expand Down Expand Up @@ -81,10 +89,6 @@ export default class Salvager extends Component {
const bufferMidPoint = Math.floor(midPoint / this.state.rowHeight);
let bufferStart = clamp(Math.floor(bufferMidPoint - this.props.bufferSize / 2), 0, this.props.data.length - this.props.bufferSize);

if (bufferStart === this.state.bufferStart) {
return this.setState({ isUpdating: false });
}

this.setState({
bufferStart,
isUpdating: false,
Expand Down

0 comments on commit bb0a0a8

Please sign in to comment.