Skip to content

Commit 3965001

Browse files
committed
Split scheduleUpdate into scheduleUpdate and scheduleWork.
scheduleWork updates the priority of the fiber and its ancestors and schedules work to be performed. scheduleUpdate inserts an update into a fiber's update queue and calls then schedules work with scheduleWork. Now we don't have to export so many things from the scheduler.
1 parent a93d3ef commit 3965001

File tree

4 files changed

+53
-97
lines changed

4 files changed

+53
-97
lines changed

src/renderers/shared/fiber/ReactFiberBeginWork.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {HostContext} from 'ReactFiberHostContext';
1616
import type {HydrationContext} from 'ReactFiberHydrationContext';
1717
import type {FiberRoot} from 'ReactFiberRoot';
1818
import type {HostConfig} from 'ReactFiberReconciler';
19-
import type {PriorityLevel} from 'ReactPriorityLevel';
2019
import type {ExpirationTime} from 'ReactFiberExpirationTime';
2120

2221
var {
@@ -72,16 +71,13 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
7271
config: HostConfig<T, P, I, TI, PI, C, CX, PL>,
7372
hostContext: HostContext<C, CX>,
7473
hydrationContext: HydrationContext<C, CX>,
75-
scheduleUpdate: (fiber: Fiber, expirationTime: ExpirationTime) => void,
76-
getPriorityContext: (
74+
scheduleUpdate: (
7775
fiber: Fiber,
78-
forceAsync: boolean,
79-
) => PriorityLevel | null,
80-
recalculateCurrentTime: () => ExpirationTime,
81-
getExpirationTimeForPriority: (
82-
currentTime: ExpirationTime,
83-
priorityLevel: PriorityLevel | null,
84-
) => ExpirationTime,
76+
partialState: mixed,
77+
callback: (() => mixed) | null,
78+
isReplace: boolean,
79+
isForced: boolean,
80+
) => void,
8581
) {
8682
const {
8783
shouldSetTextContent,
@@ -103,14 +99,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
10399
mountClassInstance,
104100
// resumeMountClassInstance,
105101
updateClassInstance,
106-
} = ReactFiberClassComponent(
107-
scheduleUpdate,
108-
getPriorityContext,
109-
memoizeProps,
110-
memoizeState,
111-
recalculateCurrentTime,
112-
getExpirationTimeForPriority,
113-
);
102+
} = ReactFiberClassComponent(scheduleUpdate, memoizeProps, memoizeState);
114103

115104
// TODO: Remove this and use reconcileChildrenAtExpirationTime directly.
116105
function reconcileChildren(current, workInProgress, nextChildren) {

src/renderers/shared/fiber/ReactFiberClassComponent.js

Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
'use strict';
1212

1313
import type {Fiber} from 'ReactFiber';
14-
import type {PriorityLevel} from 'ReactPriorityLevel';
1514
import type {ExpirationTime} from 'ReactFiberExpirationTime';
1615

1716
var {Update} = require('ReactTypeOfSideEffect');
@@ -25,10 +24,7 @@ var {
2524
getUnmaskedContext,
2625
isContextConsumer,
2726
} = require('ReactFiberContext');
28-
var {
29-
insertUpdateIntoFiber,
30-
beginUpdateQueue,
31-
} = require('ReactFiberUpdateQueue');
27+
var {beginUpdateQueue} = require('ReactFiberUpdateQueue');
3228
var {hasContextChanged} = require('ReactFiberContext');
3329
var {isMounted} = require('ReactFiberTreeReflection');
3430
var ReactInstanceMap = require('ReactInstanceMap');
@@ -76,96 +72,42 @@ if (__DEV__) {
7672
}
7773

7874
module.exports = function(
79-
scheduleUpdate: (fiber: Fiber, expirationTime: ExpirationTime) => void,
80-
getPriorityContext: (
75+
scheduleUpdate: (
8176
fiber: Fiber,
82-
forceAsync: boolean,
83-
) => PriorityLevel | null,
77+
partialState: mixed,
78+
callback: (() => mixed) | null,
79+
isReplace: boolean,
80+
isForced: boolean,
81+
) => void,
8482
memoizeProps: (workInProgress: Fiber, props: any) => void,
8583
memoizeState: (workInProgress: Fiber, state: any) => void,
86-
recalculateCurrentTime: () => ExpirationTime,
87-
getExpirationTimeForPriority: (
88-
currentTime: ExpirationTime,
89-
priorityLevel: PriorityLevel | null,
90-
) => ExpirationTime,
9184
) {
9285
// Class component state updater
9386
const updater = {
9487
isMounted,
9588
enqueueSetState(instance, partialState, callback) {
9689
const fiber = ReactInstanceMap.get(instance);
97-
const priorityLevel = getPriorityContext(fiber, false);
98-
const currentTime = recalculateCurrentTime();
99-
const expirationTime = getExpirationTimeForPriority(
100-
currentTime,
101-
priorityLevel,
102-
);
10390
callback = callback === undefined ? null : callback;
10491
if (__DEV__) {
10592
warnOnInvalidCallback(callback, 'setState');
10693
}
107-
const update = {
108-
priorityLevel,
109-
expirationTime,
110-
partialState,
111-
callback,
112-
isReplace: false,
113-
isForced: false,
114-
isTopLevelUnmount: false,
115-
next: null,
116-
};
117-
insertUpdateIntoFiber(fiber, update, currentTime);
118-
scheduleUpdate(fiber, expirationTime);
94+
scheduleUpdate(fiber, partialState, callback, false, false);
11995
},
12096
enqueueReplaceState(instance, state, callback) {
12197
const fiber = ReactInstanceMap.get(instance);
122-
const priorityLevel = getPriorityContext(fiber, false);
123-
const currentTime = recalculateCurrentTime();
124-
const expirationTime = getExpirationTimeForPriority(
125-
currentTime,
126-
priorityLevel,
127-
);
12898
callback = callback === undefined ? null : callback;
12999
if (__DEV__) {
130100
warnOnInvalidCallback(callback, 'replaceState');
131101
}
132-
const update = {
133-
priorityLevel,
134-
expirationTime,
135-
partialState: state,
136-
callback,
137-
isReplace: true,
138-
isForced: false,
139-
isTopLevelUnmount: false,
140-
next: null,
141-
};
142-
insertUpdateIntoFiber(fiber, update, currentTime);
143-
scheduleUpdate(fiber, expirationTime);
102+
scheduleUpdate(fiber, state, callback, true, false);
144103
},
145104
enqueueForceUpdate(instance, callback) {
146105
const fiber = ReactInstanceMap.get(instance);
147-
const priorityLevel = getPriorityContext(fiber, false);
148-
const currentTime = recalculateCurrentTime();
149-
const expirationTime = getExpirationTimeForPriority(
150-
currentTime,
151-
priorityLevel,
152-
);
153106
callback = callback === undefined ? null : callback;
154107
if (__DEV__) {
155108
warnOnInvalidCallback(callback, 'forceUpdate');
156109
}
157-
const update = {
158-
priorityLevel,
159-
expirationTime,
160-
partialState: null,
161-
callback,
162-
isReplace: false,
163-
isForced: true,
164-
isTopLevelUnmount: false,
165-
next: null,
166-
};
167-
insertUpdateIntoFiber(fiber, update, currentTime);
168-
scheduleUpdate(fiber, expirationTime);
110+
scheduleUpdate(fiber, null, callback, false, true);
169111
},
170112
};
171113

src/renderers/shared/fiber/ReactFiberReconciler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
223223
var {getPublicInstance} = config;
224224

225225
var {
226-
scheduleUpdate,
226+
scheduleWork,
227227
scheduleCompletionCallback,
228228
getPriorityContext,
229229
getExpirationTimeForPriority,
@@ -337,7 +337,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
337337
insertUpdateIntoQueue(root.blockers, block, currentTime);
338338
}
339339

340-
scheduleUpdate(current, expirationTime);
340+
scheduleWork(current, expirationTime);
341341
return expirationTime;
342342
}
343343

src/renderers/shared/fiber/ReactFiberScheduler.js

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ var {
9898
processUpdateQueue,
9999
createUpdateQueue,
100100
insertUpdateIntoQueue,
101+
insertUpdateIntoFiber,
101102
} = require('ReactFiberUpdateQueue');
102103

103104
var {resetContext} = require('ReactFiberContext');
@@ -180,9 +181,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
180181
hostContext,
181182
hydrationContext,
182183
scheduleUpdate,
183-
getPriorityContext,
184-
recalculateCurrentTime,
185-
getExpirationTimeForPriority,
186184
);
187185
const {completeWork} = ReactFiberCompleteWork(
188186
config,
@@ -1531,11 +1529,38 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
15311529
}
15321530
}
15331531

1534-
function scheduleUpdate(fiber: Fiber, expirationTime: ExpirationTime) {
1535-
return scheduleUpdateImpl(fiber, expirationTime, false);
1532+
function scheduleUpdate(
1533+
fiber: Fiber,
1534+
partialState: mixed,
1535+
callback: (() => mixed) | null,
1536+
isReplace: boolean,
1537+
isForced: boolean,
1538+
) {
1539+
const priorityLevel = getPriorityContext(fiber, false);
1540+
const currentTime = recalculateCurrentTime();
1541+
const expirationTime = getExpirationTimeForPriority(
1542+
currentTime,
1543+
priorityLevel,
1544+
);
1545+
const update = {
1546+
priorityLevel,
1547+
expirationTime,
1548+
partialState,
1549+
callback,
1550+
isReplace,
1551+
isForced,
1552+
nextCallback: null,
1553+
next: null,
1554+
};
1555+
insertUpdateIntoFiber(fiber, update, currentTime);
1556+
scheduleWork(fiber, expirationTime);
1557+
}
1558+
1559+
function scheduleWork(fiber: Fiber, expirationTime: ExpirationTime) {
1560+
return scheduleWorkImpl(fiber, expirationTime, false);
15361561
}
15371562

1538-
function scheduleUpdateImpl(
1563+
function scheduleWorkImpl(
15391564
fiber: Fiber,
15401565
expirationTime: ExpirationTime,
15411566
isErrorRecovery: boolean,
@@ -1669,7 +1694,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
16691694
// callback synchronously.
16701695
performWork(TaskPriority, null);
16711696
} else {
1672-
scheduleUpdate(root.current, expirationTime);
1697+
scheduleWork(root.current, expirationTime);
16731698
}
16741699
}
16751700

@@ -1724,7 +1749,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
17241749
mostRecentCurrentTime,
17251750
TaskPriority,
17261751
);
1727-
scheduleUpdateImpl(fiber, taskTime, true);
1752+
scheduleWorkImpl(fiber, taskTime, true);
17281753
}
17291754

17301755
function recalculateCurrentTime(): ExpirationTime {
@@ -1818,7 +1843,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
18181843
}
18191844

18201845
return {
1821-
scheduleUpdate: scheduleUpdate,
1846+
scheduleWork: scheduleWork,
18221847
scheduleCompletionCallback: scheduleCompletionCallback,
18231848
getPriorityContext: getPriorityContext,
18241849
recalculateCurrentTime: recalculateCurrentTime,

0 commit comments

Comments
 (0)