-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
types(useEventListener): fix typos #4787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
() => void
with Fn
() => void
with Fn
@@ -64,10 +67,10 @@ export function useEventListener<E extends keyof WindowEventMap>( | |||
* @param listener | |||
* @param options | |||
*/ | |||
export function useEventListener<E extends keyof DocumentEventMap>( | |||
export function useEventListener<E extends keyof DocumentOrShadowRootEventMap>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be two overloads instead. otherwise this means we can add shadow root event listeners to a document
something like:
function useEventListener<E extends keyof DocumentEventMap>(
target: Document,
event: MaybeRefOrGetter<Arrayable<E>>,
listener: MaybeRef<Arrayable<(this: Document, ev: DocumentEventMap[E]) => any>>,
options?: MaybeRefOrGetter<boolean | AddEventListenerOptions>
): Fn;
function useEventListener<E extends keyof ShadowRootEventMap>(
target: ShadowRoot,
event: MaybeRefOrGetter<Arrayable<E>>,
listener: MaybeRef<Arrayable<(this: ShadowRoot, ev: DocumentEventMap[E]) => any>>,
options?: MaybeRefOrGetter<boolean | AddEventListenerOptions>
): Fn;
function useEventListener<E extends keyof DocumentOrShadowRootEventMap>(
target: DocumentOrShadowRoot,
event: MaybeRefOrGetter<Arrayable<E>>,
listener: MaybeRef<Arrayable<(this: DocumentOrShadowRoot, ev: DocumentEventMap[E]) => any>>,
options?: MaybeRefOrGetter<boolean | AddEventListenerOptions>
): Fn {
// implementation
}
that also means the this
of the event listener will be correctly typed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need a mixture of both
#4788 is what I was describing, but should be using the shadow root event map
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function useEventListener<E extends keyof DocumentEventMap>(
target: Document,
event: MaybeRefOrGetter<Arrayable<E>>,
listener: MaybeRef<Arrayable<(this: Document, ev: DocumentEventMap[E]) => any>>,
options?: MaybeRefOrGetter<boolean | AddEventListenerOptions>
): Fn;
function useEventListener<E extends keyof ShadowRootEventMap>(
target: ShadowRoot,
event: MaybeRefOrGetter<Arrayable<E>>,
listener: MaybeRef<Arrayable<(this: ShadowRoot, ev: DocumentEventMap[E]) => any>>,
options?: MaybeRefOrGetter<boolean | AddEventListenerOptions>
): Fn;
removed DocumentOrShadowRootEventMap
and relatived defination
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi, we share the same view. You can take a look at my pr. I think the most important thing is "this" in the listener. Because shadowRoot has attributes that other nodes do not have.such as host,mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to me
if you get chance, its probably worth adding a test which uses a shadow root
Before submitting the PR, please make sure you do the following
fixes #123
).Description
Additional context