Skip to content
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

Merged

Conversation

lucasray
Copy link
Contributor

Checklist

Changes proposed in this pull request:

Adds a 2nd arg to the Tag's onRemove 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 the onRemove callback without creating a lambda or additional React component, which may have perf consequences.

Copy link
Contributor

@cmslewis cmslewis left a 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.
Copy link
Contributor

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.

Copy link
Contributor

@cmslewis cmslewis Jun 22, 2017

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.

Copy link
Contributor Author

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

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is safeInvoke necessary here?

Copy link
Contributor Author

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.

Copy link
Contributor

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);

Copy link
Contributor Author

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

Copy link
Contributor

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.

@lucasray
Copy link
Contributor Author

Fixes lint

Preview: documentation
Coverage: core | datetime

private onRemoveClick = (e: React.MouseEvent<HTMLButtonElement>) => {
const { onRemove } = this.props;
if (onRemove) {
onRemove(e, this.props);
Copy link
Contributor

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.

@cmslewis cmslewis merged commit 4de5af0 into palantir:master Jun 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants