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

Function batchedUpdates

code/one-direction-data-flow/public/app.js:3471–3495  ·  view source on GitHub ↗
(fn, bookkeeping)

Source from the content-addressed store, hash-verified

3469
3470var isBatching = false;
3471function batchedUpdates(fn, bookkeeping) {
3472 if (isBatching) {
3473 // If we are currently inside another batch, we need to wait until it
3474 // fully completes before restoring state.
3475 return fn(bookkeeping);
3476 }
3477 isBatching = true;
3478 try {
3479 return _batchedUpdates(fn, bookkeeping);
3480 } finally {
3481 // Here we wait until all updates have propagated, which is important
3482 // when using controlled components within layers:
3483 // https://github.com/facebook/react/issues/1698
3484 // Then we restore state of any controlled component.
3485 isBatching = false;
3486 var controlledComponentsHavePendingUpdates = needsStateRestore();
3487 if (controlledComponentsHavePendingUpdates) {
3488 // If a controlled event was fired, we may need to restore the state of
3489 // the DOM node back to the controlled value. This is necessary when React
3490 // bails out of the update without touching the DOM.
3491 _flushInteractiveUpdates();
3492 restoreStateIfNeeded();
3493 }
3494 }
3495}
3496
3497function interactiveUpdates(fn, a, b) {
3498 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