11import * as React from 'react' ;
22import './Styles.css' ;
3- import { debounce } from './Globals/Debounce ' ;
3+ import { throttle } from './Globals/Throttle ' ;
44import { ResizeType } from './Globals/Types' ;
55import * as PropTypes from 'prop-types' ;
66
@@ -16,6 +16,8 @@ interface IProps {
1616 onResizeEnd ?: ( ) => void
1717}
1818
19+ const RESIZE_THROTTLE = 10 ;
20+
1921export const Resizable : React . FC < IProps > = ( props ) => {
2022 const resize = ( originalX : number , originalY : number , x : number , y : number ) => {
2123 const adjustmentX =
@@ -42,8 +44,8 @@ export const Resizable : React.FC<IProps> = (props) => {
4244 let moved = false ;
4345
4446 const touchResize = ( e : TouchEvent ) => resizing && resize ( originalTouchX , originalTouchY , e . touches [ 0 ] . pageX , e . touches [ 0 ] . pageY ) ;
45- const debouncedTouchResize = debounce < typeof touchResize > ( touchResize , 10 ) ;
46- const withPreventDefault = ( e : TouchEvent ) => { moved = true ; e . preventDefault ( ) ; e . stopImmediatePropagation ( ) ; debouncedTouchResize ( e ) ; } ;
47+ const throttledTouchResize = throttle < typeof touchResize > ( touchResize , RESIZE_THROTTLE ) ;
48+ const withPreventDefault = ( e : TouchEvent ) => { moved = true ; e . preventDefault ( ) ; e . stopImmediatePropagation ( ) ; throttledTouchResize ( e ) ; } ;
4749 const removeListener = ( ) => {
4850 resizing = false ;
4951 window . removeEventListener ( 'touchmove' , withPreventDefault ) ;
@@ -64,8 +66,8 @@ export const Resizable : React.FC<IProps> = (props) => {
6466 let moved = false ;
6567
6668 const mouseResize = ( e : MouseEvent ) => resizing && resize ( originalMouseX , originalMouseY , e . pageX , e . pageY ) ;
67- const debouncedMouseResize = debounce < typeof mouseResize > ( mouseResize , 10 ) ;
68- const withPreventDefault = ( e : MouseEvent ) => { moved = true ; e . preventDefault ( ) ; e . stopImmediatePropagation ( ) ; debouncedMouseResize ( e ) ; } ;
69+ const throttledMouseResize = throttle < typeof mouseResize > ( mouseResize , RESIZE_THROTTLE ) ;
70+ const withPreventDefault = ( e : MouseEvent ) => { moved = true ; e . preventDefault ( ) ; e . stopImmediatePropagation ( ) ; throttledMouseResize ( e ) ; } ;
6971 const removeListener = ( ) => {
7072 resizing = false ;
7173 window . removeEventListener ( 'mousemove' , withPreventDefault ) ;
0 commit comments