Skip to content

Handle nested controlled events#8251

Merged
sebmarkbage merged 1 commit intofacebook:masterfrom
sebmarkbage:reentrantevents
Nov 11, 2016
Merged

Handle nested controlled events#8251
sebmarkbage merged 1 commit intofacebook:masterfrom
sebmarkbage:reentrantevents

Conversation

@sebmarkbage
Copy link
Copy Markdown
Contributor

I came up with a contrived case of where nested controlled events could fire within the same batch - but on different targets.

I think we came to the conclusion that controlled values typically cannot use preventDefault so it is ok that they don't flush until after the event has finished. So therefore we accumulate a queue of all the nested targets within a batch and then restore state on all of them.

I'm still skeptical that this is the correct way to do controlled values. The reason we have to do them in a single event loop is because when you type, the sequence of values that get accepted or not can matter. I wonder if there is a scenario we can come up with where you can fire multiple
inner events in an event loop and end up with batching causing problems.

enqueueStateRestore() {
needsRestoreState = true;
enqueueStateRestore(target) {
if (restoreTarget) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We have accumulateInto, forEachAccumulated if you want.

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.

I find that indirection hard to read and not sure how inlinable that is.

I came up with a contrived case of where nested controlled events could
fire within the same batch - but on different targets.

I think we came to the conclusion that controlled values typically cannot
use preventDefault so it is ok that they don't flush until after the event
has finished. So therefore we accumulate a queue of all the nested targets
within a batch and then restore state on all of them.

I'm still skeptical that this is the correct way to do controlled values.
The reason we have to do them in a single event loop is because when you
type, the sequence of values that get accepted or not can matter. I wonder
if there is a scenario we can come up with where you can fire multiple
inner events in an event loop and end up with batching causing problems.

This effectively just reimplements asap again but with no allocations for
a single target and no closure allocations.
@sebmarkbage sebmarkbage merged commit 4804518 into facebook:master Nov 11, 2016
acusti pushed a commit to brandcast/react that referenced this pull request Mar 15, 2017
I came up with a contrived case of where nested controlled events could
fire within the same batch - but on different targets.

I think we came to the conclusion that controlled values typically cannot
use preventDefault so it is ok that they don't flush until after the event
has finished. So therefore we accumulate a queue of all the nested targets
within a batch and then restore state on all of them.

I'm still skeptical that this is the correct way to do controlled values.
The reason we have to do them in a single event loop is because when you
type, the sequence of values that get accepted or not can matter. I wonder
if there is a scenario we can come up with where you can fire multiple
inner events in an event loop and end up with batching causing problems.

This effectively just reimplements asap again but with no allocations for
a single target and no closure allocations.
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