Use sigil instead of comparing baseState to null
Andrew Clark committed
Oct 18, 2017 at 15:39 UTC
76659c418f730c19fa4ca08320efd71d8de15b43
1 file changed
+10
-3
src/renderers/shared/fiber/ReactFiberUpdateQueue.js
+10
-3
@@ -64,6 +64,7 @@ export type UpdateQueue<State> = {
64
last: Update<State> | null,
65
callbackList: Array<Update<State>> | null,
66
hasForceUpdate: boolean,
67
+ isInitialized: boolean,
68
69
// Dev only
70
isProcessing?: boolean,
@@ -77,6 +78,7 @@ function createUpdateQueue<State>(baseState: State): UpdateQueue<State> {
78
last: null,
79
callbackList: null,
80
hasForceUpdate: false,
81
+ isInitialized: false,
82
};
83
if (__DEV__) {
84
queue.isProcessing = false;
@@ -204,6 +206,7 @@ function processUpdateQueue<State>(
206
expirationTime: currentQueue.expirationTime,
207
first: currentQueue.first,
208
last: currentQueue.last,
209
+ isInitialized: currentQueue.isInitialized,
210
// These fields are no longer valid because they were already committed.
211
// Reset them.
212
callbackList: null,
@@ -225,9 +228,13 @@ function processUpdateQueue<State>(
228
// It depends on which fiber is the next current. Initialize with an empty
229
// base state, then set to the memoizedState when rendering. Not super
230
// happy with this approach.
228
- let state = queue.baseState === null
229
- ? workInProgress.memoizedState
230
- : queue.baseState;
231
+ let state;
232
+ if (queue.isInitialized) {
233
+ state = queue.baseState;
234
+ } else {
235
+ state = queue.baseState = workInProgress.memoizedState;
236
+ queue.isInitialized = true;
237
+ }
238
let dontMutatePrevState = true;
239
let update = queue.first;
240
let didSkip = false;