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

Function batchedUpdates

code/new-context-api/public/app.js:2959–2983  ·  view source on GitHub ↗
(fn, bookkeeping)

Source from the content-addressed store, hash-verified

2957
2958var isBatching = false;
2959function batchedUpdates(fn, bookkeeping) {
2960 if (isBatching) {
2961 // If we are currently inside another batch, we need to wait until it
2962 // fully completes before restoring state.
2963 return fn(bookkeeping);
2964 }
2965 isBatching = true;
2966 try {
2967 return _batchedUpdates(fn, bookkeeping);
2968 } finally {
2969 // Here we wait until all updates have propagated, which is important
2970 // when using controlled components within layers:
2971 // https://github.com/facebook/react/issues/1698
2972 // Then we restore state of any controlled component.
2973 isBatching = false;
2974 var controlledComponentsHavePendingUpdates = needsStateRestore();
2975 if (controlledComponentsHavePendingUpdates) {
2976 // If a controlled event was fired, we may need to restore the state of
2977 // the DOM node back to the controlled value. This is necessary when React
2978 // bails out of the update without touching the DOM.
2979 _flushInteractiveUpdates();
2980 restoreStateIfNeeded();
2981 }
2982 }
2983}
2984
2985function interactiveUpdates(fn, a, b) {
2986 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