Skip to content

Commit d0d798e

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 6afff20 commit d0d798e

File tree

4 files changed

+52
-91
lines changed

4 files changed

+52
-91
lines changed

src/renderers/shared/fiber/ReactFiberBeginWork.js

+7-17
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,13 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
7272
config: HostConfig<T, P, I, TI, PI, C, CX, PL>,
7373
hostContext: HostContext<C, CX>,
7474
hydrationContext: HydrationContext<C, CX>,
75-
scheduleUpdate: (fiber: Fiber, expirationTime: ExpirationTime) => void,
76-
getPriorityContext: (
75+
scheduleUpdate: (
7776
fiber: Fiber,
78-
forceAsync: boolean,
79-
) => PriorityLevel | null,
80-
recalculateCurrentTime: () => ExpirationTime,
81-
getExpirationTimeForPriority: (
82-
currentTime: ExpirationTime,
83-
priorityLevel: PriorityLevel | null,
84-
) => ExpirationTime,
77+
partialState: mixed,
78+
callback: () => mixed | null,
79+
isReplace: boolean,
80+
isForced: boolean,
81+
) => void,
8582
) {
8683
const {
8784
shouldSetTextContent,
@@ -103,14 +100,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
103100
mountClassInstance,
104101
// resumeMountClassInstance,
105102
updateClassInstance,
106-
} = ReactFiberClassComponent(
107-
scheduleUpdate,
108-
getPriorityContext,
109-
memoizeProps,
110-
memoizeState,
111-
recalculateCurrentTime,
112-
getExpirationTimeForPriority,
113-
);
103+
} = ReactFiberClassComponent(scheduleUpdate, memoizeProps, memoizeState);
114104

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

src/renderers/shared/fiber/ReactFiberClassComponent.js

+9-63
Original file line numberDiff line numberDiff line change
@@ -76,96 +76,42 @@ if (__DEV__) {
7676
}
7777

7878
module.exports = function(
79-
scheduleUpdate: (fiber: Fiber, expirationTime: ExpirationTime) => void,
80-
getPriorityContext: (
79+
scheduleUpdate: (
8180
fiber: Fiber,
82-
forceAsync: boolean,
83-
) => PriorityLevel | null,
81+
partialState: mixed,
82+
callback: () => mixed | null,
83+
isReplace: boolean,
84+
isForced: boolean,
85+
) => void,
8486
memoizeProps: (workInProgress: Fiber, props: any) => void,
8587
memoizeState: (workInProgress: Fiber, state: any) => void,
86-
recalculateCurrentTime: () => ExpirationTime,
87-
getExpirationTimeForPriority: (
88-
currentTime: ExpirationTime,
89-
priorityLevel: PriorityLevel | null,
90-
) => ExpirationTime,
9188
) {
9289
// Class component state updater
9390
const updater = {
9491
isMounted,
9592
enqueueSetState(instance, partialState, callback) {
9693
const fiber = ReactInstanceMap.get(instance);
97-
const priorityLevel = getPriorityContext(fiber, false);
98-
const currentTime = recalculateCurrentTime();
99-
const expirationTime = getExpirationTimeForPriority(
100-
currentTime,
101-
priorityLevel,
102-
);
10394
callback = callback === undefined ? null : callback;
10495
if (__DEV__) {
10596
warnOnInvalidCallback(callback, 'setState');
10697
}
107-
const update = {
108-
priorityLevel,
109-
expirationTime,
110-
partialState,
111-
callback,
112-
isReplace: false,
113-
isForced: false,
114-
nextCallback: null,
115-
next: null,
116-
};
117-
insertUpdateIntoFiber(fiber, update, currentTime);
118-
scheduleUpdate(fiber, expirationTime);
98+
scheduleUpdate(fiber, partialState, callback, false, false);
11999
},
120100
enqueueReplaceState(instance, state, callback) {
121101
const fiber = ReactInstanceMap.get(instance);
122-
const priorityLevel = getPriorityContext(fiber, false);
123-
const currentTime = recalculateCurrentTime();
124-
const expirationTime = getExpirationTimeForPriority(
125-
currentTime,
126-
priorityLevel,
127-
);
128102
callback = callback === undefined ? null : callback;
129103
if (__DEV__) {
130104
warnOnInvalidCallback(callback, 'replaceState');
131105
}
132-
const update = {
133-
priorityLevel,
134-
expirationTime,
135-
partialState: state,
136-
callback,
137-
isReplace: true,
138-
isForced: false,
139-
nextCallback: null,
140-
next: null,
141-
};
142-
insertUpdateIntoFiber(fiber, update, currentTime);
143-
scheduleUpdate(fiber, expirationTime);
106+
scheduleUpdate(fiber, state, callback, true, false);
144107
},
145108
enqueueForceUpdate(instance, callback) {
146109
const fiber = ReactInstanceMap.get(instance);
147-
const priorityLevel = getPriorityContext(fiber, false);
148-
const currentTime = recalculateCurrentTime();
149-
const expirationTime = getExpirationTimeForPriority(
150-
currentTime,
151-
priorityLevel,
152-
);
153110
callback = callback === undefined ? null : callback;
154111
if (__DEV__) {
155112
warnOnInvalidCallback(callback, 'forceUpdate');
156113
}
157-
const update = {
158-
priorityLevel,
159-
expirationTime,
160-
partialState: null,
161-
callback,
162-
isReplace: false,
163-
isForced: true,
164-
nextCallback: null,
165-
next: null,
166-
};
167-
insertUpdateIntoFiber(fiber, update, currentTime);
168-
scheduleUpdate(fiber, expirationTime);
114+
scheduleUpdate(fiber, null, callback, false, true);
169115
},
170116
};
171117

src/renderers/shared/fiber/ReactFiberReconciler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
222222
var {getPublicInstance} = config;
223223

224224
var {
225-
scheduleUpdate,
225+
scheduleWork,
226226
scheduleCompletionCallback,
227227
getPriorityContext,
228228
getExpirationTimeForPriority,
@@ -313,7 +313,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
313313
insertUpdateIntoQueue(root.blockers, block, currentTime);
314314
}
315315

316-
scheduleUpdate(current, expirationTime);
316+
scheduleWork(current, expirationTime);
317317
return expirationTime;
318318
}
319319

src/renderers/shared/fiber/ReactFiberScheduler.js

+34-9
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');
@@ -174,9 +175,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
174175
hostContext,
175176
hydrationContext,
176177
scheduleUpdate,
177-
getPriorityContext,
178-
recalculateCurrentTime,
179-
getExpirationTimeForPriority,
180178
);
181179
const {completeWork} = ReactFiberCompleteWork(
182180
config,
@@ -1525,11 +1523,38 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
15251523
}
15261524
}
15271525

1528-
function scheduleUpdate(fiber: Fiber, expirationTime: ExpirationTime) {
1529-
return scheduleUpdateImpl(fiber, expirationTime, false);
1526+
function scheduleUpdate(
1527+
fiber: Fiber,
1528+
partialState: mixed,
1529+
callback: (() => mixed) | null,
1530+
isReplace: boolean,
1531+
isForced: boolean,
1532+
) {
1533+
const priorityLevel = getPriorityContext(fiber, false);
1534+
const currentTime = recalculateCurrentTime();
1535+
const expirationTime = getExpirationTimeForPriority(
1536+
currentTime,
1537+
priorityLevel,
1538+
);
1539+
const update = {
1540+
priorityLevel,
1541+
expirationTime,
1542+
partialState,
1543+
callback,
1544+
isReplace,
1545+
isForced,
1546+
nextCallback: null,
1547+
next: null,
1548+
};
1549+
insertUpdateIntoFiber(fiber, update, currentTime);
1550+
scheduleWork(fiber, expirationTime);
1551+
}
1552+
1553+
function scheduleWork(fiber: Fiber, expirationTime: ExpirationTime) {
1554+
return scheduleWorkImpl(fiber, expirationTime, false);
15301555
}
15311556

1532-
function scheduleUpdateImpl(
1557+
function scheduleWorkImpl(
15331558
fiber: Fiber,
15341559
expirationTime: ExpirationTime,
15351560
isErrorRecovery: boolean,
@@ -1663,7 +1688,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
16631688
// callback synchronously.
16641689
performWork(TaskPriority, null);
16651690
} else {
1666-
scheduleUpdate(root.current, expirationTime);
1691+
scheduleWork(root.current, expirationTime);
16671692
}
16681693
}
16691694

@@ -1718,7 +1743,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
17181743
mostRecentCurrentTime,
17191744
TaskPriority,
17201745
);
1721-
scheduleUpdateImpl(fiber, taskTime, true);
1746+
scheduleWorkImpl(fiber, taskTime, true);
17221747
}
17231748

17241749
function recalculateCurrentTime(): ExpirationTime {
@@ -1810,7 +1835,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
18101835
}
18111836

18121837
return {
1813-
scheduleUpdate: scheduleUpdate,
1838+
scheduleWork: scheduleWork,
18141839
scheduleCompletionCallback: scheduleCompletionCallback,
18151840
getPriorityContext: getPriorityContext,
18161841
recalculateCurrentTime: recalculateCurrentTime,

0 commit comments

Comments
 (0)