react-flexigrid
Version:
A React table component designed to allow presenting millions of rows of data.
71 lines (58 loc) • 2.01 kB
JavaScript
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import { requestAnimationFrame, getJudgeFunction } from '../utils';
import normalizeWheel from './normalizeWheel';
var WheelHandler =
/**
* onWheel is the callback that will be called with right frame rate if
* any wheel events happened
* onWheel should is to be called with two arguments: deltaX and deltaY in
* this order
*/
function WheelHandler(onWheel, handleScrollX, handleScrollY, stopPropagation) {
_classCallCheck(this, WheelHandler);
_initialiseProps.call(this);
this.deltaX = 0;
this.deltaY = 0;
this.animationFrameID = null;
this.handleScrollX = getJudgeFunction(handleScrollX);
this.handleScrollY = getJudgeFunction(handleScrollY);
this.stopPropagation = getJudgeFunction(stopPropagation);
this.callback = onWheel;
};
var _initialiseProps = function _initialiseProps() {
var _this = this;
this.onWheel = function (e) {
var normalizedEvent = normalizeWheel(e);
var pixelX = normalizedEvent.pixelX,
pixelY = normalizedEvent.pixelY;
var deltaX = _this.deltaX + pixelX;
var deltaY = _this.deltaY + pixelY;
var handleScrollX = _this.handleScrollX(deltaX, deltaY);
var handleScrollY = _this.handleScrollY(deltaY, deltaX);
if (!handleScrollX && !handleScrollY) {
return;
}
_this.deltaX += handleScrollX ? pixelX : 0;
_this.deltaY += handleScrollY ? pixelY : 0;
e.preventDefault();
var changed = void 0;
if (_this.deltaX !== 0 || _this.deltaY !== 0) {
if (_this.stopPropagation()) {
e.stopPropagation();
}
changed = true;
}
if (changed === true && _this.animationFrameID === null) {
_this.animationFrameID = requestAnimationFrame(_this.didWheel);
}
};
this.didWheel = function () {
_this.animationFrameID = null;
if (_this.callback) {
_this.callback(_this.deltaX, _this.deltaY);
}
_this.deltaX = 0;
_this.deltaY = 0;
};
};
export default WheelHandler;