-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
Add before
and after
options, remove immediate
option
#9
Conversation
before
and after
options, remove immediate
option
Maybe we should follow the
|
// @bfred-it |
|
Simply put, I generally trust lodash’ logic since the maintainer has been honing the library for years. |
let before = true; //saved from somewhere
const myDebouncer = (fn, after) => {
//probably some logic here, what's important for us is just fn, before and after
if (before && after) { //handle debounceFn changing behavior when both before and after are true
return () => undefined;
}
return debounceFn(fn, {before, after});
};
|
|
I agree with what @bfred-it said above. |
@sindresorhus ping |
const before = (options.before === undefined) ? false : options.before; | ||
const after = (options.after === undefined) ? true : options.after; |
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 it's worth using a regular Object.assign
or {...}
to define defaults and destructure all the options in one place.
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.
Not a big fan of memory allocations without any purpose, but since it's hard to expect this method to be used frequently, we can add allocation I think.
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.
You could also use destructuring with defaults in the function parameters so no new objects would be created
Thanks :) |
Add before and after options, remove immediate option, fixes #5
Both
before
andafter
set totrue
lead to function which will never be executed and debounced version will always returnundefined
. Typed that for typescript, so should be easy to catch if it was a mistake, though don't see much sense in checking it at runtime.Test
before:false after:true options
basically repeats what's tested in maindebounces a function
test, but still added it for clarity.