-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[Core] Adds additional arg to Tag onRemove handler #1267
[Core] Adds additional arg to Tag onRemove handler #1267
Conversation
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.
Would prefer to pass just a single identifying value here, but given that there isn't a single, clearly prescribed identifier, this looks fine to me!
Requesting one small change before approving/merging.
@@ -26,7 +26,7 @@ export interface ITagProps extends IProps, IIntentProps, React.HTMLAttributes<Ta | |||
* Click handler for remove button. | |||
* Button will only be rendered if this prop is defined. |
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.
Can we add a line to the description explaining what the props
parameter is?
e.g. Receives the props for the tag that was removed.
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.
or maybe rename to tagProps
and avoid a description altogether.
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.
sure, I'll rename to tagProps
, at which point I think it's fairly clear what props are being passed, but happy to also add to the description if you'd like
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.
tagProps
alone is fine to me. 👍
private onRemoveClick = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
const { onRemove } = this.props; | ||
if (onRemove) { | ||
onRemove(e, this.props); |
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.
Is safeInvoke
necessary here?
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.
since onRemove
is effectively Function | undefined
, the typechecker should guarantee this to be safe. this callback only actually occurs if isFunction(onRemove)
from line 42, though that isn't expressed in the types here. what does safeInvoke
provide that the typechecker cannot? happy to rewrite this whole function as:
private onRemoveClick = (e: React.MouseEvent<HTMLButtonElement>) => {
const { onRemove } = this.props;
safeInvoke(onRemove, e, this.props);
}
if preferred, just seems slightly more complicated for no gain.
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.
The benefit is more for succinctness than anything. Note this whole thing becomes one line with safeInvoke
:
Utils.safeInvoke(this.props.onRemove, e, this.props);
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.
@cmslewis okay, do you all prefer this style? I slightly prefer the existing (clear what is happening without prior knowledge of what safeInvoke
does, very slightly more performant since it doesn't add another call), but fine with changing it
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.
Yeah, it's BP convention at this point, but we don't need to block on it.
Fixes lintPreview: documentation |
private onRemoveClick = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
const { onRemove } = this.props; | ||
if (onRemove) { | ||
onRemove(e, this.props); |
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.
Yeah, it's BP convention at this point, but we don't need to block on it.
Checklist
Changes proposed in this pull request:
Adds a 2nd arg to the
Tag
'sonRemove
handler. This a non-breaking change, as passing functions that accept only 1 argument will still typecheck. This is useful in order to properly handle theonRemove
callback without creating a lambda or additional React component, which may have perf consequences.