Skip to content

Commit 5c04fd8

Browse files
committed
chore(ViewportProvider): make throttle and debounce usage more expressive
1 parent d881d7a commit 5c04fd8

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

lib/ViewportProvider.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,9 @@ export default class ViewportProvider extends React.PureComponent {
103103
super(props);
104104
this.scrollState = createInitScrollState();
105105
this.dimensionsState = createInitDimensionsState();
106-
this.handleScroll = throttle(this.handleScroll, 16, {
107-
leading: true,
108-
trailing: false,
109-
});
110-
this.handleResize = debounce(this.handleResize, 80);
111106
}
112107

113-
handleScroll = () => {
108+
handleScroll = throttle(() => {
114109
const { x, y } = getNodeScroll();
115110
const {
116111
xDir: prevXDir,
@@ -130,13 +125,16 @@ export default class ViewportProvider extends React.PureComponent {
130125

131126
this.scrollState.x = x;
132127
this.scrollState.y = y;
133-
};
128+
}, 16, {
129+
leading: true,
130+
trailing: false,
131+
});
134132

135-
handleResize = () => {
133+
handleResize = debounce(() => {
136134
const { width, height } = getClientDimensions();
137135
this.dimensionsState.width = width;
138136
this.dimensionsState.height = height;
139-
};
137+
}, 80);
140138

141139
componentDidMount() {
142140
window.addEventListener('scroll', this.handleScroll, false);

0 commit comments

Comments
 (0)