daily pastebin goal
24%
SHARE
TWEET

Untitled

a guest Oct 21st, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export const listenTo = <K extends keyof DocumentEventMap>(
  2.   type: K | K[],
  3.   listener: (this: Document, ev: DocumentEventMap[K]) => any,
  4.   options?: boolean | AddEventListenerOptions
  5. ) => {
  6.   if (Array.isArray(type)) {
  7.     type.forEach(typ => {
  8.       document.addEventListener(typ, listener, options);
  9.     });
  10.  
  11.     return () => {
  12.       type.forEach(typ => {
  13.         document.removeEventListener(typ, listener, options);
  14.       });
  15.     };
  16.   } else {
  17.     document.addEventListener(type, listener, options);
  18.     return () => document.removeEventListener(type, listener, options);
  19.   }
  20. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top