Skip to content

Commit

Permalink
unstable_batchedUpdates should return value of callback
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed Oct 31, 2016
1 parent b44da09 commit 1c596ea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/renderers/dom/fiber/ReactDOMFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ var ReactDOM = {
return DOMRenderer.findHostInstance(component);
},

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

};
Expand Down
5 changes: 4 additions & 1 deletion src/renderers/shared/fiber/ReactFiberReconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export type Reconciler<C, I, TI> = {
updateContainer(element : ReactElement<any>, container : OpaqueNode) : void,
unmountContainer(container : OpaqueNode) : void,
performWithPriority(priorityLevel : PriorityLevel, fn : Function) : void,
batchedUpdates(fn: Function) : void,
/* eslint-disable no-undef */
// FIXME: ESLint complains about type parameter
batchedUpdates<A>(fn : () => A) : A,
/* eslint-enable no-undef */

// Used to extract the return value from the initial render. Legacy API.
getPublicRootInstance(container : OpaqueNode) : (ReactComponent<any, any, any> | TI | I | null),
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 @@ -673,11 +673,11 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
}
}

function batchedUpdates(fn: Function) {
function batchedUpdates<A>(fn : () => A) : A {
const prev = shouldBatchUpdates;
shouldBatchUpdates = true;
try {
fn();
return fn();
} finally {
shouldBatchUpdates = prev;
}
Expand Down

0 comments on commit 1c596ea

Please sign in to comment.