Fix stateQueue typing
Andrew Clark committed
Jul 25, 2016 at 09:36 UTC
691e053650a161afda9c2ad1dd02f21ec264e2f0
3 files changed
+12
-11
src/renderers/shared/fiber/ReactFiber.js
+1
-1
@@ -78,7 +78,7 @@ export type Fiber = Instance & {
78
// TODO: I think that there is a way to merge pendingProps and memoizedProps.
79
memoizedProps: any, // The props used to create the output.
80
// A queue of local state updates.
81
- stateQueue: StateQueue,
81
+ stateQueue: ?StateQueue,
82
// The state used to create the output. This is a full state object.
83
memoizedState: any,
84
// Output is the return value of this fiber, or a linked list of return values
src/renderers/shared/fiber/ReactFiberBeginWork.js
+6
-2
@@ -152,7 +152,9 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>, getSchedu
152
const updater = {
153
enqueueSetState(instance, partialState) {
154
const fiber = instance._fiber;
155
- const stateQueue = addToQueue(fiber.stateQueue, partialState);
155
+ const stateQueue = fiber.stateQueue ?
156
+ addToQueue(fiber.stateQueue, partialState) :
157
+ createStateQueue(partialState);
158
scheduleUpdate(fiber, stateQueue, LowPriority);
159
},
160
};
@@ -181,7 +183,9 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>, getSchedu
183
state = instance.state || null;
184
// The initial state must be added to the pending state queue in case
185
// setState is called before the initial render.
184
- workInProgress.stateQueue = createStateQueue(state);
186
+ if (state !== null) {
187
+ workInProgress.stateQueue = createStateQueue(state);
188
+ }
189
// The instance needs access to the fiber so that it can schedule updates
190
instance._fiber = workInProgress;
191
instance.updater = updater;
src/renderers/shared/fiber/ReactFiberStateQueue.js
+5
-8
@@ -14,9 +14,9 @@
14
15
export type StateQueue = {
16
partialState: any,
17
- next: StateQueue,
18
- tail: StateQueue
19
-} | null;
17
+ next: StateQueue | null,
18
+ tail: StateQueue | null
19
+};
20
21
exports.createStateQueue = function(partialState : mixed) : StateQueue {
22
return {
@@ -28,9 +28,6 @@ exports.createStateQueue = function(partialState : mixed) : StateQueue {
28
29
exports.addToQueue = function(queue : StateQueue, partialState : mixed): StateQueue {
30
const node = exports.createStateQueue(partialState);
31
- if (queue === null) {
32
- return node;
33
- }
31
if (queue.tail === null) {
32
queue.next = node;
33
} else {
@@ -40,8 +37,8 @@ exports.addToQueue = function(queue : StateQueue, partialState : mixed): StateQu
37
return queue;
38
};
39
43
-exports.mergeStateQueue = function(prevState : any, props : any, queue : StateQueue) : any {
44
- if (queue === null) {
40
+exports.mergeStateQueue = function(prevState : any, props : any, queue : ?StateQueue) : any {
41
+ if (!queue) {
42
return prevState;
43
}
44
let state = Object.assign({}, prevState);