-
Notifications
You must be signed in to change notification settings - Fork 2.7k
change argument order for on function with AbortSignal #10810
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
|
I actually had a similar thought about the 2nd on(button, { keydown }, { capture: true, once: true })
// or even
on(button, { keydown }, true) // useCaptureThe 3rd arg would essentially be the exact same as the 3rd arg to |
|
The API is mostly in service to creating elements with JSX. How would you do this? <div
on={{
click: capture(() => {
// ...
}),
focus: () => {
// not captured
},
}}
/> |
|
The reason the signal is the optional second arg is just because it's butt ugly with prettier when it's the last arg ```tsx
function ComponentWithWindowEvents(this: Remix.Handle) {
on(window, this.signal, {
scroll: () => {},
focus: capture(() => {}),
beforeunload: () => {},
})
return () => {
// ...
}
}
function ComponentWithWindowEvents(this: Remix.Handle) {
on(
window,
{
scroll: () => {},
focus: capture(() => {}),
beforeunload: () => {},
},
{ signal: this.signal },
)
return () => {
// ...
}
}While I originally was thinking of this as a thin wrapper over |
|
For what it's worth, I had the same thought when reading the docs yesterday, but thought I might just be missing something. If the main reason is because of the prettier formatting ugliness, I personally don't think that's enough of a reason to not make the signal the 3rd argument. I also don't mind how it reads that badly, and if I really did care that much I'd just curry it and call onWindow(
{
scroll: () => {},
focus: capture(() => {}),
beforeunload: () => {},
},
{ signal: this.signal },
)Either way, a 2nd argument being the optional argument feels really weird on top of it deviating a bit in structure from what devs will be used to with |
|
The concern of this PR would be obviated if there was a Essentially, this.on(target, { ...listeners })As far as allowing |
I agree with @aleclarson. Ryan and I have discussed a potential I do like the conceptual symmetry between |
It's easier to make a PR about this than an issue/discussion. Just curious what you think about doing this to avoid unfortunate function overloading. Overloading is irritating as a consumer of the types. Having an optional
optionsargument at the end seems reasonable.