| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| type: any, | ||
| key: any, | ||
| ref: any, | ||
| ref: string | (elem: ?HTMLElement) => void, |
There was a problem hiding this comment.
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 :)
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
(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.)
Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
There was a problem hiding this comment.
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_
.
Sorry, something went wrong.
There was a problem hiding this comment.
Omg, @andreypopp it works!
Sorry, something went wrong.
There was a problem hiding this comment.
Why isn’t it the default 😄
Sorry, something went wrong.
There was a problem hiding this comment.
(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).
Sorry, something went wrong.
There was a problem hiding this comment.
(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.
Sorry, something went wrong.
| // is made. It probably belongs where the key checking and | ||
| // instantiateReactComponent is done. | ||
|
|
||
| var prevEmpty = prevElement === null || prevElement === false; |
There was a problem hiding this comment.
flow is not smart enough to know that this check is flowing through the variable for the next condition
Sorry, something went wrong.
| var nextEmpty = nextElement === null || nextElement === false; | ||
|
|
||
| return ( | ||
| // This has a few false positives w/r/t empty components. |
There was a problem hiding this comment.
Would be nice to learn what those false positives are since we're touching this code.
Sorry, something went wrong.
There was a problem hiding this comment.
This blames to 999b0f9
Sorry, something went wrong.
There was a problem hiding this comment.
cc @spicyj, let me know if you have more context on this/any concern.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, that's right.
Sorry, something went wrong.
|
(Added needs-revision based on @zpao feedback) |
Sorry, something went wrong.
|
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! |
Sorry, something went wrong.
| ReactRef.detachRefs = function(instance, element) { | ||
| ReactRef.detachRefs = function( | ||
| instance: ReactInstance, | ||
| element: ReactElement, |
There was a problem hiding this comment.
Can be null or false here too.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
Sorry, something went wrong.
|
Added null | false in detachRef |
Sorry, something went wrong.
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) |
There was a problem hiding this comment.
All the tests are passing but i'd love a second pair of eyes to know if this is safe
Sorry, something went wrong.
|
It turned out to be a meatier change when adding string, false and null to the mix :) |
Sorry, something went wrong.
|
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). |
Sorry, something went wrong.
Nothing out of the ordinary on this one. (cherry picked from commit 31dd694)
Nothing out of the ordinary on this one.
| Back | FazBrowse Home | New Git URL |
Nothing out of the ordinary on this one.