Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fiber] Host Container Fiber and Priority Levels #7034

Merged
merged 19 commits into from
Jun 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 27 additions & 3 deletions src/renderers/noop/ReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

'use strict';

import type { Fiber } from 'ReactFiber';

var ReactFiberReconciler = require('ReactFiberReconciler');

var scheduledHighPriCallback = null;
Expand All @@ -38,12 +40,16 @@ var NoopRenderer = ReactFiberReconciler({

});

var root = null;

var ReactNoop = {

render(element : ReactElement<any>) {

NoopRenderer.mountNewRoot(element);

if (!root) {
root = NoopRenderer.mountContainer(element, null);
} else {
NoopRenderer.updateContainer(element, root);
}
},

flushHighPri() {
Expand Down Expand Up @@ -79,6 +85,24 @@ var ReactNoop = {
ReactNoop.flushLowPri();
},

// Logs the current state of the tree.
dumpTree() {
if (!root) {
console.log('Nothing rendered yet.');
return;
}
function logFiber(fiber : Fiber, depth) {
console.log(' '.repeat(depth) + '- ' + (fiber.type ? fiber.type.name || fiber.type : '[root]'), '[' + fiber.pendingWorkPriority + (fiber.pendingProps ? '*' : '') + ']');
if (fiber.child) {
logFiber(fiber.child, depth + 1);
}
if (fiber.sibling) {
logFiber(fiber.sibling, depth);
}
}
logFiber((root.stateNode : any).current, 0);
},

};

module.exports = ReactNoop;
51 changes: 28 additions & 23 deletions src/renderers/shared/fiber/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import type { ReactCoroutine, ReactYield } from 'ReactCoroutine';
import type { Fiber } from 'ReactFiber';
import type { PriorityLevel } from 'ReactPriorityLevel';

import type { ReactNodeList } from 'ReactTypes';

Expand All @@ -28,7 +29,7 @@ var {
var ReactFiber = require('ReactFiber');
var ReactReifiedYield = require('ReactReifiedYield');

function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousSibling : Fiber, newChildren) : Fiber {
function createSubsequentChild(returnFiber : Fiber, existingChild : ?Fiber, previousSibling : Fiber, newChildren, priority : PriorityLevel) : Fiber {
if (typeof newChildren !== 'object' || newChildren === null) {
return previousSibling;
}
Expand All @@ -41,34 +42,35 @@ function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousS
element.key === existingChild.key) {
// TODO: This is not sufficient since previous siblings could be new.
// Will fix reconciliation properly later.
const clone = ReactFiber.cloneFiber(existingChild);
clone.input = element.props;
const clone = ReactFiber.cloneFiber(existingChild, priority);
clone.pendingProps = element.props;
clone.child = existingChild.child;
clone.sibling = null;
clone.return = returnFiber;
previousSibling.sibling = clone;
return clone;
}
const child = ReactFiber.createFiberFromElement(element);
const child = ReactFiber.createFiberFromElement(element, priority);
previousSibling.sibling = child;
child.parent = parent;
child.return = returnFiber;
return child;
}

case REACT_COROUTINE_TYPE: {
const coroutine = (newChildren : ReactCoroutine);
const child = ReactFiber.createFiberFromCoroutine(coroutine);
const child = ReactFiber.createFiberFromCoroutine(coroutine, priority);
previousSibling.sibling = child;
child.parent = parent;
child.return = returnFiber;
return child;
}

case REACT_YIELD_TYPE: {
const yieldNode = (newChildren : ReactYield);
const reifiedYield = ReactReifiedYield.createReifiedYield(yieldNode);
const child = ReactFiber.createFiberFromYield(yieldNode);
const child = ReactFiber.createFiberFromYield(yieldNode, priority);
child.output = reifiedYield;
previousSibling.sibling = child;
child.parent = parent;
child.return = returnFiber;
return child;
}
}
Expand All @@ -77,7 +79,7 @@ function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousS
let prev : Fiber = previousSibling;
let existing : ?Fiber = existingChild;
for (var i = 0; i < newChildren.length; i++) {
prev = createSubsequentChild(parent, existing, prev, newChildren[i]);
prev = createSubsequentChild(returnFiber, existing, prev, newChildren[i], priority);
if (prev && existing) {
// TODO: This is not correct because there could've been more
// than one sibling consumed but I don't want to return a tuple.
Expand All @@ -91,7 +93,7 @@ function createSubsequentChild(parent : Fiber, existingChild : ?Fiber, previousS
}
}

function createFirstChild(parent, existingChild, newChildren) {
function createFirstChild(returnFiber, existingChild, newChildren, priority) {
if (typeof newChildren !== 'object' || newChildren === null) {
return null;
}
Expand All @@ -103,21 +105,22 @@ function createFirstChild(parent, existingChild, newChildren) {
element.type === existingChild.type &&
element.key === existingChild.key) {
// Get the clone of the existing fiber.
const clone = ReactFiber.cloneFiber(existingChild);
clone.input = element.props;
const clone = ReactFiber.cloneFiber(existingChild, priority);
clone.pendingProps = element.props;
clone.child = existingChild.child;
clone.sibling = null;
clone.return = returnFiber;
return clone;
}
const child = ReactFiber.createFiberFromElement(element);
child.parent = parent;
const child = ReactFiber.createFiberFromElement(element, priority);
child.return = returnFiber;
return child;
}

case REACT_COROUTINE_TYPE: {
const coroutine = (newChildren : ReactCoroutine);
const child = ReactFiber.createFiberFromCoroutine(coroutine);
child.parent = parent;
const child = ReactFiber.createFiberFromCoroutine(coroutine, priority);
child.return = returnFiber;
return child;
}

Expand All @@ -127,9 +130,9 @@ function createFirstChild(parent, existingChild, newChildren) {
// the fragment.
const yieldNode = (newChildren : ReactYield);
const reifiedYield = ReactReifiedYield.createReifiedYield(yieldNode);
const child = ReactFiber.createFiberFromYield(yieldNode);
const child = ReactFiber.createFiberFromYield(yieldNode, priority);
child.output = reifiedYield;
child.parent = parent;
child.return = returnFiber;
return child;
}
}
Expand All @@ -140,10 +143,10 @@ function createFirstChild(parent, existingChild, newChildren) {
var existing : ?Fiber = existingChild;
for (var i = 0; i < newChildren.length; i++) {
if (prev == null) {
prev = createFirstChild(parent, existing, newChildren[i]);
prev = createFirstChild(returnFiber, existing, newChildren[i], priority);
first = prev;
} else {
prev = createSubsequentChild(parent, existing, prev, newChildren[i]);
prev = createSubsequentChild(returnFiber, existing, prev, newChildren[i], priority);
}
if (prev && existing) {
// TODO: This is not correct because there could've been more
Expand All @@ -158,6 +161,8 @@ function createFirstChild(parent, existingChild, newChildren) {
}
}

exports.reconcileChildFibers = function(parent : Fiber, currentFirstChild : ?Fiber, newChildren : ReactNodeList) : ?Fiber {
return createFirstChild(parent, currentFirstChild, newChildren);
// TODO: This API won't work because we'll need to transfer the side-effects of
// unmounting children to the returnFiber.
exports.reconcileChildFibers = function(returnFiber : Fiber, currentFirstChild : ?Fiber, newChildren : ReactNodeList, priority : PriorityLevel) : ?Fiber {
return createFirstChild(returnFiber, currentFirstChild, newChildren, priority);
};