Created
October 21, 2018 22:06
-
-
Save itsdouges/10d3f3a6a19242185594f723f1aa844b to your computer and use it in GitHub Desktop.
Revisions
-
Madou created this gist
Oct 21, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ export const listenTo = <K extends keyof DocumentEventMap>( type: K | K[], listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions ) => { if (Array.isArray(type)) { type.forEach(typ => { document.addEventListener(typ, listener, options); }); return () => { type.forEach(typ => { document.removeEventListener(typ, listener, options); }); }; } else { document.addEventListener(type, listener, options); return () => document.removeEventListener(type, listener, options); } };