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

Function batchedUpdates

code/controlled-uncontrolled/public/app.js:2922–2946  ·  view source on GitHub ↗
(fn, bookkeeping)

Source from the content-addressed store, hash-verified

2920
2921var isBatching = false;
2922function batchedUpdates(fn, bookkeeping) {
2923 if (isBatching) {
2924 // If we are currently inside another batch, we need to wait until it
2925 // fully completes before restoring state.
2926 return fn(bookkeeping);
2927 }
2928 isBatching = true;
2929 try {
2930 return _batchedUpdates(fn, bookkeeping);
2931 } finally {
2932 // Here we wait until all updates have propagated, which is important
2933 // when using controlled components within layers:
2934 // https://github.com/facebook/react/issues/1698
2935 // Then we restore state of any controlled component.
2936 isBatching = false;
2937 var controlledComponentsHavePendingUpdates = needsStateRestore();
2938 if (controlledComponentsHavePendingUpdates) {
2939 // If a controlled event was fired, we may need to restore the state of
2940 // the DOM node back to the controlled value. This is necessary when React
2941 // bails out of the update without touching the DOM.
2942 _flushInteractiveUpdates();
2943 restoreStateIfNeeded();
2944 }
2945 }
2946}
2947
2948function interactiveUpdates(fn, a, b) {
2949 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