Skip to content

Commit

Permalink
Use sigil instead of comparing baseState to null
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed Oct 18, 2017
1 parent d964728 commit 76659c4
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/renderers/shared/fiber/ReactFiberUpdateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type UpdateQueue<State> = {
last: Update<State> | null,
callbackList: Array<Update<State>> | null,
hasForceUpdate: boolean,
isInitialized: boolean,

// Dev only
isProcessing?: boolean,
Expand All @@ -77,6 +78,7 @@ function createUpdateQueue<State>(baseState: State): UpdateQueue<State> {
last: null,
callbackList: null,
hasForceUpdate: false,
isInitialized: false,
};
if (__DEV__) {
queue.isProcessing = false;
Expand Down Expand Up @@ -204,6 +206,7 @@ function processUpdateQueue<State>(
expirationTime: currentQueue.expirationTime,
first: currentQueue.first,
last: currentQueue.last,
isInitialized: currentQueue.isInitialized,
// These fields are no longer valid because they were already committed.
// Reset them.
callbackList: null,
Expand All @@ -225,9 +228,13 @@ function processUpdateQueue<State>(
// It depends on which fiber is the next current. Initialize with an empty
// base state, then set to the memoizedState when rendering. Not super
// happy with this approach.
let state = queue.baseState === null
? workInProgress.memoizedState
: queue.baseState;
let state;
if (queue.isInitialized) {
state = queue.baseState;
} else {
state = queue.baseState = workInProgress.memoizedState;
queue.isInitialized = true;
}
let dontMutatePrevState = true;
let update = queue.first;
let didSkip = false;
Expand Down

0 comments on commit 76659c4

Please sign in to comment.