mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Fix stateQueue typing
This commit is contained in:
committed by
Sebastian Markbage
parent
909caccebd
commit
691e053650
@@ -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
|
||||
|
||||
@@ -152,7 +152,9 @@ module.exports = function<T, P, I, C>(config : HostConfig<T, P, I, C>, 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<T, P, I, C>(config : HostConfig<T, P, I, C>, 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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user