@mirohq/design-system-use-listeners
Advanced tools
Comparing version 0.1.0-use-press.0 to 0.1.0
@@ -9,12 +9,15 @@ 'use strict'; | ||
const globalListeners = react.useRef(/* @__PURE__ */ new Map()); | ||
const removeListener = react.useCallback((eventTarget, type, listener, options) => { | ||
var _a; | ||
const fnGlobalListener = (_a = globalListeners.current.get(listener)) == null ? void 0 : _a.fn; | ||
const fn = fnGlobalListener != null ? fnGlobalListener : listener; | ||
eventTarget.removeEventListener(type, fn, options); | ||
globalListeners.current.delete(listener); | ||
}, []); | ||
const removeListener = react.useCallback( | ||
(eventTarget, type, listener, options) => { | ||
var _a; | ||
const fnGlobalListener = (_a = globalListeners.current.get(listener)) == null ? void 0 : _a.fn; | ||
const fn = fnGlobalListener != null ? fnGlobalListener : listener; | ||
eventTarget.removeEventListener(type, fn, options); | ||
globalListeners.current.delete(listener); | ||
}, | ||
[] | ||
); | ||
const addListener = react.useCallback( | ||
(eventTarget, type, listener, options) => { | ||
const fn = (options == null ? void 0 : options.once) === true ? (...args) => { | ||
const fn = (typeof options === "object" ? options.once === true : false) ? (...args) => { | ||
listener(...args); | ||
@@ -21,0 +24,0 @@ removeListener(eventTarget, type, listener, options); |
@@ -5,12 +5,15 @@ import { useRef, useCallback, useEffect } from 'react'; | ||
const globalListeners = useRef(/* @__PURE__ */ new Map()); | ||
const removeListener = useCallback((eventTarget, type, listener, options) => { | ||
var _a; | ||
const fnGlobalListener = (_a = globalListeners.current.get(listener)) == null ? void 0 : _a.fn; | ||
const fn = fnGlobalListener != null ? fnGlobalListener : listener; | ||
eventTarget.removeEventListener(type, fn, options); | ||
globalListeners.current.delete(listener); | ||
}, []); | ||
const removeListener = useCallback( | ||
(eventTarget, type, listener, options) => { | ||
var _a; | ||
const fnGlobalListener = (_a = globalListeners.current.get(listener)) == null ? void 0 : _a.fn; | ||
const fn = fnGlobalListener != null ? fnGlobalListener : listener; | ||
eventTarget.removeEventListener(type, fn, options); | ||
globalListeners.current.delete(listener); | ||
}, | ||
[] | ||
); | ||
const addListener = useCallback( | ||
(eventTarget, type, listener, options) => { | ||
const fn = (options == null ? void 0 : options.once) === true ? (...args) => { | ||
const fn = (typeof options === "object" ? options.once === true : false) ? (...args) => { | ||
listener(...args); | ||
@@ -17,0 +20,0 @@ removeListener(eventTarget, type, listener, options); |
@@ -0,4 +1,5 @@ | ||
declare type Listener = <KW extends keyof WindowEventMap, KH extends keyof HTMLElementEventMap, K extends keyof DocumentEventMap>(element: EventTarget, eventName: KW | KH | K | string, listener: (event: WindowEventMap[KW] | HTMLElementEventMap[KH] | DocumentEventMap[K] | Event) => void, options?: boolean | AddEventListenerOptions) => void; | ||
interface Listeners { | ||
addListener: (<K extends keyof DocumentEventMap>(el: EventTarget, type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions) => void) & ((el: EventTarget, type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void); | ||
removeListener: (<K extends keyof DocumentEventMap>(el: EventTarget, type: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | EventListenerOptions) => void) & ((el: EventTarget, type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void); | ||
addListener: Listener; | ||
removeListener: Listener; | ||
removeAllListeners: () => void; | ||
@@ -5,0 +6,0 @@ } |
{ | ||
"name": "@mirohq/design-system-use-listeners", | ||
"version": "0.1.0-use-press.0", | ||
"version": "0.1.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "Miro", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
91
12321