@samitouri / QOS-React / commits / 6cdc610bcc

[Fiber] Add types for ReactFiber and ReactChildFiber (#8072)

* Add Types for ReactFiber * Add Types for ReactChildFiber

Toru Kobayashi committed Oct 24, 2016 at 22:20 UTC 6cdc610bccfeaa6bb575be72528c6e31280dab94
2 files changed +23 -23
src/renderers/shared/fiber/ReactChildFiber.js
+16 -16
@@ -71,7 +71,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
71 function deleteChild(
72 returnFiber : Fiber,
73 childToDelete : Fiber
74 - ) {
74 + ) : void {
75 if (!shouldTrackSideEffects) {
76 // Noop.
77 return;
@@ -102,7 +102,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
102 function deleteRemainingChildren(
103 returnFiber : Fiber,
104 currentFirstChild : ?Fiber
105 - ) {
105 + ) : null {
106 if (!shouldTrackSideEffects) {
107 // Noop.
108 return null;
@@ -139,7 +139,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
139 return existingChildren;
140 }
141
142 - function useFiber(fiber : Fiber, priority : PriorityLevel) {
142 + function useFiber(fiber : Fiber, priority : PriorityLevel) : Fiber {
143 // We currently set sibling to null and index to 0 here because it is easy
144 // to forget to do before returning it. E.g. for the single child case.
145 if (shouldClone) {
@@ -159,7 +159,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
159 }
160 }
161
162 - function placeChild(newFiber : Fiber, lastPlacedIndex : number, newIndex : number) {
162 + function placeChild(newFiber : Fiber, lastPlacedIndex : number, newIndex : number) : number {
163 newFiber.index = newIndex;
164 if (!shouldTrackSideEffects) {
165 // Noop.
@@ -183,7 +183,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
183 }
184 }
185
186 - function placeSingleChild(newFiber : Fiber) {
186 + function placeSingleChild(newFiber : Fiber) : Fiber {
187 // This is simpler for the single child case. We only need to do a
188 // placement for inserting new children.
189 if (shouldTrackSideEffects && !newFiber.alternate) {
@@ -217,7 +217,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
217 current : ?Fiber,
218 element : ReactElement<any>,
219 priority : PriorityLevel
220 - ) {
220 + ) : Fiber {
221 if (current == null || current.type !== element.type) {
222 // Insert
223 const created = createFiberFromElement(element, priority);
@@ -239,7 +239,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
239 current : ?Fiber,
240 coroutine : ReactCoroutine,
241 priority : PriorityLevel
242 - ) {
242 + ) : Fiber {
243 // TODO: Should this also compare handler to determine whether to reuse?
244 if (current == null || current.tag !== CoroutineComponent) {
245 // Insert
@@ -260,7 +260,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
260 current : ?Fiber,
261 yieldNode : ReactYield,
262 priority : PriorityLevel
263 - ) {
263 + ) : Fiber {
264 // TODO: Should this also compare continuation to determine whether to reuse?
265 if (current == null || current.tag !== YieldComponent) {
266 // Insert
@@ -286,7 +286,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
286 current : ?Fiber,
287 fragment : Iterable<*>,
288 priority : PriorityLevel
289 - ) {
289 + ) : Fiber {
290 if (current == null || current.tag !== Fragment) {
291 // Insert
292 const created = createFiberFromFragment(fragment, priority);
@@ -461,7 +461,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
461 returnFiber : Fiber,
462 currentFirstChild : ?Fiber,
463 newChildren : Array<*>,
464 - priority : PriorityLevel) {
464 + priority : PriorityLevel) : ?Fiber {
465
466 // This algorithm can't optimize by searching from boths ends since we
467 // don't have backpointers on fibers. I'm trying to see how far we can get
@@ -600,7 +600,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
600 returnFiber : Fiber,
601 currentFirstChild : ?Fiber,
602 newChildren : Iterator<*>,
603 - priority : PriorityLevel) {
603 + priority : PriorityLevel) : null {
604 // TODO: Copy everything from reconcileChildrenArray but use the iterator
605 // instead.
606 return null;
@@ -611,7 +611,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
611 currentFirstChild : ?Fiber,
612 textContent : string,
613 priority : PriorityLevel
614 - ) {
614 + ) : Fiber {
615 // There's no need to check for keys on text nodes since we don't have a
616 // way to define them.
617 if (currentFirstChild && currentFirstChild.tag === HostText) {
@@ -636,7 +636,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
636 currentFirstChild : ?Fiber,
637 element : ReactElement<any>,
638 priority : PriorityLevel
639 - ) {
639 + ) : Fiber {
640 const key = element.key;
641 let child = currentFirstChild;
642 while (child) {
@@ -671,7 +671,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
671 currentFirstChild : ?Fiber,
672 coroutine : ReactCoroutine,
673 priority : PriorityLevel
674 - ) {
674 + ) : Fiber {
675 const key = coroutine.key;
676 let child = currentFirstChild;
677 while (child) {
@@ -704,7 +704,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
704 currentFirstChild : ?Fiber,
705 yieldNode : ReactYield,
706 priority : PriorityLevel
707 - ) {
707 + ) : Fiber {
708 const key = yieldNode.key;
709 let child = currentFirstChild;
710 while (child) {
@@ -820,7 +820,7 @@ exports.reconcileChildFibersInPlace = ChildReconciler(false, true);
820
821 exports.mountChildFibersInPlace = ChildReconciler(false, false);
822
823 -exports.cloneChildFibers = function(current : ?Fiber, workInProgress : Fiber) {
823 +exports.cloneChildFibers = function(current : ?Fiber, workInProgress : Fiber) : void {
824 if (!workInProgress.child) {
825 return;
826 }
src/renderers/shared/fiber/ReactFiber.js
+7 -7
@@ -259,12 +259,12 @@ exports.cloneFiber = function(fiber : Fiber, priorityLevel : PriorityLevel) : Fi
259 return alt;
260 };
261
262 -exports.createHostContainerFiber = function() {
262 +exports.createHostContainerFiber = function() : Fiber {
263 const fiber = createFiber(HostContainer, null);
264 return fiber;
265 };
266
267 -exports.createFiberFromElement = function(element : ReactElement<*>, priorityLevel : PriorityLevel) {
267 +exports.createFiberFromElement = function(element : ReactElement<*>, priorityLevel : PriorityLevel) : Fiber {
268 // $FlowFixMe: ReactElement.key is currently defined as ?string but should be defined as null | string in Flow.
269 const fiber = createFiberFromElementType(element.type, element.key);
270 fiber.pendingProps = element.props;
@@ -272,7 +272,7 @@ exports.createFiberFromElement = function(element : ReactElement<*>, priorityLev
272 return fiber;
273 };
274
275 -exports.createFiberFromFragment = function(elements : ReactFragment, priorityLevel : PriorityLevel) {
275 +exports.createFiberFromFragment = function(elements : ReactFragment, priorityLevel : PriorityLevel) : Fiber {
276 // TODO: Consider supporting keyed fragments. Technically, we accidentally
277 // support that in the existing React.
278 const fiber = createFiber(Fragment, null);
@@ -281,14 +281,14 @@ exports.createFiberFromFragment = function(elements : ReactFragment, priorityLev
281 return fiber;
282 };
283
284 -exports.createFiberFromText = function(content : string, priorityLevel : PriorityLevel) {
284 +exports.createFiberFromText = function(content : string, priorityLevel : PriorityLevel) : Fiber {
285 const fiber = createFiber(HostText, null);
286 fiber.pendingProps = content;
287 fiber.pendingWorkPriority = priorityLevel;
288 return fiber;
289 };
290
291 -function createFiberFromElementType(type : mixed, key : null | string) {
291 +function createFiberFromElementType(type : mixed, key : null | string) : Fiber {
292 let fiber;
293 if (typeof type === 'function') {
294 fiber = shouldConstruct(type) ?
@@ -314,7 +314,7 @@ function createFiberFromElementType(type : mixed, key : null | string) {
314
315 exports.createFiberFromElementType = createFiberFromElementType;
316
317 -exports.createFiberFromCoroutine = function(coroutine : ReactCoroutine, priorityLevel : PriorityLevel) {
317 +exports.createFiberFromCoroutine = function(coroutine : ReactCoroutine, priorityLevel : PriorityLevel) : Fiber {
318 const fiber = createFiber(CoroutineComponent, coroutine.key);
319 fiber.type = coroutine.handler;
320 fiber.pendingProps = coroutine;
@@ -322,7 +322,7 @@ exports.createFiberFromCoroutine = function(coroutine : ReactCoroutine, priority
322 return fiber;
323 };
324
325 -exports.createFiberFromYield = function(yieldNode : ReactYield, priorityLevel : PriorityLevel) {
325 +exports.createFiberFromYield = function(yieldNode : ReactYield, priorityLevel : PriorityLevel) : Fiber {
326 const fiber = createFiber(YieldComponent, yieldNode.key);
327 fiber.pendingProps = {};
328 return fiber;