Skip to content

Commit

Permalink
- refactored part of the "updateScrollbars" method to a new method "s…
Browse files Browse the repository at this point in the history
…houldUpdateScrollbars"

- checks "this.container.current" node exists before continuing the update
  • Loading branch information
Yair Even Or authored and yairEO committed Dec 19, 2022
1 parent 4931ee7 commit 1065aba
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/components/Scrollable/Scrollable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,25 @@ export default class Scrollable extends React.PureComponent {
};
};

updateScrollbars = () => {
this.event.next = this.getEvent();
shouldUpdateScrollbars(event) {
const {next, prev} = event,
changed = next.clientHeight !== prev.clientHeight ||
next.scrollHeight !== prev.scrollHeight ||
next.clientWidth !== prev.clientWidth ||
next.scrollWidth !== prev.scrollWidth ||
next.top !== prev.top ||
next.left !== prev.left;

return changed;
}

const nextEvent = this.event.next,
prevEvent = this.event.prev,
changed = nextEvent.clientHeight !== prevEvent.clientHeight ||
nextEvent.scrollHeight !== prevEvent.scrollHeight ||
nextEvent.clientWidth !== prevEvent.clientWidth ||
nextEvent.scrollWidth !== prevEvent.scrollWidth ||
nextEvent.top !== prevEvent.top ||
nextEvent.left !== prevEvent.left;
updateScrollbars = () => {
const nextEvent = this.event.next = this.getEvent(),
changed = this.shouldUpdateScrollbars(this.event);

// Ensures that updates (which are a potentially expensive operation)
// are only executed if the applicable scroll properties have changed
if (changed) {
if (changed && this.container.current) {
this.props.onUpdate(nextEvent);
const el = this.container.current.parentElement;
const vRatio = nextEvent.clientHeight / nextEvent.scrollHeight;
Expand Down

0 comments on commit 1065aba

Please sign in to comment.