From 691e053650a161afda9c2ad1dd02f21ec264e2f0 Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Mon, 25 Jul 2016 09:36:08 -0700 Subject: [PATCH] Fix stateQueue typing --- src/renderers/shared/fiber/ReactFiber.js | 2 +- src/renderers/shared/fiber/ReactFiberBeginWork.js | 8 ++++++-- src/renderers/shared/fiber/ReactFiberStateQueue.js | 13 +++++-------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 33128d85dd..d6dc2bf337 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -78,7 +78,7 @@ export type Fiber = Instance & { // TODO: I think that there is a way to merge pendingProps and memoizedProps. memoizedProps: any, // The props used to create the output. // A queue of local state updates. - stateQueue: StateQueue, + stateQueue: ?StateQueue, // The state used to create the output. This is a full state object. memoizedState: any, // Output is the return value of this fiber, or a linked list of return values diff --git a/src/renderers/shared/fiber/ReactFiberBeginWork.js b/src/renderers/shared/fiber/ReactFiberBeginWork.js index 3004ce13d2..a8e97032d2 100644 --- a/src/renderers/shared/fiber/ReactFiberBeginWork.js +++ b/src/renderers/shared/fiber/ReactFiberBeginWork.js @@ -152,7 +152,9 @@ module.exports = function(config : HostConfig, getSchedu const updater = { enqueueSetState(instance, partialState) { const fiber = instance._fiber; - const stateQueue = addToQueue(fiber.stateQueue, partialState); + const stateQueue = fiber.stateQueue ? + addToQueue(fiber.stateQueue, partialState) : + createStateQueue(partialState); scheduleUpdate(fiber, stateQueue, LowPriority); }, }; @@ -181,7 +183,9 @@ module.exports = function(config : HostConfig, getSchedu state = instance.state || null; // The initial state must be added to the pending state queue in case // setState is called before the initial render. - workInProgress.stateQueue = createStateQueue(state); + if (state !== null) { + workInProgress.stateQueue = createStateQueue(state); + } // The instance needs access to the fiber so that it can schedule updates instance._fiber = workInProgress; instance.updater = updater; diff --git a/src/renderers/shared/fiber/ReactFiberStateQueue.js b/src/renderers/shared/fiber/ReactFiberStateQueue.js index 9ba3063361..5932002810 100644 --- a/src/renderers/shared/fiber/ReactFiberStateQueue.js +++ b/src/renderers/shared/fiber/ReactFiberStateQueue.js @@ -14,9 +14,9 @@ export type StateQueue = { partialState: any, - next: StateQueue, - tail: StateQueue -} | null; + next: StateQueue | null, + tail: StateQueue | null +}; exports.createStateQueue = function(partialState : mixed) : StateQueue { return { @@ -28,9 +28,6 @@ exports.createStateQueue = function(partialState : mixed) : StateQueue { exports.addToQueue = function(queue : StateQueue, partialState : mixed): StateQueue { const node = exports.createStateQueue(partialState); - if (queue === null) { - return node; - } if (queue.tail === null) { queue.next = node; } else { @@ -40,8 +37,8 @@ exports.addToQueue = function(queue : StateQueue, partialState : mixed): StateQu return queue; }; -exports.mergeStateQueue = function(prevState : any, props : any, queue : StateQueue) : any { - if (queue === null) { +exports.mergeStateQueue = function(prevState : any, props : any, queue : ?StateQueue) : any { + if (!queue) { return prevState; } let state = Object.assign({}, prevState);