Skip to content

Commit

Permalink
[Fiber] Add types for ReactFiber and ReactChildFiber (facebook#8072)
Browse files Browse the repository at this point in the history
* Add Types for ReactFiber

* Add Types for ReactChildFiber
  • Loading branch information
koba04 authored and gaearon committed Oct 24, 2016
1 parent 6fa1ddb commit 6cdc610
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
32 changes: 16 additions & 16 deletions src/renderers/shared/fiber/ReactChildFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
function deleteChild(
returnFiber : Fiber,
childToDelete : Fiber
) {
) : void {
if (!shouldTrackSideEffects) {
// Noop.
return;
Expand Down Expand Up @@ -102,7 +102,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
function deleteRemainingChildren(
returnFiber : Fiber,
currentFirstChild : ?Fiber
) {
) : null {
if (!shouldTrackSideEffects) {
// Noop.
return null;
Expand Down Expand Up @@ -139,7 +139,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
return existingChildren;
}

function useFiber(fiber : Fiber, priority : PriorityLevel) {
function useFiber(fiber : Fiber, priority : PriorityLevel) : Fiber {
// We currently set sibling to null and index to 0 here because it is easy
// to forget to do before returning it. E.g. for the single child case.
if (shouldClone) {
Expand All @@ -159,7 +159,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
}
}

function placeChild(newFiber : Fiber, lastPlacedIndex : number, newIndex : number) {
function placeChild(newFiber : Fiber, lastPlacedIndex : number, newIndex : number) : number {
newFiber.index = newIndex;
if (!shouldTrackSideEffects) {
// Noop.
Expand All @@ -183,7 +183,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
}
}

function placeSingleChild(newFiber : Fiber) {
function placeSingleChild(newFiber : Fiber) : Fiber {
// This is simpler for the single child case. We only need to do a
// placement for inserting new children.
if (shouldTrackSideEffects && !newFiber.alternate) {
Expand Down Expand Up @@ -217,7 +217,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
current : ?Fiber,
element : ReactElement<any>,
priority : PriorityLevel
) {
) : Fiber {
if (current == null || current.type !== element.type) {
// Insert
const created = createFiberFromElement(element, priority);
Expand All @@ -239,7 +239,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
current : ?Fiber,
coroutine : ReactCoroutine,
priority : PriorityLevel
) {
) : Fiber {
// TODO: Should this also compare handler to determine whether to reuse?
if (current == null || current.tag !== CoroutineComponent) {
// Insert
Expand All @@ -260,7 +260,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
current : ?Fiber,
yieldNode : ReactYield,
priority : PriorityLevel
) {
) : Fiber {
// TODO: Should this also compare continuation to determine whether to reuse?
if (current == null || current.tag !== YieldComponent) {
// Insert
Expand All @@ -286,7 +286,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
current : ?Fiber,
fragment : Iterable<*>,
priority : PriorityLevel
) {
) : Fiber {
if (current == null || current.tag !== Fragment) {
// Insert
const created = createFiberFromFragment(fragment, priority);
Expand Down Expand Up @@ -461,7 +461,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
returnFiber : Fiber,
currentFirstChild : ?Fiber,
newChildren : Array<*>,
priority : PriorityLevel) {
priority : PriorityLevel) : ?Fiber {

// This algorithm can't optimize by searching from boths ends since we
// don't have backpointers on fibers. I'm trying to see how far we can get
Expand Down Expand Up @@ -600,7 +600,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
returnFiber : Fiber,
currentFirstChild : ?Fiber,
newChildren : Iterator<*>,
priority : PriorityLevel) {
priority : PriorityLevel) : null {
// TODO: Copy everything from reconcileChildrenArray but use the iterator
// instead.
return null;
Expand All @@ -611,7 +611,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
currentFirstChild : ?Fiber,
textContent : string,
priority : PriorityLevel
) {
) : Fiber {
// There's no need to check for keys on text nodes since we don't have a
// way to define them.
if (currentFirstChild && currentFirstChild.tag === HostText) {
Expand All @@ -636,7 +636,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
currentFirstChild : ?Fiber,
element : ReactElement<any>,
priority : PriorityLevel
) {
) : Fiber {
const key = element.key;
let child = currentFirstChild;
while (child) {
Expand Down Expand Up @@ -671,7 +671,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
currentFirstChild : ?Fiber,
coroutine : ReactCoroutine,
priority : PriorityLevel
) {
) : Fiber {
const key = coroutine.key;
let child = currentFirstChild;
while (child) {
Expand Down Expand Up @@ -704,7 +704,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
currentFirstChild : ?Fiber,
yieldNode : ReactYield,
priority : PriorityLevel
) {
) : Fiber {
const key = yieldNode.key;
let child = currentFirstChild;
while (child) {
Expand Down Expand Up @@ -820,7 +820,7 @@ exports.reconcileChildFibersInPlace = ChildReconciler(false, true);

exports.mountChildFibersInPlace = ChildReconciler(false, false);

exports.cloneChildFibers = function(current : ?Fiber, workInProgress : Fiber) {
exports.cloneChildFibers = function(current : ?Fiber, workInProgress : Fiber) : void {
if (!workInProgress.child) {
return;
}
Expand Down
14 changes: 7 additions & 7 deletions src/renderers/shared/fiber/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,20 +259,20 @@ exports.cloneFiber = function(fiber : Fiber, priorityLevel : PriorityLevel) : Fi
return alt;
};

exports.createHostContainerFiber = function() {
exports.createHostContainerFiber = function() : Fiber {
const fiber = createFiber(HostContainer, null);
return fiber;
};

exports.createFiberFromElement = function(element : ReactElement<*>, priorityLevel : PriorityLevel) {
exports.createFiberFromElement = function(element : ReactElement<*>, priorityLevel : PriorityLevel) : Fiber {
// $FlowFixMe: ReactElement.key is currently defined as ?string but should be defined as null | string in Flow.
const fiber = createFiberFromElementType(element.type, element.key);
fiber.pendingProps = element.props;
fiber.pendingWorkPriority = priorityLevel;
return fiber;
};

exports.createFiberFromFragment = function(elements : ReactFragment, priorityLevel : PriorityLevel) {
exports.createFiberFromFragment = function(elements : ReactFragment, priorityLevel : PriorityLevel) : Fiber {
// TODO: Consider supporting keyed fragments. Technically, we accidentally
// support that in the existing React.
const fiber = createFiber(Fragment, null);
Expand All @@ -281,14 +281,14 @@ exports.createFiberFromFragment = function(elements : ReactFragment, priorityLev
return fiber;
};

exports.createFiberFromText = function(content : string, priorityLevel : PriorityLevel) {
exports.createFiberFromText = function(content : string, priorityLevel : PriorityLevel) : Fiber {
const fiber = createFiber(HostText, null);
fiber.pendingProps = content;
fiber.pendingWorkPriority = priorityLevel;
return fiber;
};

function createFiberFromElementType(type : mixed, key : null | string) {
function createFiberFromElementType(type : mixed, key : null | string) : Fiber {
let fiber;
if (typeof type === 'function') {
fiber = shouldConstruct(type) ?
Expand All @@ -314,15 +314,15 @@ function createFiberFromElementType(type : mixed, key : null | string) {

exports.createFiberFromElementType = createFiberFromElementType;

exports.createFiberFromCoroutine = function(coroutine : ReactCoroutine, priorityLevel : PriorityLevel) {
exports.createFiberFromCoroutine = function(coroutine : ReactCoroutine, priorityLevel : PriorityLevel) : Fiber {
const fiber = createFiber(CoroutineComponent, coroutine.key);
fiber.type = coroutine.handler;
fiber.pendingProps = coroutine;
fiber.pendingWorkPriority = priorityLevel;
return fiber;
};

exports.createFiberFromYield = function(yieldNode : ReactYield, priorityLevel : PriorityLevel) {
exports.createFiberFromYield = function(yieldNode : ReactYield, priorityLevel : PriorityLevel) : Fiber {
const fiber = createFiber(YieldComponent, yieldNode.key);
fiber.pendingProps = {};
return fiber;
Expand Down

0 comments on commit 6cdc610

Please sign in to comment.