Skip to content
Merged
Prev Previous commit
Next Next commit
Remove first class UpdateQueue types and use closures instead
I tried to avoid this at first, since we avoid it everywhere else in the Fiber
codebase, but since updates are not in a hot path, the trade off with file size
seems worth it.
  • Loading branch information
acdlite committed Apr 21, 2018
commit de45514cd6831c91f790182af862311db2249bb4
14 changes: 3 additions & 11 deletions packages/react-noop-renderer/src/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -526,23 +526,15 @@ const ReactNoop = {

function logUpdateQueue(updateQueue: UpdateQueue<mixed>, depth) {
log(' '.repeat(depth + 1) + 'QUEUED UPDATES');
const firstUpdate = updateQueue.first;
const firstUpdate = updateQueue.firstUpdate;
if (!firstUpdate) {
return;
}

log(
' '.repeat(depth + 1) + '~',
firstUpdate && firstUpdate.partialState,
firstUpdate.callback ? 'with callback' : '',
'[' + firstUpdate.expirationTime + ']',
);
let next;
while ((next = firstUpdate.next)) {
log(' '.repeat(depth + 1) + '~', '[' + firstUpdate.expirationTime + ']');
while (firstUpdate.next) {
log(
' '.repeat(depth + 1) + '~',
next.partialState,
next.callback ? 'with callback' : '',
'[' + firstUpdate.expirationTime + ']',
);
}
Expand Down
26 changes: 11 additions & 15 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ import warning from 'fbjs/lib/warning';
import ReactDebugCurrentFiber from './ReactDebugCurrentFiber';
import {cancelWorkTimer} from './ReactDebugFiberPerf';

import ReactFiberClassComponent from './ReactFiberClassComponent';
import ReactFiberClassComponent, {
createGetDerivedStateFromPropsUpdate,
} from './ReactFiberClassComponent';
import {
mountChildFibers,
reconcileChildFibers,
cloneChildFibers,
} from './ReactChildFiber';
import {
createDeriveStateFromPropsUpdate,
enqueueRenderPhaseUpdate,
processClassUpdateQueue,
processRootUpdateQueue,
} from './ReactUpdateQueue';
import {enqueueRenderPhaseUpdate, processUpdateQueue} from './ReactUpdateQueue';
import {NoWork, Never} from './ReactFiberExpirationTime';
import {AsyncMode, StrictMode} from './ReactTypeOfMode';
import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt';
Expand Down Expand Up @@ -415,7 +412,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
let updateQueue = workInProgress.updateQueue;
if (updateQueue !== null) {
const prevChildren = workInProgress.memoizedState;
processRootUpdateQueue(workInProgress, updateQueue, renderExpirationTime);
processUpdateQueue(workInProgress, updateQueue, renderExpirationTime);
const nextChildren = workInProgress.memoizedState;

if (nextChildren === prevChildren) {
Expand Down Expand Up @@ -595,15 +592,14 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(

const getDerivedStateFromProps = Component.getDerivedStateFromProps;
if (typeof getDerivedStateFromProps === 'function') {
const update = createDeriveStateFromPropsUpdate(renderExpirationTime);
const update = createGetDerivedStateFromPropsUpdate(
getDerivedStateFromProps,
renderExpirationTime,
);
enqueueRenderPhaseUpdate(workInProgress, update, renderExpirationTime);
const updateQueue = workInProgress.updateQueue;
if (updateQueue !== null) {
processClassUpdateQueue(
workInProgress,
updateQueue,
renderExpirationTime,
);
processUpdateQueue(workInProgress, updateQueue, renderExpirationTime);
}
}

Expand Down Expand Up @@ -1080,7 +1076,7 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
function memoizeState(workInProgress: Fiber, nextState: any) {
workInProgress.memoizedState = nextState;
// Don't reset the updateQueue, in case there are pending updates. Resetting
// is handled by processClassUpdateQueue.
// is handled by processUpdateQueue.
}

function beginWork(
Expand Down
Loading