Skip to content

Commit

Permalink
feat(setRootNode): save call to getComputedStyle if root node is unch…
Browse files Browse the repository at this point in the history
…anged
  • Loading branch information
Rendez committed Nov 1, 2017
1 parent f5317d8 commit 80659dd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"eslint-plugin-import": "^2.7.0",
"eslint-plugin-prettier": "^2.3.0",
"eslint-plugin-react": "^7.3.0",
"flow-bin": "^0.57.1",
"husky": "^0.14.3",
"intersection-observer": "^0.4.2",
"jest": "^21.0.1",
Expand Down
8 changes: 6 additions & 2 deletions src/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ export default class List extends React.PureComponent {
}

setRef = callback => {
let prevRootNode;
this.setRootNode = node => {
const overflow = window.getComputedStyle(node)[AXIS_CSS_MAP[this.props.axis]];
callback(['auto', 'scroll', 'overlay'].includes(overflow) ? node : null);
if (node !== prevRootNode) {
prevRootNode = node;
const overflow = window.getComputedStyle(node)[AXIS_CSS_MAP[this.props.axis]];
callback(['auto', 'scroll', 'overlay'].indexOf(overflow) !== -1 ? node : null);
}
};
};

Expand Down
6 changes: 6 additions & 0 deletions src/__tests__/List.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ describe('setRootNode', () => {
createTree({ currentLength: 20 });
expect(mockCallback).toBeCalledWith(null);
});

test('having same root node prevents call getComputedStyle', () => {
const tree = createTree({ currentLength: 20 });
tree.getInstance().setRootNode(target);
expect(window.getComputedStyle).toHaveBeenCalledTimes(1);
});
});

describe('handleUpdate', () => {
Expand Down
10 changes: 3 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
dependencies:
"@researchgate/eslint-config-rg-base" "^1.0.0"

"@researchgate/react-intersection-observer@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@researchgate/react-intersection-observer/-/react-intersection-observer-0.3.1.tgz#189e32c85d0b3a70e12d8408aa52e89da4e8bc85"
"@researchgate/react-intersection-observer@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@researchgate/react-intersection-observer/-/react-intersection-observer-0.4.0.tgz#703af3398ea327ba9633718582c528b95da70ef2"
dependencies:
invariant "^2.2.2"
prop-types "^15.5.10"
Expand Down Expand Up @@ -3247,10 +3247,6 @@ flatten@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.2.tgz#dae46a9d78fbe25292258cc1e780a41d95c03782"

flow-bin@^0.56.0:
version "0.56.0"
resolved "https://registry.yarnpkg.com/flow-bin/-/flow-bin-0.56.0.tgz#ce43092203a344ba9bf63c0cabe95d95145f6cad"

for-in@^1.0.1:
version "1.0.2"
resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80"
Expand Down

0 comments on commit 80659dd

Please sign in to comment.