Skip to content

Commit

Permalink
Pass next props as argument to begin<TypeOfWork>Component functions
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed May 30, 2017
1 parent 06ce50a commit ea7d604
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 53 deletions.
99 changes: 47 additions & 52 deletions src/renderers/shared/fiber/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
}

function beginHostRoot(current, workInProgress, renderPriority) {
function beginHostRoot(
current: Fiber | null,
workInProgress: Fiber,
nextProps: mixed,
renderPriority: PriorityLevel
): Fiber | null {
const root = (workInProgress.stateNode: FiberRoot);
if (root.pendingContext) {
pushTopLevelContextObject(
Expand Down Expand Up @@ -156,17 +161,12 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
function beginHostPortal(
current: Fiber | null,
workInProgress: Fiber,
nextChildren: mixed,
renderPriority: PriorityLevel,
): Fiber | null {
pushHostContainer(workInProgress, workInProgress.stateNode.containerInfo);

const memoizedChildren = workInProgress.memoizedProps;
let nextChildren = workInProgress.pendingProps;
if (nextChildren === null) {
nextChildren = memoizedChildren;
invariant(nextChildren !== null, 'Must have pending or memoized props.');
}

if (nextChildren === memoizedChildren && !hasContextChanged()) {
return bailout(current, workInProgress, nextChildren, null, renderPriority);
}
Expand All @@ -182,15 +182,15 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
);
}

function beginHostComponent(current, workInProgress, renderPriority) {
function beginHostComponent(
current: Fiber | null,
workInProgress: Fiber,
nextProps: mixed,
renderPriority: PriorityLevel,
): Fiber | null {
pushHostContext(workInProgress);

const memoizedProps = workInProgress.memoizedProps;
let nextProps = workInProgress.pendingProps;
if (nextProps === null) {
nextProps = memoizedProps;
invariant(nextProps !== null, 'Must have pending or memoized props.');
}

// Check if the ref has changed and schedule an effect. This should happen
// even if we bailout.
Expand Down Expand Up @@ -250,13 +250,13 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
);
}

function beginHostText(current, workInProgress, renderPriority) {
function beginHostText(
current: Fiber | null,
workInProgress: Fiber,
nextProps: mixed,
renderPriority: PriorityLevel,
): Fiber | null {
const memoizedProps = workInProgress.memoizedProps;
let nextProps = workInProgress.pendingProps;
if (nextProps === null) {
nextProps = memoizedProps;
invariant(nextProps !== null, 'Must have pending or memoized props.');
}
if (nextProps === memoizedProps) {
return bailout(current, workInProgress, nextProps, null, renderPriority);
}
Expand All @@ -273,23 +273,21 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}

function beginIndeterminateComponent(
current,
workInProgress,
renderPriority,
) {
current: Fiber | null,
workInProgress: Fiber,
nextProps: mixed,
renderPriority: PriorityLevel,
): Fiber | null {
invariant(
current === null,
'An indeterminate component should never have mounted. This error is ' +
'likely caused by a bug in React. Please file an issue.',
);

const fn = workInProgress.type;
const nextProps = workInProgress.pendingProps;
let unmaskedContext = getUnmaskedContext(workInProgress);
let nextContext = getMaskedContext(workInProgress, unmaskedContext);

invariant(nextProps !== null, 'Must have pending props.');

// This is either a functional component or a module-style class component.
let value;
if (__DEV__) {
Expand Down Expand Up @@ -382,16 +380,15 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
}
}

function beginFunctionalComponent(current, workInProgress, renderPriority) {
function beginFunctionalComponent(
current: Fiber | null,
workInProgress: Fiber,
nextProps: mixed,
renderPriority: PriorityLevel,
): Fiber | null {
const fn = workInProgress.type;

const memoizedProps = workInProgress.memoizedProps;
let nextProps = workInProgress.pendingProps;
if (nextProps === null) {
nextProps = memoizedProps;
invariant(nextProps !== null, 'Must have pending or memoized props.');
}

if (
(nextProps === memoizedProps && !hasContextChanged()) ||
// TODO: Disable this before release, since it is not part of the public
Expand Down Expand Up @@ -474,6 +471,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
function beginClassComponent(
current: Fiber | null,
workInProgress: Fiber,
nextProps: mixed,
renderPriority: PriorityLevel,
): Fiber | null {
// Push context providers early to prevent context stack mismatches. During
Expand All @@ -483,12 +481,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(

const ctor = workInProgress.type;

const memoizedProps = workInProgress.memoizedProps;
let nextProps = workInProgress.pendingProps;
if (nextProps === null) {
nextProps = memoizedProps;
invariant(nextProps !== null, 'Must have pending or memoized props.');
}
const unmaskedContext = getUnmaskedContext(workInProgress);
const nextContext = getMaskedContext(workInProgress, unmaskedContext);

Expand Down Expand Up @@ -827,15 +819,10 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
function beginFragment(
current: Fiber | null,
workInProgress: Fiber,
nextProps: mixed,
renderPriority: PriorityLevel,
): Fiber | null {
const memoizedProps = workInProgress.memoizedProps;
let nextProps = workInProgress.pendingProps;
if (nextProps === null) {
nextProps = memoizedProps;
invariant(nextProps !== null, 'Must have pending or memoized props.');
}

if (nextProps === memoizedProps && !hasContextChanged()) {
// No changes to props or context. Bailout.
return bailout(current, workInProgress, nextProps, null, renderPriority);
Expand Down Expand Up @@ -1271,7 +1258,6 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
return resetToCurrent(current, workInProgress, renderPriority);
}


function beginWork(
current: Fiber | null,
workInProgress: Fiber,
Expand All @@ -1288,31 +1274,40 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
workInProgress.firstEffect = null;
workInProgress.lastEffect = null;

let nextProps = workInProgress.pendingProps;
if (nextProps === null) {
// If there are no pending props, re-use the memoized props.
nextProps = workInProgress.memoizedProps;
invariant(nextProps !== null, 'Must have pending or memoized props.');
}

switch (workInProgress.tag) {
case HostRoot:
return beginHostRoot(current, workInProgress, renderPriority);
return beginHostRoot(current, workInProgress, nextProps, renderPriority);
case HostPortal:
return beginHostPortal(current, workInProgress, renderPriority);
return beginHostPortal(current, workInProgress, nextProps, renderPriority);
case HostComponent:
return beginHostComponent(current, workInProgress, renderPriority);
return beginHostComponent(current, workInProgress, nextProps, renderPriority);
case HostText:
return beginHostText(current, workInProgress, renderPriority);
return beginHostText(current, workInProgress, nextProps, renderPriority);
case IndeterminateComponent:
return beginIndeterminateComponent(
current,
workInProgress,
nextProps,
renderPriority,
);
case FunctionalComponent:
return beginFunctionalComponent(
current,
workInProgress,
nextProps,
renderPriority,
);
case ClassComponent:
return beginClassComponent(current, workInProgress, renderPriority);
return beginClassComponent(current, workInProgress, nextProps, renderPriority);
case Fragment:
return beginFragment(current, workInProgress, renderPriority);
return beginFragment(current, workInProgress, nextProps, renderPriority);
default:
invariant(
false,
Expand Down
3 changes: 2 additions & 1 deletion src/renderers/shared/fiber/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var {getUpdatePriority} = require('ReactFiberUpdateQueue');
var {resetContext} = require('ReactFiberContext');

var invariant = require('fbjs/lib/invariant');
var emptyObject = require('fbjs/lib/emptyObject');

if (__DEV__) {
var warning = require('fbjs/lib/warning');
Expand Down Expand Up @@ -319,7 +320,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
return createWorkInProgress(
highestPriorityRoot.current,
highestPriorityLevel,
null,
emptyObject,
);
}

Expand Down

0 comments on commit ea7d604

Please sign in to comment.