Skip to content

Commit

Permalink
Finish ReactGenericBatching (#8405)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits committed Nov 24, 2016
1 parent 13cb540 commit 8791325
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions scripts/fiber/tests-failing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ src/renderers/dom/shared/__tests__/ReactDOMTextComponent-test.js
* can reconcile text arbitrarily split into multiple nodes
* can reconcile text arbitrarily split into multiple nodes on some substitutions only

src/renderers/dom/shared/__tests__/ReactEventListener-test.js
* should batch between handlers from different roots
src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js
* should control a value in reentrant events

src/renderers/dom/stack/client/__tests__/ReactDOM-test.js
* throws in render() if the mount callback is not a function
Expand Down
2 changes: 1 addition & 1 deletion scripts/fiber/tests-passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ src/renderers/dom/shared/__tests__/ReactEventListener-test.js
* should propagate events one level down
* should propagate events two levels down
* should not get confused by disappearing elements
* should batch between handlers from different roots
* should not fire duplicate events for a React DOM tree

src/renderers/dom/shared/__tests__/escapeTextContentForBrowser-test.js
Expand Down Expand Up @@ -812,7 +813,6 @@ src/renderers/dom/shared/wrappers/__tests__/ReactDOMIframe-test.js

src/renderers/dom/shared/wrappers/__tests__/ReactDOMInput-test.js
* should properly control a value even if no event listener exists
* should control a value in reentrant events
* should control values in reentrant events with different targets
* should display `defaultValue` of number 0
* only assigns defaultValue if it changes
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/dom/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
var ReactDOMComponentTree = require('ReactDOMComponentTree');
var ReactDOMInjection = require('ReactDOMInjection');
var ReactDOMStackInjection = require('ReactDOMStackInjection');
var ReactGenericBatching = require('ReactGenericBatching');
var ReactMount = require('ReactMount');
var ReactReconciler = require('ReactReconciler');
var ReactUpdates = require('ReactUpdates');
var ReactVersion = require('ReactVersion');

var findDOMNode = require('findDOMNode');
Expand All @@ -35,7 +35,7 @@ var ReactDOM = {
version: ReactVersion,

/* eslint-disable camelcase */
unstable_batchedUpdates: ReactUpdates.batchedUpdates,
unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,
unstable_renderSubtreeIntoContainer: ReactMount.renderSubtreeIntoContainer,
/* eslint-enable camelcase */
};
Expand Down
7 changes: 4 additions & 3 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var ReactDOMComponentTree = require('ReactDOMComponentTree');
var ReactDOMFeatureFlags = require('ReactDOMFeatureFlags');
var ReactDOMFiberComponent = require('ReactDOMFiberComponent');
var ReactDOMInjection = require('ReactDOMInjection');
var ReactGenericBatching = require('ReactGenericBatching');
var ReactFiberReconciler = require('ReactFiberReconciler');
var ReactInputSelection = require('ReactInputSelection');
var ReactInstanceMap = require('ReactInstanceMap');
Expand Down Expand Up @@ -165,6 +166,8 @@ var DOMRenderer = ReactFiberReconciler({

});

ReactGenericBatching.injection.injectFiberBatchedUpdates(DOMRenderer.batchedUpdates);

var warned = false;

function warnAboutUnstableUse() {
Expand Down Expand Up @@ -220,9 +223,7 @@ var ReactDOM = {
return ReactPortal.createPortal(children, container, null, key);
},

unstable_batchedUpdates<A>(fn : () => A) : A {
return DOMRenderer.batchedUpdates(fn);
},
unstable_batchedUpdates: ReactGenericBatching.batchedUpdates,

};

Expand Down
4 changes: 2 additions & 2 deletions src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,11 +790,11 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
}
}

function batchedUpdates<A>(fn : () => A) : A {
function batchedUpdates<A, R>(fn : (a: A) => R, a : A) : R {
const prev = shouldBatchUpdates;
shouldBatchUpdates = true;
try {
return fn();
return fn(a);
} finally {
// If we're exiting the batch, perform any scheduled task work
try {
Expand Down
19 changes: 9 additions & 10 deletions src/renderers/shared/shared/event/ReactGenericBatching.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ var ReactControlledComponent = require('ReactControlledComponent');

// Defaults
var stackBatchedUpdates = function(fn, a, b, c, d, e) {
fn(a, b, c, d, e);
return fn(a, b, c, d, e);
};
var fiberPerformSynchronousWork = function(fn, bookkeeping) {
fn(bookkeeping);
var fiberBatchedUpdates = function(fn, bookkeeping) {
return 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);
return fiberBatchedUpdates(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);
return stackBatchedUpdates(performFiberBatchedUpdates, fn, bookkeeping);
}

var isNestingBatched = false;
Expand All @@ -44,12 +44,11 @@ function batchedUpdatesWithControlledComponents(fn, bookkeeping) {
// 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.
batchedUpdates(fn, bookkeeping);
return;
return batchedUpdates(fn, bookkeeping);
}
isNestingBatched = true;
try {
batchedUpdates(fn, bookkeeping);
return batchedUpdates(fn, bookkeeping);
} finally {
// Here we wait until all updates have propagated, which is important
// when using controlled components within layers:
Expand All @@ -64,8 +63,8 @@ var ReactGenericBatchingInjection = {
injectStackBatchedUpdates: function(_batchedUpdates) {
stackBatchedUpdates = _batchedUpdates;
},
injectFiberPerformSynchronousWork: function(_performSynchronousWork) {
fiberPerformSynchronousWork = _performSynchronousWork;
injectFiberBatchedUpdates: function(_batchedUpdates) {
fiberBatchedUpdates = _batchedUpdates;
},
};

Expand Down

0 comments on commit 8791325

Please sign in to comment.