-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
Resolve refs in the order of the children #7101
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,14 @@ var StatusDisplay = React.createClass({ | |
return this.state.internalState; | ||
}, | ||
|
||
componentDidMount: function() { | ||
this.props.onFlush(); | ||
}, | ||
|
||
componentDidUpdate: function() { | ||
this.props.onFlush(); | ||
}, | ||
|
||
render: function() { | ||
return ( | ||
<div> | ||
|
@@ -74,43 +82,74 @@ var StatusDisplay = React.createClass({ | |
*/ | ||
var FriendsStatusDisplay = React.createClass({ | ||
/** | ||
* Retrieves the rendered children in a nice format for comparing to the input | ||
* `this.props.usernameToStatus`. Gets the order directly from each rendered | ||
* child's `index` field. Refs are not maintained in the rendered order, and | ||
* neither is `this._renderedChildren` (surprisingly). | ||
*/ | ||
getStatusDisplays: function() { | ||
var name; | ||
var orderOfUsernames = []; | ||
* Gets the order directly from each rendered child's `index` field. | ||
* Refs are not maintained in the rendered order, and neither is | ||
* `this._renderedChildren` (surprisingly). | ||
*/ | ||
getOriginalKeys: function() { | ||
var originalKeys = []; | ||
// TODO: Update this to a better test that doesn't rely so much on internal | ||
// implementation details. | ||
var statusDisplays = | ||
ReactInstanceMap.get(this) | ||
._renderedComponent | ||
._renderedChildren; | ||
var name; | ||
for (name in statusDisplays) { | ||
var child = statusDisplays[name]; | ||
var isPresent = !!child; | ||
if (isPresent) { | ||
orderOfUsernames[child._mountIndex] = getOriginalKey(name); | ||
originalKeys[child._mountIndex] = getOriginalKey(name); | ||
} | ||
} | ||
return originalKeys; | ||
}, | ||
/** | ||
* Retrieves the rendered children in a nice format for comparing to the input | ||
* `this.props.usernameToStatus`. | ||
*/ | ||
getStatusDisplays: function() { | ||
var res = {}; | ||
var i; | ||
for (i = 0; i < orderOfUsernames.length; i++) { | ||
var key = orderOfUsernames[i]; | ||
var originalKeys = this.getOriginalKeys(); | ||
for (i = 0; i < originalKeys.length; i++) { | ||
var key = originalKeys[i]; | ||
res[key] = this.refs[key]; | ||
} | ||
return res; | ||
}, | ||
/** | ||
* Verifies that by the time a child is flushed, the refs that appeared | ||
* earlier have already been resolved. | ||
* TODO: This assumption will likely break with incremental reconciler | ||
* but our internal layer API depends on this assumption. We need to change | ||
* it to be more declarative before making ref resolution indeterministic. | ||
*/ | ||
verifyPreviousRefsResolved: function(flushedKey) { | ||
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. Note: I verified this fails on master (5 tests failing). |
||
var i; | ||
var originalKeys = this.getOriginalKeys(); | ||
for (i = 0; i < originalKeys.length; i++) { | ||
var key = originalKeys[i]; | ||
if (key === flushedKey) { | ||
// We are only interested in children up to the current key. | ||
return; | ||
} | ||
expect(this.refs[key]).toBeTruthy(); | ||
} | ||
}, | ||
render: function() { | ||
var children = []; | ||
var key; | ||
for (key in this.props.usernameToStatus) { | ||
var status = this.props.usernameToStatus[key]; | ||
children.push( | ||
!status ? null : | ||
<StatusDisplay key={key} ref={key} status={status} /> | ||
<StatusDisplay | ||
key={key} | ||
ref={key} | ||
onFlush={this.verifyPreviousRefsResolved.bind(this, key)} | ||
status={status} | ||
/> | ||
); | ||
} | ||
return ( | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We use an array for this in
mountChildren
so I can change it here too if necessary.