one-listener
big project?
many contributors?
too many event listeners on window
?
This library aims to gather all handlers in one listener. This way the number of listeners are reduced.
Performance intense listeners are wrapped in a requestAnimationFrame
.
If a certain limit of handlers is reached events will be throttled.
Everything is configurable. You can even create your own module and lock certain features.
available listeners
- scroll
- resize
- mousewheel
- mousemove
- mouseup (default behavior)
- touchmove
- touchend (default behavior)
API
A detailed documentation can be found here
You can also take a look at the examples
Pride
installation
npm install one-listener
Examples
Look at the examples folder for a detailed example
simple
; const one = limit: 6 throttle: 200;const requestEventListener cancelEventListener = one;
API
;const one = const requestEventListener cancelEventListener = one; // request mousemove const stopMoveTracking = ; // request scroll// and cancel mousemove on condition const trackScroll = { console; if windowscrollY > 100 ; }; ; // remove scroll tracking after 5 seconds;
Setters
; const one = ;onelimit = 20onethrottle = 200
Getters
; const one = ;console;console;console;
locked instances
; // create locked instances (listeners.js)const o = limit: 6 throttle: 200;const n = limit: Infinity;const a = limit: 0 throttle: 100; const one = requestEventListener: orequestEventListener cancelEventListener: ocancelEventListenerconst always = requestEventListener: arequestEventListener cancelEventListener: acancelEventListenerconst never = requestEventListener: nrequestEventListener cancelEventListener: ncancelEventListener // then import (somefile.js) ;const requestEventListener cancelEventListener = one; //requestEventListener() || one.requestEventListener()//always.requestEventListener()//never.requestEventListener()