Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- };
Add Comment
Please, Sign In to add comment