mirror of
https://github.com/facebook/react.git
synced 2026-11-18 20:15:56 +00:00
Create ReactGenericBatching injection wrapper around BatchedUpdates
This moves calls that don't know if they're in a Fiber or Stack context to use ReactGenericBatching.batchedUpdates. The corresponding one will be injected from either the stack reconciler and/or the fiber reconciler if they're loaded at the same time. This lets them share the event system when they're both used at once. This can also be useful for libraries that call unstable_batchedUpdates today but don't know which renderer to use.
This commit is contained in:
1 parent
2f8d1689db
commit
ea47782aaa
6 files changed
+69
-6
No files matched your search
@@ -15,7 +15,7 @@ var EventListener = require('EventListener');
|
||||
var ExecutionEnvironment = require('ExecutionEnvironment');
|
||||
var PooledClass = require('PooledClass');
|
||||
var ReactDOMComponentTree = require('ReactDOMComponentTree');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
var ReactGenericBatching = require('ReactGenericBatching');
|
||||
|
||||
var getEventTarget = require('getEventTarget');
|
||||
var getUnboundedScrollPosition = require('getUnboundedScrollPosition');
|
||||
@@ -165,7 +165,7 @@ var ReactEventListener = {
|
||||
try {
|
||||
// Event queue being processed in the same cycle allows
|
||||
// `preventDefault`.
|
||||
ReactUpdates.batchedUpdates(handleTopLevelImpl, bookKeeping);
|
||||
ReactGenericBatching.batchedUpdates(handleTopLevelImpl, bookKeeping);
|
||||
} finally {
|
||||
TopLevelCallbackBookKeeping.release(bookKeeping);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ var EventPluginHub = require('EventPluginHub');
|
||||
var EventPropagators = require('EventPropagators');
|
||||
var ExecutionEnvironment = require('ExecutionEnvironment');
|
||||
var ReactDOMComponentTree = require('ReactDOMComponentTree');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
var ReactGenericBatching = require('ReactGenericBatching');
|
||||
var SyntheticEvent = require('SyntheticEvent');
|
||||
|
||||
var inputValueTracking = require('inputValueTracking');
|
||||
@@ -98,7 +98,7 @@ function manualDispatchChangeEvent(nativeEvent) {
|
||||
// components don't work properly in conjunction with event bubbling because
|
||||
// the component is rerendered and the value reverted before all the event
|
||||
// handlers can run. See https://github.com/facebook/react/issues/708.
|
||||
ReactUpdates.batchedUpdates(runEventInBatch, event);
|
||||
ReactGenericBatching.batchedUpdates(runEventInBatch, event);
|
||||
}
|
||||
|
||||
function runEventInBatch(event) {
|
||||
|
||||
@@ -19,6 +19,7 @@ var ReactDOMEmptyComponent = require('ReactDOMEmptyComponent');
|
||||
var ReactDOMTextComponent = require('ReactDOMTextComponent');
|
||||
var ReactDefaultBatchingStrategy = require('ReactDefaultBatchingStrategy');
|
||||
var ReactEmptyComponent = require('ReactEmptyComponent');
|
||||
var ReactGenericBatching = require('ReactGenericBatching');
|
||||
var ReactHostComponent = require('ReactHostComponent');
|
||||
var ReactReconcileTransaction = require('ReactReconcileTransaction');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
@@ -34,6 +35,10 @@ function inject() {
|
||||
}
|
||||
alreadyInjected = true;
|
||||
|
||||
ReactGenericBatching.injection.injectStackBatchedUpdates(
|
||||
ReactUpdates.batchedUpdates
|
||||
);
|
||||
|
||||
ReactHostComponent.injection.injectGenericComponentClass(
|
||||
ReactDOMComponent
|
||||
);
|
||||
|
||||
@@ -16,7 +16,7 @@ var EventPluginRegistry = require('EventPluginRegistry');
|
||||
var ReactEventEmitterMixin = require('ReactEventEmitterMixin');
|
||||
var ReactNativeComponentTree = require('ReactNativeComponentTree');
|
||||
var ReactNativeTagHandles = require('ReactNativeTagHandles');
|
||||
var ReactUpdates = require('ReactUpdates');
|
||||
var ReactGenericBatching = require('ReactGenericBatching');
|
||||
|
||||
var warning = require('warning');
|
||||
|
||||
@@ -123,7 +123,7 @@ var ReactNativeEventEmitter = {
|
||||
// any events.
|
||||
return;
|
||||
}
|
||||
ReactUpdates.batchedUpdates(function() {
|
||||
ReactGenericBatching.batchedUpdates(function() {
|
||||
ReactNativeEventEmitter.handleTopLevel(
|
||||
topLevelType,
|
||||
inst,
|
||||
|
||||
@@ -23,6 +23,7 @@ var React = require('React');
|
||||
var ReactComponentEnvironment = require('ReactComponentEnvironment');
|
||||
var ReactDefaultBatchingStrategy = require('ReactDefaultBatchingStrategy');
|
||||
var ReactEmptyComponent = require('ReactEmptyComponent');
|
||||
var ReactGenericBatching = require('ReactGenericBatching');
|
||||
var ReactHostComponent = require('ReactHostComponent');
|
||||
var ReactNativeComponentEnvironment = require('ReactNativeComponentEnvironment');
|
||||
var ReactNativeTextComponent = require('ReactNativeTextComponent');
|
||||
@@ -32,6 +33,10 @@ var ReactUpdates = require('ReactUpdates');
|
||||
var invariant = require('invariant');
|
||||
|
||||
function inject() {
|
||||
ReactGenericBatching.injection.injectStackBatchedUpdates(
|
||||
ReactUpdates.batchedUpdates
|
||||
);
|
||||
|
||||
ReactUpdates.injection.injectReconcileTransaction(
|
||||
ReactNativeComponentEnvironment.ReactReconcileTransaction
|
||||
);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright 2013-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*
|
||||
* @providesModule ReactGenericBatching
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
// Used as a way to call batchedUpdates when we don't know if we're in a Fiber
|
||||
// or Stack context. 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 stackBatchedUpdates = function(fn, a, b, c, d, e) {
|
||||
fn(a, b, c, d, e);
|
||||
};
|
||||
var fiberPerformSynchronousWork = function(fn, bookkeeping) {
|
||||
fn(bookkeeping);
|
||||
};
|
||||
|
||||
function performFiberBatchedUpdates(fn, bookkeeping) {
|
||||
// If we have Fiber loaded, we need to wrap this in a batching call so that
|
||||
// Fiber can apply its default priority for this call.
|
||||
fiberPerformSynchronousWork(fn, bookkeeping);
|
||||
}
|
||||
function batchedUpdates(fn, bookkeeping) {
|
||||
// We first perform work with the stack batching strategy, by passing our
|
||||
// indirection to it.
|
||||
stackBatchedUpdates(performFiberBatchedUpdates, fn, bookkeeping);
|
||||
}
|
||||
|
||||
var ReactGenericBatchingInjection = {
|
||||
injectStackBatchedUpdates: function(_batchedUpdates) {
|
||||
stackBatchedUpdates = _batchedUpdates;
|
||||
},
|
||||
injectFiberPerformSynchronousWork: function(_performSynchronousWork) {
|
||||
fiberPerformSynchronousWork = _performSynchronousWork;
|
||||
},
|
||||
};
|
||||
|
||||
var ReactGenericBatching = {
|
||||
batchedUpdates,
|
||||
injection: ReactGenericBatchingInjection,
|
||||
};
|
||||
|
||||
module.exports = ReactGenericBatching;
|
||||
Reference in new issue
Block a user