packages/js-toolkit/services/pointer.js
/**
   * Bind the handler to the mousemove and touchmove events.
   * Bind the up and down handler to the mousedown, mouseup, touchstart and touchend events.
   *
   * @return {Pointer}
   */
Bind the handler to the mousemove and touchmove events.
Bind the up and down handler to the mousedown, mouseup, touchstart and touchend events.

@return {Pointer}
Bind the handler to the mousemove and touchmove events . Bind the up and down handler to the mousedown mouseup touchstart and touchend events . @return { Pointer }
init() {
    const { add, remove } = useRaf();
    this.hasRaf = false;
    const debounced = debounce((event) => {
      this.updateValues(event);
      remove('usePointer');
      this.trigger(this.props);
      this.hasRaf = false;
    }, 50);
    this.handler = throttle((event) => {
      this.updateValues(event);
      if (!this.hasRaf) {
        add('usePointer', () => {
          this.trigger(this.props);
        });
        this.hasRaf = true;
      }
      debounced(event);
    }, 32).bind(this);
    this.downHandler = this.downHandler.bind(this);
    this.upHandler = this.upHandler.bind(this);
    document.documentElement.addEventListener('mouseenter', this.handler, { once: true });
    document.addEventListener('mousemove', this.handler, { passive: true });
    document.addEventListener('touchmove', this.handler, { passive: true });
    document.addEventListener('mousedown', this.downHandler, { passive: true });
    document.addEventListener('touchstart', this.downHandler, { passive: true });
    document.addEventListener('mouseup', this.upHandler, { passive: true });
    document.addEventListener('touchend', this.upHandler, { passive: true });
    return this;
  }
init ( ) { const { add , remove } = useRaf ( ) ; this . hasRaf = false ; const debounced = debounce ( ( event ) => { this . updateValues ( event ) ; remove ( 'usePointer' ) ; this . trigger ( this . props ) ; this . hasRaf = false ; } , 50 ) ; this . handler = throttle ( ( event ) => { this . updateValues ( event ) ; if ( ! this . hasRaf ) { add ( 'usePointer' , ( ) => { this . trigger ( this . props ) ; } ) ; this . hasRaf = true ; } debounced ( event ) ; } , 32 ) . bind ( this ) ; this . downHandler = this . downHandler . bind ( this ) ; this . upHandler = this . upHandler . bind ( this ) ; document . documentElement . addEventListener ( 'mouseenter' , this . handler , { once : true } ) ; document . addEventListener ( 'mousemove' , this . handler , { passive : true } ) ; document . addEventListener ( 'touchmove' , this . handler , { passive : true } ) ; document . addEventListener ( 'mousedown' , this . downHandler , { passive : true } ) ; document . addEventListener ( 'touchstart' , this . downHandler , { passive : true } ) ; document . addEventListener ( 'mouseup' , this . upHandler , { passive : true } ) ; document . addEventListener ( 'touchend' , this . upHandler , { passive : true } ) ; return this ; }
Bind the handler to the mousemove and touchmove events.
Bind the handler to the mousemove and touchmove events .
// Reset changed flags at the end of the mousemove or touchmove event