MCPcopy Create free account
hub / github.com/krasimir/react-in-patterns / batchedUpdates

Function batchedUpdates

code/styling/public/app.js:3598–3622  ·  view source on GitHub ↗
(fn, bookkeeping)

Source from the content-addressed store, hash-verified

3596
3597var isBatching = false;
3598function batchedUpdates(fn, bookkeeping) {
3599 if (isBatching) {
3600 // If we are currently inside another batch, we need to wait until it
3601 // fully completes before restoring state.
3602 return fn(bookkeeping);
3603 }
3604 isBatching = true;
3605 try {
3606 return _batchedUpdates(fn, bookkeeping);
3607 } finally {
3608 // Here we wait until all updates have propagated, which is important
3609 // when using controlled components within layers:
3610 // https://github.com/facebook/react/issues/1698
3611 // Then we restore state of any controlled component.
3612 isBatching = false;
3613 var controlledComponentsHavePendingUpdates = needsStateRestore();
3614 if (controlledComponentsHavePendingUpdates) {
3615 // If a controlled event was fired, we may need to restore the state of
3616 // the DOM node back to the controlled value. This is necessary when React
3617 // bails out of the update without touching the DOM.
3618 _flushInteractiveUpdates();
3619 restoreStateIfNeeded();
3620 }
3621 }
3622}
3623
3624function interactiveUpdates(fn, a, b) {
3625 return _interactiveUpdates(fn, a, b);

Callers 2

dispatchEventFunction · 0.70

Calls 5

_batchedUpdatesFunction · 0.70
needsStateRestoreFunction · 0.70
_flushInteractiveUpdatesFunction · 0.70
restoreStateIfNeededFunction · 0.70
performSyncWorkFunction · 0.70

Tested by

no test coverage detected