import { isFunction } from "./functionUtils" ; export function elementIsOrContains ( element , testElement ) { return element === testElement || element . contains ( testElement ) ; } see https export function throttleEvent ( target , eventName , newEventName ) { const throttledFunc = throttleImpl ( ( event ) => { target . dispatchEvent ( new CustomEvent ( newEventName , event ) ) ; } ) ; target . addEventListener ( eventName , throttledFunc ) ; return throttledFunc ; } export interface IThrottledReactEventOptions { preventDefault ? : boolean ; } see https export function throttleReactEventCallback < E extends React . SyntheticEvent = React . SyntheticEvent > ( callback , options = { } ) { const throttledFunc = throttleImpl ( callback , ( event2 ) => { if ( options . preventDefault ) { event2 . preventDefault ( ) ; } } , ( event2 ) => event2 . persist ( ) ) ; return throttledFunc ; } /**
 * Throttle a method by wrapping it in a `requestAnimationFrame` call. Returns
 * the throttled function.
 */ export function throttle < T extends Function > ( method ) { return throttleImpl ( method ) ; } function throttleImpl < T extends Function > ( onAnimationFrameRequested , onBeforeIsRunningCheck ? , onAfterIsRunningCheck ? ) { let isRunning = false ; const func = ( ... args ) => { if ( isFunction ( onBeforeIsRunningCheck ) ) { onBeforeIsRunningCheck ( ... args ) ; } if ( isRunning ) { return ; } isRunning = true ; if ( isFunction ( onAfterIsRunningCheck ) ) { onAfterIsRunningCheck ( ... args ) ; } requestAnimationFrame ( ( ) => { onAnimationFrameRequested ( ... args ) ; isRunning = false ; } ) ; } ; return ( func as any ) as T ; }