Skip to content

Commit 036f294

Browse files
committed
Fix UpdateQueue flow types
This makes the types for UpdateQueue a bit more sound though it's still not quite right. Not sure how to properly State so that it works with partial state updates, replaceState, and updater functions. This at least gives us more safety for non-Fiber update queues, like FiberRoot's completionCallbacks queue.
1 parent a1553d4 commit 036f294

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

src/renderers/dom/fiber/ReactDOMFiberEntry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ function renderSubtreeIntoContainer(
694694
type PublicRoot = {
695695
render(children: ReactNodeList, callback: ?() => mixed): void,
696696
prerender(children: ReactNodeList): Work,
697-
unmount(callback: ?() => mixed): Work,
697+
unmount(callback: ?() => mixed): void,
698698

699699
_reactRootContainer: *,
700700
_getComponent: () => DOMContainer,

src/renderers/noop/ReactNoopEntry.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ var ReactNoop = {
410410
logHostInstances(container.children, depth + 1);
411411
}
412412

413-
function logUpdateQueue(updateQueue: UpdateQueue, depth) {
413+
function logUpdateQueue(updateQueue: UpdateQueue<mixed>, depth) {
414414
log(' '.repeat(depth + 1) + 'QUEUED UPDATES');
415415
const firstUpdate = updateQueue.first;
416416
if (!firstUpdate) {

src/renderers/shared/fiber/ReactFiber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export type Fiber = {|
115115
memoizedProps: any, // The props used to create the output.
116116

117117
// A queue of state updates and callbacks.
118-
updateQueue: UpdateQueue | null,
118+
updateQueue: UpdateQueue<any> | null,
119119

120120
// The state used to create the output
121121
memoizedState: any,

src/renderers/shared/fiber/ReactFiberReconciler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
320320
const blockUpdate = {
321321
priorityLevel: null,
322322
expirationTime,
323-
partialState: nextState,
323+
partialState: null,
324324
callback: null,
325325
isReplace: false,
326326
isForced: false,

src/renderers/shared/fiber/ReactFiberScheduler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
985985
nextRenderExpirationTime,
986986
);
987987

988-
loop: while (
988+
while (
989989
shouldContinueWorking(minPriorityLevel, nextPriorityLevel, deadline)
990990
) {
991991
if (nextRenderExpirationTime <= mostRecentCurrentTime) {

src/renderers/shared/fiber/ReactFiberUpdateQueue.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ type PartialState<State, Props> =
3030
| $Subtype<State>
3131
| ((prevState: State, props: Props) => $Subtype<State>);
3232

33-
// Callbacks are not validated until invocation
34-
type Callback = mixed;
33+
type Callback = () => mixed;
3534

3635
export type Update<State> = {
3736
priorityLevel: PriorityLevel | null,
@@ -69,7 +68,7 @@ let _queue1;
6968
let _queue2;
7069

7170
function createUpdateQueue<State>(): UpdateQueue<State> {
72-
const queue: UpdateQueue = {
71+
const queue: UpdateQueue<State> = {
7372
first: null,
7473
last: null,
7574
hasForceUpdate: false,
@@ -82,7 +81,7 @@ function createUpdateQueue<State>(): UpdateQueue<State> {
8281
}
8382
exports.createUpdateQueue = createUpdateQueue;
8483

85-
function cloneUpdate(update: Update<State>): Update<State> {
84+
function cloneUpdate<State>(update: Update<State>): Update<State> {
8685
return {
8786
priorityLevel: update.priorityLevel,
8887
expirationTime: update.expirationTime,
@@ -97,7 +96,7 @@ function cloneUpdate(update: Update<State>): Update<State> {
9796

9897
const COALESCENCE_THRESHOLD: ExpirationTime = 10;
9998

100-
function insertUpdateIntoPosition(
99+
function insertUpdateIntoPosition<State>(
101100
queue: UpdateQueue<State>,
102101
update: Update<State>,
103102
insertAfter: Update<State> | null,
@@ -138,7 +137,7 @@ function insertUpdateIntoPosition(
138137

139138
// Returns the update after which the incoming update should be inserted into
140139
// the queue, or null if it should be inserted at beginning.
141-
function findInsertionPosition(
140+
function findInsertionPosition<State>(
142141
queue: UpdateQueue<State>,
143142
update: Update<State>,
144143
): Update<State> | null {
@@ -214,7 +213,7 @@ function ensureUpdateQueues(fiber: Fiber) {
214213
// we shouldn't make a copy.
215214
//
216215
// If the update is cloned, it returns the cloned update.
217-
function insertUpdateIntoFiber(
216+
function insertUpdateIntoFiber<State>(
218217
fiber: Fiber,
219218
update: Update<State>,
220219
currentTime: ExpirationTime,
@@ -304,8 +303,8 @@ function insertUpdateIntoFiber(
304303
}
305304
exports.insertUpdateIntoFiber = insertUpdateIntoFiber;
306305

307-
function insertUpdateIntoQueue(
308-
queue: UpdateQueue,
306+
function insertUpdateIntoQueue<State>(
307+
queue: UpdateQueue<State>,
309308
update: Update<State>,
310309
currentTime: ExpirationTime,
311310
) {
@@ -337,13 +336,14 @@ function getStateFromUpdate(update, instance, prevState, props) {
337336
const partialState = update.partialState;
338337
if (typeof partialState === 'function') {
339338
const updateFn = partialState;
339+
// $FlowFixMe - Idk how to type State correctly.
340340
return updateFn.call(instance, prevState, props);
341341
} else {
342342
return partialState;
343343
}
344344
}
345345

346-
function processUpdateQueue(
346+
function processUpdateQueue<State>(
347347
queue: UpdateQueue<State>,
348348
instance: mixed,
349349
prevState: State,
@@ -382,6 +382,7 @@ function processUpdateQueue(
382382
partialState = getStateFromUpdate(update, instance, state, props);
383383
if (partialState) {
384384
if (dontMutatePrevState) {
385+
// $FlowFixMe - Idk how to type State properly.
385386
state = Object.assign({}, state, partialState);
386387
} else {
387388
state = Object.assign(state, partialState);
@@ -416,7 +417,7 @@ function processUpdateQueue(
416417
}
417418
exports.processUpdateQueue = processUpdateQueue;
418419

419-
function beginUpdateQueue(
420+
function beginUpdateQueue<State>(
420421
current: Fiber | null,
421422
workInProgress: Fiber,
422423
queue: UpdateQueue<State>,

0 commit comments

Comments
 (0)