Skip to content

Commit

Permalink
used lodash.debounce for debouncing resizing event
Browse files Browse the repository at this point in the history
fixes: akiran#233
  • Loading branch information
laveesingh committed Apr 2, 2018
1 parent 4814b2b commit deb98db
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"classnames": "^2.2.5",
"enquire.js": "^2.1.6",
"json2mq": "^0.2.0",
"lodash.debounce": "^4.0.8",
"resize-observer-polyfill": "^1.5.0"
},
"peerDependencies": {
Expand Down
18 changes: 5 additions & 13 deletions src/inner-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import React from 'react';
import ReactDOM from 'react-dom'
import initialState from './initial-state';
import debounce from 'lodash.debounce'
import classnames from 'classnames';
import { getOnDemandLazySlides, extractObject, initializedState, getHeight,
canGoNext, slideHandler, changeSlide, keyHandler, swipeStart, swipeMove,
Expand All @@ -26,8 +27,7 @@ export class InnerSlider extends React.Component {
}
this.callbackTimers = []
this.clickable = true
this.resizeQueue = 0
this.resizeQueueTimer = null
this.debouncedResize = null
}
listRefHandler = ref => this.list = ref
trackRefHandler = ref => this.track = ref
Expand Down Expand Up @@ -140,17 +140,9 @@ export class InnerSlider extends React.Component {
this.adaptHeight();
}
onWindowResized = (setTrackStyle) => {
this.resizeQueue += 1
if (this.resizeQueueTimer === null) {
this.resizeQueueTimer = setInterval(() => {
this.resizeQueue /= 1.2
if (this.resizeQueue < 1) {
this.resizeWindow(setTrackStyle) // setTrackStyle value may not be correct
clearInterval(this.resizeQueueTimer)
this.resizeQueueTimer = null
}
}, 50)
}
if (this.debouncedResize) this.debouncedResize.cancel()
this.debouncedResize = debounce(() => this.resizeWindow(setTrackStyle), 50)
this.debouncedResize()
}
resizeWindow = (setTrackStyle=true) => {
if (!ReactDOM.findDOMNode(this.track)) return
Expand Down

0 comments on commit deb98db

Please sign in to comment.