Remove first-class function
Instead we'll branch on the priority level, like in scheduleWork.
Andrew Clark committed
Oct 31, 2016 at 11:18 UTC
da45010cb7083cac22f54fcb4981039186e3f70b
2 files changed
+20
-7
src/renderers/shared/fiber/ReactFiberReconciler.js
+1
-1
@@ -28,7 +28,7 @@ if (__DEV__) {
28
29
var { findCurrentHostFiber } = require('ReactFiberTreeReflection');
30
31
-type Deadline = {
31
+export type Deadline = {
32
timeRemaining : () => number
33
};
34
src/renderers/shared/fiber/ReactFiberScheduler.js
+19
-6
@@ -15,7 +15,7 @@
15
import type { TrappedError } from 'ReactFiberErrorBoundary';
16
import type { Fiber } from 'ReactFiber';
17
import type { FiberRoot } from 'ReactFiberRoot';
18
-import type { HostConfig } from 'ReactFiberReconciler';
18
+import type { HostConfig, Deadline } from 'ReactFiberReconciler';
19
import type { PriorityLevel } from 'ReactPriorityLevel';
20
21
var ReactFiberBeginWork = require('ReactFiberBeginWork');
@@ -379,7 +379,7 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
379
}
380
381
function performDeferredWork(deadline) {
382
- performAndHandleErrors(performDeferredWorkUnsafe, deadline);
382
+ performAndHandleErrors(LowPriority, deadline);
383
}
384
385
function scheduleDeferredWork(root : FiberRoot, priority : PriorityLevel) {
@@ -432,7 +432,7 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
432
}
433
434
function performAnimationWork() {
435
- performAndHandleErrors(performAnimationWorkUnsafe);
435
+ performAndHandleErrors(AnimationPriority);
436
}
437
438
function scheduleAnimationWork(root: FiberRoot, priorityLevel : PriorityLevel) {
@@ -510,7 +510,7 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
510
shouldBatchUpdates = true;
511
// All nested updates are batched
512
try {
513
- performAndHandleErrors(performSynchronousWorkUnsafe);
513
+ performAndHandleErrors(SynchronousPriority);
514
} finally {
515
shouldBatchUpdates = prev;
516
}
@@ -540,9 +540,22 @@ module.exports = function<T, P, I, TI, C>(config : HostConfig<T, P, I, TI, C>) {
540
}
541
}
542
543
- function performAndHandleErrors<A>(fn: (a: A) => void, a: A) {
543
+ function performAndHandleErrors(priorityLevel : PriorityLevel, deadline : ?Deadline) {
544
+ // The exact priority level doesn't matter, so long as it's in range of the
545
+ // work (sync, animation, deferred) being performed.
546
try {
545
- fn(a);
547
+ if (priorityLevel === SynchronousPriority) {
548
+ performSynchronousWorkUnsafe();
549
+ }
550
+ if (priorityLevel > AnimationPriority) {
551
+ if (!deadline) {
552
+ throw new Error('No deadline');
553
+ } else {
554
+ performDeferredWorkUnsafe(deadline);
555
+ }
556
+ return;
557
+ }
558
+ performAnimationWorkUnsafe();
559
} catch (error) {
560
const failedUnitOfWork = nextUnitOfWork;
561
// Reset because it points to the error boundary: