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
[flow] add some typings to utils #7104
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule flattenChildren | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
@@ -22,22 +23,29 @@ var warning = require('warning'); | |
* @param {!string} name String name of key path to child. | ||
* @param {number=} selfDebugID Optional debugID of the current internal instance. | ||
*/ | ||
function flattenSingleChildIntoContext(traverseContext, child, name, selfDebugID) { | ||
function flattenSingleChildIntoContext( | ||
traverseContext: mixed, | ||
child: ReactElement<any>, | ||
name: string, | ||
selfDebugID: number | ||
): void { | ||
// We found a component instance. | ||
var result = traverseContext; | ||
var keyUnique = (result[name] === undefined); | ||
if (__DEV__) { | ||
warning( | ||
keyUnique, | ||
'flattenChildren(...): Encountered two children with the same key, ' + | ||
'`%s`. Child keys must be unique; when two children share a key, only ' + | ||
'the first child will be used.%s', | ||
KeyEscapeUtils.unescape(name), | ||
ReactComponentTreeDevtool.getStackAddendumByID(selfDebugID) | ||
); | ||
} | ||
if (keyUnique && child != null) { | ||
result[name] = child; | ||
if (traverseContext && typeof traverseContext === 'object') { | ||
const result = traverseContext; | ||
const keyUnique = (result[name] === undefined); | ||
if (__DEV__) { | ||
warning( | ||
keyUnique, | ||
'flattenChildren(...): Encountered two children with the same key, ' + | ||
'`%s`. Child keys must be unique; when two children share a key, only ' + | ||
'the first child will be used.%s', | ||
KeyEscapeUtils.unescape(name), | ||
ReactComponentTreeDevtool.getStackAddendumByID(selfDebugID) | ||
); | ||
} | ||
if (keyUnique && child != null) { | ||
result[name] = child; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -46,7 +54,7 @@ function flattenSingleChildIntoContext(traverseContext, child, name, selfDebugID | |
* children will not be included in the resulting object. | ||
* @return {!object} flattened children keyed by name. | ||
*/ | ||
function flattenChildren(children, selfDebugID) { | ||
function flattenChildren(children: ReactElement<any>, selfDebugID: number): ?{ [name: string]: ReactElement<any> } { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @keyanzhang you are rigth. I'll file PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @chicoxyzzy Thanks, there's already #7110 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep sorry didn't noticed that |
||
if (children == null) { | ||
return children; | ||
} | ||
|
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.
Sorry, just saw this.
selfDebugID
is actually an optional parameter that will only be available in dev mode. You can also see from thenumber=
JSDoc annotation. cc @vjeuxThere 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.
Thanks! #7110