unstable_batchedUpdates should return value of callback

This commit is contained in:
Andrew Clark
2016-10-30 22:44:52 -07:00
parent 2e5e88c750
commit 26731ea967
3 changed files with 8 additions and 5 deletions
+2 -2
View File
@@ -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);
},
};
@@ -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),
@@ -681,11 +681,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;
}