mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
92b7b172cc
* Convert EventPlugin{Hub,Registry} to named exports
* Convert EventPluginUtils to named exports
* Convert EventPropagators to named exports
* Convert ReactControlledComponent to named exports
* Convert ReactGenericBatching to named exports
* Convert ReactDOMComponentTree to named exports
* Convert ReactNativeComponentTree to named exports
* Convert ReactNativeRTComponentTree to named exports
* Convert FallbackCompositionState to named exports
* Convert ReactEventEmitterMixin to named exports
* Convert ReactBrowserEventEmitter to named exports
* Convert ReactNativeEventEmitter to named exports
* Convert ReactDOMEventListener to named exports
* Convert DOMMarkupOperations to named exports
* Convert DOMProperty to named exports
* Add suppression for existing Flow violation
Flow didn't see it before.
* Update sizes
49 lines
1.6 KiB
JavaScript
49 lines
1.6 KiB
JavaScript
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
import {restoreStateIfNeeded} from './ReactControlledComponent';
|
|
|
|
// Used as a way to call batchedUpdates when we don't have a reference to
|
|
// the renderer. Such as when we're dispatching events or if third party
|
|
// libraries need to call batchedUpdates. Eventually, this API will go away when
|
|
// everything is batched by default. We'll then have a similar API to opt-out of
|
|
// scheduled work and instead do synchronous work.
|
|
|
|
// Defaults
|
|
var fiberBatchedUpdates = function(fn, bookkeeping) {
|
|
return fn(bookkeeping);
|
|
};
|
|
|
|
var isNestingBatched = false;
|
|
export function batchedUpdates(fn, bookkeeping) {
|
|
if (isNestingBatched) {
|
|
// If we are currently inside another batch, we need to wait until it
|
|
// fully completes before restoring state. Therefore, we add the target to
|
|
// a queue of work.
|
|
return fiberBatchedUpdates(fn, bookkeeping);
|
|
}
|
|
isNestingBatched = true;
|
|
try {
|
|
return fiberBatchedUpdates(fn, bookkeeping);
|
|
} finally {
|
|
// Here we wait until all updates have propagated, which is important
|
|
// when using controlled components within layers:
|
|
// https://github.com/facebook/react/issues/1698
|
|
// Then we restore state of any controlled component.
|
|
isNestingBatched = false;
|
|
restoreStateIfNeeded();
|
|
}
|
|
}
|
|
|
|
var ReactGenericBatchingInjection = {
|
|
injectFiberBatchedUpdates: function(_batchedUpdates) {
|
|
fiberBatchedUpdates = _batchedUpdates;
|
|
},
|
|
};
|
|
|
|
export const injection = ReactGenericBatchingInjection;
|