FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Type ReactRef by vjeux · Pull Request #7600 · react/react · GitHub

/ react Public

Type ReactRef - #7600

Merged
vjeux merged 1 commit into
react:masterfrom
vjeux:type_ReactRef
Sep 2, 2016
Merged

vjeux merged 1 commit into
react:masterfrom
vjeux:type_ReactRef

Conversation

vjeux commented Aug 29, 2016

Copy link
Copy Markdown
Contributor

Nothing out of the ordinary on this one.

type: any,
key: any,
ref: any,
ref: string | (elem: ?HTMLElement) => void,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Expanding the types of ReactElement as I go along. Flow coverage tool in nuclide is super useful to see what flows sees in the code I flowify :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there any way flow coverage could be integrated into flow CLI? Many people don't use Nuclide and when they try flow, they aren't aware flow coverage exists.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(I understand there's a separate command but it's easy to miss when you are learning or trying it for the first time. I didn't know it existed until someone mentioned it on Twitter a month ago.)

vjeux Aug 29, 2016 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There's already a command flow coverage <file> but it just shows the summary which isn't really useful:

Would be awesome if it printed in ascii art what nuclide shows:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

flow coverage --color
On Mon, 29 Aug 2016 at 19:04, Christopher Chedeau notifications@github.com
wrote:

In src/isomorphic/classic/element/ReactElementType.js
#7600 (comment):

@@ -23,7 +23,7 @@ export type ReactElement = {
$$typeof: any,
type: any,
key: any,

  • ref: any,
  • ref: string | (elem: ?HTMLElement) => void,

cc @thejameskyle https://github.com/thejameskyle

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/facebook/react/pull/7600/files/6a1166f44d77d267879a9e39b6cde9241a569043#r76634323,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAB3gk_ZuNizzgRHP7SeOrxVSKUMDotlks5qkwMFgaJpZM4JvD5_
.

vjeux Aug 29, 2016 •
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Omg, @andreypopp it works!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why isn’t it the default 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(elem: ?HTMLElement) => void isn't right - you can get a component instance passed in (in the case of refs on composite components).

I think we probably want to define this correctly as much as possible and not leave partially correct types on fields (probably fine to leave any on to-be type fields).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(elem: ?HTMLElement) => void isn't right - you can get a component instance passed in (in the case of refs on composite components).

Good catch! I need to figure out what the type of a component instance is.

I think we probably want to define this correctly as much as possible and not leave partially correct types on fields (probably fine to leave any on to-be type fields).

Agreed, I want anything to be typed to be fully correct.

// is made. It probably belongs where the key checking and
// instantiateReactComponent is done.

var prevEmpty = prevElement === null || prevElement === false;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

flow is not smart enough to know that this check is flowing through the variable for the next condition

var nextEmpty = nextElement === null || nextElement === false;

return (
// This has a few false positives w/r/t empty components.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Would be nice to learn what those false positives are since we're touching this code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This blames to 999b0f9

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

cc @spicyj, let me know if you have more context on this/any concern.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think the idea is that if both prevElement == null || prevElement === false and nextElement == null || nextElement === false then the function will return true. This is a false positive because if it was empty and stays empty, there is no need to update refs. Probably not a big deal.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Yes, that's right.

vjeux commented Aug 30, 2016

Copy link
Copy Markdown
Contributor Author

(Added needs-revision based on @zpao feedback)

vjeux commented Aug 30, 2016

Copy link
Copy Markdown
Contributor Author

Removed the ref type on ReactInstanceType as we don't yet have a type for the user class and it wasn't accurate enough.

Typed the function as ReactInstance | null | false in order to ensure that undefined cannot slip in.

I'm looking for another review, thanks for the comments!

ReactRef.detachRefs = function(instance, element) {
ReactRef.detachRefs = function(
instance: ReactInstance,
element: ReactElement,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can be null or false here too.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Good catch, I can't wait for flow to warn when you're doing checks that do not make sense based on the type you have.

vjeux commented Aug 30, 2016

Copy link
Copy Markdown
Contributor Author

Added null | false in detachRef

Nothing out of the ordinary on this one.
// If owner changes but we have an unchanged function ref, don't update refs
(typeof nextElement.ref === 'string' &&
nextElement._owner !== prevElement._owner)
(typeof nextRef === 'string' && nextOwner !== prevOwner)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

All the tests are passing but i'd love a second pair of eyes to know if this is safe

vjeux commented Sep 2, 2016

Copy link
Copy Markdown
Contributor Author

It turned out to be a meatier change when adding string, false and null to the mix :)

gaearon commented Sep 2, 2016

Copy link
Copy Markdown
Contributor

Looks right to me. If it turns out to be wrong but we didn’t have tests for that case, our fault (and we’ll add tests).

vjeux added this to the 15-next milestone Sep 2, 2016
vjeux merged commit 31dd694 into react:master Sep 2, 2016
zpao modified the milestones: 15-next, 15.4.0 Oct 4, 2016
zpao pushed a commit that referenced this pull request Oct 4, 2016
Nothing out of the ordinary on this one.
(cherry picked from commit 31dd694)
mrizwanashiq pushed a commit to mrizwanashiq/react that referenced this pull request Jun 25, 2026
Nothing out of the ordinary on this one.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL