-
Notifications
You must be signed in to change notification settings - Fork 323
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
feat(debounce): Support AbortSignal to debounce for improved cancellation #45
Conversation
@Hanna922 is attempting to deploy a commit to the Toss Team on Vercel. A member of the Team first needs to authorize it. |
Hello @Hanna922, Thanks for your contribution! |
src/function/debounce.ts
Outdated
export function debounce<F extends (...args: any[]) => void>( | ||
func: F, | ||
debounceMs: number, | ||
abortSignal?: AbortSignal |
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.
To receive signals, what about we follow the fetch API's option? It would be helpful when we add new options to our debounce function.
interface DebounceOptions {
signal?: AbortSignal;
}
export function debounce<F extends (...args: any[]) => void>(
func: F,
debounceMs: number,
{ signal }: DebounceOptions = {}
) { /* ... */ }
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.
It was applied in b6ed097
src/function/debounce.ts
Outdated
if (abortSignal) { | ||
abortSignal.removeEventListener('abort', onAbort); | ||
} |
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.
if (abortSignal) { | |
abortSignal.removeEventListener('abort', onAbort); | |
} | |
abortSignal?.removeEventListener('abort', onAbort); |
What about using optional chaining here?
src/function/debounce.ts
Outdated
if (abortSignal) { | ||
abortSignal.addEventListener('abort', onAbort); | ||
} |
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.
if (abortSignal) { | |
abortSignal.addEventListener('abort', onAbort); | |
} | |
abortSignal?.addEventListener('abort', onAbort); |
Here too
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.
It was applied in 8cf4772
@raon0211 I have applied the comments and added docs! Thank you 🙇🏻♀️ |
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.
Awesome work!
Hi👋🏻 I have reviewed issue #37 and thought it was a good feature, so I have added it.
If this change is acceptable, I'll add docs and extend this functionality to the
delay
function.Before
After