From 6c32fea3ae42b6ca57f79bdda70dba2c7f23c23f Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 7 Apr 2017 22:42:05 +0100 Subject: [PATCH 01/15] made createFiber create a constructed FiberNode object --- src/renderers/shared/fiber/ReactFiber.js | 75 ++++++++++++------------ 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index faf8f95d3704..638b7bfaceb2 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -163,6 +163,41 @@ if (__DEV__) { var debugCounter = 1; } +function FiberNode(tag: TypeOfWork, key: null | string): Fiber { + // Instance + this.tag = tag; + this.key = key; + this.type = null; + this.stateNode = null; + + // Fiber + this.return = null; + this.child = null; + this.sibling = null; + this.index = 0; + + this.ref = null; + + this.pendingProps = null; + this.memoizedProps = null; + this.updateQueue = null; + this.memoizedState = null; + + // Effects + this.effectTag = NoEffect; + this.nextEffect = null; + this.firstEffect = null; + this.lastEffect = null; + + this.pendingWorkPriority = NoWork; + this.progressedPriority = NoWork; + this.progressedChild = null; + this.progressedFirstDeletion = null; + this.progressedLastDeletion = null; + + this.alternate = null; +} + // This is a constructor of a POJO instead of a constructor function for a few // reasons: // 1) Nobody should add any instance methods on this. Instance methods can be @@ -177,45 +212,7 @@ if (__DEV__) { // 5) It should be easy to port this to a C struct and keep a C implementation // compatible. var createFiber = function(tag: TypeOfWork, key: null | string): Fiber { - var fiber: Fiber = { - // Instance - - tag: tag, - - key: key, - - type: null, - - stateNode: null, - - // Fiber - - return: null, - - child: null, - sibling: null, - index: 0, - - ref: null, - - pendingProps: null, - memoizedProps: null, - updateQueue: null, - memoizedState: null, - - effectTag: NoEffect, - nextEffect: null, - firstEffect: null, - lastEffect: null, - - pendingWorkPriority: NoWork, - progressedPriority: NoWork, - progressedChild: null, - progressedFirstDeletion: null, - progressedLastDeletion: null, - - alternate: null, - }; + var fiber: Fiber = new FiberNode(tag, key); if (__DEV__) { fiber._debugID = debugCounter++; From 83830dab257c2a0fef9ae7682090770777b0f72b Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 7 Apr 2017 22:46:19 +0100 Subject: [PATCH 02/15] updated comment --- src/renderers/shared/fiber/ReactFiber.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 638b7bfaceb2..f2faf53c07d3 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -198,18 +198,16 @@ function FiberNode(tag: TypeOfWork, key: null | string): Fiber { this.alternate = null; } -// This is a constructor of a POJO instead of a constructor function for a few -// reasons: +// This is now a constructor function again, rather than a POJO constructor, still +// please ensure we do the following: // 1) Nobody should add any instance methods on this. Instance methods can be // more difficult to predict when they get optimized and they are almost // never inlined properly in static compilers. // 2) Nobody should rely on `instanceof Fiber` for type testing. We should // always know when it is a fiber. -// 3) We can easily go from a createFiber call to calling a constructor if that -// is faster. The opposite is not true. -// 4) We might want to experiment with using numeric keys since they are easier +// 3) We might want to experiment with using numeric keys since they are easier // to optimize in a non-JIT environment. -// 5) It should be easy to port this to a C struct and keep a C implementation +// 4) It should be easy to port this to a C struct and keep a C implementation // compatible. var createFiber = function(tag: TypeOfWork, key: null | string): Fiber { var fiber: Fiber = new FiberNode(tag, key); From f6fedc36b3d432ba58c40adeb35a374e444d478e Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 7 Apr 2017 23:18:19 +0100 Subject: [PATCH 03/15] satisfying flow and prettier --- src/renderers/shared/fiber/ReactFiber.js | 66 ++++++++++++------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index f2faf53c07d3..46c3ea9b37c9 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -163,39 +163,39 @@ if (__DEV__) { var debugCounter = 1; } -function FiberNode(tag: TypeOfWork, key: null | string): Fiber { - // Instance - this.tag = tag; - this.key = key; - this.type = null; - this.stateNode = null; - - // Fiber - this.return = null; - this.child = null; - this.sibling = null; - this.index = 0; - - this.ref = null; - - this.pendingProps = null; - this.memoizedProps = null; - this.updateQueue = null; - this.memoizedState = null; - - // Effects - this.effectTag = NoEffect; - this.nextEffect = null; - this.firstEffect = null; - this.lastEffect = null; - - this.pendingWorkPriority = NoWork; - this.progressedPriority = NoWork; - this.progressedChild = null; - this.progressedFirstDeletion = null; - this.progressedLastDeletion = null; - - this.alternate = null; +function FiberNode(tag: TypeOfWork, key: null | string) { + // Instance + this.tag = tag; + this.key = key; + this.type = null; + this.stateNode = null; + + // Fiber + this.return = null; + this.child = null; + this.sibling = null; + this.index = 0; + + this.ref = null; + + this.pendingProps = null; + this.memoizedProps = null; + this.updateQueue = null; + this.memoizedState = null; + + // Effects + this.effectTag = NoEffect; + this.nextEffect = null; + this.firstEffect = null; + this.lastEffect = null; + + this.pendingWorkPriority = NoWork; + this.progressedPriority = NoWork; + this.progressedChild = null; + this.progressedFirstDeletion = null; + this.progressedLastDeletion = null; + + this.alternate = null; } // This is now a constructor function again, rather than a POJO constructor, still From 180bf7641c9f32dbeec63f9ce13d17f346952aa1 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 7 Apr 2017 23:26:50 +0100 Subject: [PATCH 04/15] better comments :) --- src/renderers/shared/fiber/ReactFiber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 46c3ea9b37c9..985ddb005c12 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -198,7 +198,7 @@ function FiberNode(tag: TypeOfWork, key: null | string) { this.alternate = null; } -// This is now a constructor function again, rather than a POJO constructor, still +// This is a constructor function, rather than a POJO constructor, still // please ensure we do the following: // 1) Nobody should add any instance methods on this. Instance methods can be // more difficult to predict when they get optimized and they are almost From 220735717b1643976f06c32869a8a63b4d5f1993 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 10 Apr 2017 12:40:26 +0100 Subject: [PATCH 05/15] fixes flow error --- src/renderers/shared/fiber/ReactFiber.js | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 985ddb005c12..1163f54e336c 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -196,6 +196,16 @@ function FiberNode(tag: TypeOfWork, key: null | string) { this.progressedLastDeletion = null; this.alternate = null; + + if (__DEV__) { + this._debugID = debugCounter++; + this._debugSource = null; + this._debugOwner = null; + this._debugIsCurrentlyTiming = false; + if (typeof Object.preventExtensions === 'function') { + Object.preventExtensions(this); + } + } } // This is a constructor function, rather than a POJO constructor, still @@ -210,19 +220,7 @@ function FiberNode(tag: TypeOfWork, key: null | string) { // 4) It should be easy to port this to a C struct and keep a C implementation // compatible. var createFiber = function(tag: TypeOfWork, key: null | string): Fiber { - var fiber: Fiber = new FiberNode(tag, key); - - if (__DEV__) { - fiber._debugID = debugCounter++; - fiber._debugSource = null; - fiber._debugOwner = null; - fiber._debugIsCurrentlyTiming = false; - if (typeof Object.preventExtensions === 'function') { - Object.preventExtensions(fiber); - } - } - - return fiber; + return new FiberNode(tag, key); }; function shouldConstruct(Component) { From 61b3eb1004413a7cddd92bcf648ed74eb04a5f9b Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 10 Apr 2017 12:41:42 +0100 Subject: [PATCH 06/15] updates comment --- src/renderers/shared/fiber/ReactFiber.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 1163f54e336c..cae89bd68126 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -217,7 +217,9 @@ function FiberNode(tag: TypeOfWork, key: null | string) { // always know when it is a fiber. // 3) We might want to experiment with using numeric keys since they are easier // to optimize in a non-JIT environment. -// 4) It should be easy to port this to a C struct and keep a C implementation +// 4) We can easily go from a constructor to a createFiber object literal if that +// is faster. +// 5) It should be easy to port this to a C struct and keep a C implementation // compatible. var createFiber = function(tag: TypeOfWork, key: null | string): Fiber { return new FiberNode(tag, key); From c020982c5fe62446667f6f933c834366c3f009b3 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 10 Apr 2017 13:04:39 +0100 Subject: [PATCH 07/15] converted function constructor to a ES2015 class --- src/renderers/shared/fiber/ReactFiber.js | 147 +++++++++++------------ 1 file changed, 73 insertions(+), 74 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index cae89bd68126..dc77a7e91e91 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -55,12 +55,12 @@ if (__DEV__) { // A Fiber is work on a Component that needs to be done or was done. There can // be more than one per component. -export type Fiber = { +export class Fiber { // __DEV__ only - _debugID?: DebugID, - _debugSource?: Source | null, - _debugOwner?: Fiber | ReactInstance | null, // Stack compatible - _debugIsCurrentlyTiming?: boolean, + _debugID: DebugID; + _debugSource: Source | null; + _debugOwner: Fiber | ReactInstance | null; // Stack compatible + _debugIsCurrentlyTiming: boolean; // These first fields are conceptually members of an Instance. This used to // be split into a separate type and intersected with the other Fiber fields, @@ -73,16 +73,16 @@ export type Fiber = { // minimize the number of objects created during the initial render. // Tag identifying the type of fiber. - tag: TypeOfWork, + tag: TypeOfWork; // Unique identifier of this child. - key: null | string, + key: null | string; // The function/class/module associated with this fiber. - type: any, + type: any; // The local state associated with this fiber. - stateNode: any, + stateNode: any; // Conceptual aliases // parent : Instance -> return The parent happens to be the same as the @@ -94,120 +94,119 @@ export type Fiber = { // This is effectively the parent, but there can be multiple parents (two) // so this is only the parent of the thing we're currently processing. // It is conceptually the same as the return address of a stack frame. - return: Fiber | null, + return: Fiber | null; // Singly Linked List Tree Structure. - child: Fiber | null, - sibling: Fiber | null, - index: number, + child: Fiber | null; + sibling: Fiber | null; + index: number; // The ref last used to attach this node. // I'll avoid adding an owner field for prod and model that as functions. - ref: null | (((handle: mixed) => void) & {_stringRef: ?string}), + ref: null | (((handle: mixed) => void) & {_stringRef: ?string}); // Input is the data coming into process this fiber. Arguments. Props. - pendingProps: any, // This type will be more specific once we overload the tag. + pendingProps: any; // This type will be more specific once we overload the tag. // TODO: I think that there is a way to merge pendingProps and memoizedProps. - memoizedProps: any, // The props used to create the output. + memoizedProps: any; // The props used to create the output. // A queue of state updates and callbacks. - updateQueue: UpdateQueue | null, + updateQueue: UpdateQueue | null; // The state used to create the output - memoizedState: any, + memoizedState: any; // Effect - effectTag: TypeOfSideEffect, + effectTag: TypeOfSideEffect; // Singly linked list fast path to the next fiber with side-effects. - nextEffect: Fiber | null, + nextEffect: Fiber | null; // The first and last fiber with side-effect within this subtree. This allows // us to reuse a slice of the linked list when we reuse the work done within // this fiber. - firstEffect: Fiber | null, - lastEffect: Fiber | null, + firstEffect: Fiber | null; + lastEffect: Fiber | null; // This will be used to quickly determine if a subtree has no pending changes. - pendingWorkPriority: PriorityLevel, + pendingWorkPriority: PriorityLevel; // This value represents the priority level that was last used to process this // component. This indicates whether it is better to continue from the // progressed work or if it is better to continue from the current state. - progressedPriority: PriorityLevel, + progressedPriority: PriorityLevel; // If work bails out on a Fiber that already had some work started at a lower // priority, then we need to store the progressed work somewhere. This holds // the started child set until we need to get back to working on it. It may // or may not be the same as the "current" child. - progressedChild: Fiber | null, + progressedChild: Fiber | null; // When we reconcile children onto progressedChild it is possible that we have // to delete some child fibers. We need to keep track of this side-effects so // that if we continue later on, we have to include those effects. Deletions // are added in the reverse order from sibling pointers. - progressedFirstDeletion: Fiber | null, - progressedLastDeletion: Fiber | null, + progressedFirstDeletion: Fiber | null; + progressedLastDeletion: Fiber | null; // This is a pooled version of a Fiber. Every fiber that gets updated will // eventually have a pair. There are cases when we can clean up pairs to save // memory if we need to. - alternate: Fiber | null, + alternate: Fiber | null; // Conceptual aliases // workInProgress : Fiber -> alternate The alternate used for reuse happens // to be the same as work in progress. + constructor(tag: TypeOfWork, key: null | string) { + // Instance + this.tag = tag; + this.key = key; + this.type = null; + this.stateNode = null; + + // Fiber + this.return = null; + this.child = null; + this.sibling = null; + this.index = 0; + + this.ref = null; + + this.pendingProps = null; + this.memoizedProps = null; + this.updateQueue = null; + this.memoizedState = null; + + // Effects + this.effectTag = NoEffect; + this.nextEffect = null; + this.firstEffect = null; + this.lastEffect = null; + + this.pendingWorkPriority = NoWork; + this.progressedPriority = NoWork; + this.progressedChild = null; + this.progressedFirstDeletion = null; + this.progressedLastDeletion = null; + + this.alternate = null; + + if (__DEV__) { + this._debugID = debugCounter++; + this._debugSource = null; + this._debugOwner = null; + this._debugIsCurrentlyTiming = false; + if (typeof Object.preventExtensions === 'function') { + Object.preventExtensions(this); + } + } + } }; if (__DEV__) { var debugCounter = 1; } -function FiberNode(tag: TypeOfWork, key: null | string) { - // Instance - this.tag = tag; - this.key = key; - this.type = null; - this.stateNode = null; - - // Fiber - this.return = null; - this.child = null; - this.sibling = null; - this.index = 0; - - this.ref = null; - - this.pendingProps = null; - this.memoizedProps = null; - this.updateQueue = null; - this.memoizedState = null; - - // Effects - this.effectTag = NoEffect; - this.nextEffect = null; - this.firstEffect = null; - this.lastEffect = null; - - this.pendingWorkPriority = NoWork; - this.progressedPriority = NoWork; - this.progressedChild = null; - this.progressedFirstDeletion = null; - this.progressedLastDeletion = null; - - this.alternate = null; - - if (__DEV__) { - this._debugID = debugCounter++; - this._debugSource = null; - this._debugOwner = null; - this._debugIsCurrentlyTiming = false; - if (typeof Object.preventExtensions === 'function') { - Object.preventExtensions(this); - } - } -} - // This is a constructor function, rather than a POJO constructor, still // please ensure we do the following: // 1) Nobody should add any instance methods on this. Instance methods can be @@ -222,7 +221,7 @@ function FiberNode(tag: TypeOfWork, key: null | string) { // 5) It should be easy to port this to a C struct and keep a C implementation // compatible. var createFiber = function(tag: TypeOfWork, key: null | string): Fiber { - return new FiberNode(tag, key); + return new Fiber(tag, key); }; function shouldConstruct(Component) { From 395d750f47528ea2f430db9e4a70a81efc55a294 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Mon, 10 Apr 2017 13:36:58 +0100 Subject: [PATCH 08/15] Revert "converted function constructor to a ES2015 class" This reverts commit c020982c5fe62446667f6f933c834366c3f009b3. --- src/renderers/shared/fiber/ReactFiber.js | 147 ++++++++++++----------- 1 file changed, 74 insertions(+), 73 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index dc77a7e91e91..cae89bd68126 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -55,12 +55,12 @@ if (__DEV__) { // A Fiber is work on a Component that needs to be done or was done. There can // be more than one per component. -export class Fiber { +export type Fiber = { // __DEV__ only - _debugID: DebugID; - _debugSource: Source | null; - _debugOwner: Fiber | ReactInstance | null; // Stack compatible - _debugIsCurrentlyTiming: boolean; + _debugID?: DebugID, + _debugSource?: Source | null, + _debugOwner?: Fiber | ReactInstance | null, // Stack compatible + _debugIsCurrentlyTiming?: boolean, // These first fields are conceptually members of an Instance. This used to // be split into a separate type and intersected with the other Fiber fields, @@ -73,16 +73,16 @@ export class Fiber { // minimize the number of objects created during the initial render. // Tag identifying the type of fiber. - tag: TypeOfWork; + tag: TypeOfWork, // Unique identifier of this child. - key: null | string; + key: null | string, // The function/class/module associated with this fiber. - type: any; + type: any, // The local state associated with this fiber. - stateNode: any; + stateNode: any, // Conceptual aliases // parent : Instance -> return The parent happens to be the same as the @@ -94,119 +94,120 @@ export class Fiber { // This is effectively the parent, but there can be multiple parents (two) // so this is only the parent of the thing we're currently processing. // It is conceptually the same as the return address of a stack frame. - return: Fiber | null; + return: Fiber | null, // Singly Linked List Tree Structure. - child: Fiber | null; - sibling: Fiber | null; - index: number; + child: Fiber | null, + sibling: Fiber | null, + index: number, // The ref last used to attach this node. // I'll avoid adding an owner field for prod and model that as functions. - ref: null | (((handle: mixed) => void) & {_stringRef: ?string}); + ref: null | (((handle: mixed) => void) & {_stringRef: ?string}), // Input is the data coming into process this fiber. Arguments. Props. - pendingProps: any; // This type will be more specific once we overload the tag. + pendingProps: any, // This type will be more specific once we overload the tag. // TODO: I think that there is a way to merge pendingProps and memoizedProps. - memoizedProps: any; // The props used to create the output. + memoizedProps: any, // The props used to create the output. // A queue of state updates and callbacks. - updateQueue: UpdateQueue | null; + updateQueue: UpdateQueue | null, // The state used to create the output - memoizedState: any; + memoizedState: any, // Effect - effectTag: TypeOfSideEffect; + effectTag: TypeOfSideEffect, // Singly linked list fast path to the next fiber with side-effects. - nextEffect: Fiber | null; + nextEffect: Fiber | null, // The first and last fiber with side-effect within this subtree. This allows // us to reuse a slice of the linked list when we reuse the work done within // this fiber. - firstEffect: Fiber | null; - lastEffect: Fiber | null; + firstEffect: Fiber | null, + lastEffect: Fiber | null, // This will be used to quickly determine if a subtree has no pending changes. - pendingWorkPriority: PriorityLevel; + pendingWorkPriority: PriorityLevel, // This value represents the priority level that was last used to process this // component. This indicates whether it is better to continue from the // progressed work or if it is better to continue from the current state. - progressedPriority: PriorityLevel; + progressedPriority: PriorityLevel, // If work bails out on a Fiber that already had some work started at a lower // priority, then we need to store the progressed work somewhere. This holds // the started child set until we need to get back to working on it. It may // or may not be the same as the "current" child. - progressedChild: Fiber | null; + progressedChild: Fiber | null, // When we reconcile children onto progressedChild it is possible that we have // to delete some child fibers. We need to keep track of this side-effects so // that if we continue later on, we have to include those effects. Deletions // are added in the reverse order from sibling pointers. - progressedFirstDeletion: Fiber | null; - progressedLastDeletion: Fiber | null; + progressedFirstDeletion: Fiber | null, + progressedLastDeletion: Fiber | null, // This is a pooled version of a Fiber. Every fiber that gets updated will // eventually have a pair. There are cases when we can clean up pairs to save // memory if we need to. - alternate: Fiber | null; + alternate: Fiber | null, // Conceptual aliases // workInProgress : Fiber -> alternate The alternate used for reuse happens // to be the same as work in progress. - constructor(tag: TypeOfWork, key: null | string) { - // Instance - this.tag = tag; - this.key = key; - this.type = null; - this.stateNode = null; - - // Fiber - this.return = null; - this.child = null; - this.sibling = null; - this.index = 0; - - this.ref = null; - - this.pendingProps = null; - this.memoizedProps = null; - this.updateQueue = null; - this.memoizedState = null; - - // Effects - this.effectTag = NoEffect; - this.nextEffect = null; - this.firstEffect = null; - this.lastEffect = null; - - this.pendingWorkPriority = NoWork; - this.progressedPriority = NoWork; - this.progressedChild = null; - this.progressedFirstDeletion = null; - this.progressedLastDeletion = null; - - this.alternate = null; - - if (__DEV__) { - this._debugID = debugCounter++; - this._debugSource = null; - this._debugOwner = null; - this._debugIsCurrentlyTiming = false; - if (typeof Object.preventExtensions === 'function') { - Object.preventExtensions(this); - } - } - } }; if (__DEV__) { var debugCounter = 1; } +function FiberNode(tag: TypeOfWork, key: null | string) { + // Instance + this.tag = tag; + this.key = key; + this.type = null; + this.stateNode = null; + + // Fiber + this.return = null; + this.child = null; + this.sibling = null; + this.index = 0; + + this.ref = null; + + this.pendingProps = null; + this.memoizedProps = null; + this.updateQueue = null; + this.memoizedState = null; + + // Effects + this.effectTag = NoEffect; + this.nextEffect = null; + this.firstEffect = null; + this.lastEffect = null; + + this.pendingWorkPriority = NoWork; + this.progressedPriority = NoWork; + this.progressedChild = null; + this.progressedFirstDeletion = null; + this.progressedLastDeletion = null; + + this.alternate = null; + + if (__DEV__) { + this._debugID = debugCounter++; + this._debugSource = null; + this._debugOwner = null; + this._debugIsCurrentlyTiming = false; + if (typeof Object.preventExtensions === 'function') { + Object.preventExtensions(this); + } + } +} + // This is a constructor function, rather than a POJO constructor, still // please ensure we do the following: // 1) Nobody should add any instance methods on this. Instance methods can be @@ -221,7 +222,7 @@ if (__DEV__) { // 5) It should be easy to port this to a C struct and keep a C implementation // compatible. var createFiber = function(tag: TypeOfWork, key: null | string): Fiber { - return new Fiber(tag, key); + return new FiberNode(tag, key); }; function shouldConstruct(Component) { From d742a253cd928abd5d1706d4e6b702c373b7bdeb Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 26 May 2017 22:31:22 +0100 Subject: [PATCH 09/15] fixed some merge conflict issues --- src/renderers/shared/fiber/ReactFiber.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index b511b5ff4936..ce163f3eea3c 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -50,7 +50,6 @@ var invariant = require('fbjs/lib/invariant'); if (__DEV__) { var getComponentName = require('getComponentName'); - var hasBadMapPolyfill = false; try { const nonExtensibleObject = Object.preventExtensions({}); @@ -205,7 +204,7 @@ function FiberNode( this.memoizedProps = null; this.updateQueue = null; this.memoizedState = null; - + this.internalContextTag = internalContextTag; // Effects @@ -227,7 +226,7 @@ function FiberNode( this._debugSource = null; this._debugOwner = null; this._debugIsCurrentlyTiming = false; - if (typeof Object.preventExtensions === 'function') { + if (!hasBadMapPolyfill && typeof Object.preventExtensions === 'function') { Object.preventExtensions(this); } } @@ -246,8 +245,12 @@ function FiberNode( // is faster. // 5) It should be easy to port this to a C struct and keep a C implementation // compatible. -var createFiber = function(tag: TypeOfWork, key: null | string): Fiber { - return new FiberNode(tag, key); +var createFiber = function( + tag: TypeOfWork, + key: null | string, + internalContextTag: TypeOfInternalContext, +): Fiber { + return new FiberNode(tag, key, internalContextTag); }; function shouldConstruct(Component) { From 45e6375e9b0838566c891c017163b29e4f449fe9 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 26 May 2017 22:50:58 +0100 Subject: [PATCH 10/15] Flow.... --- src/renderers/shared/fiber/ReactFiber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index ce163f3eea3c..2331ecae9cf9 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -185,7 +185,7 @@ function FiberNode( tag: TypeOfWork, key: null | string, internalContextTag: TypeOfInternalContext, -): Fiber { +) { // Instance this.tag = tag; this.key = key; From 332139ec377746a25533119722c4bcbdb8544f98 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 9 Aug 2017 22:57:56 +0100 Subject: [PATCH 11/15] removed exact types to make flow pass --- src/renderers/shared/fiber/ReactFiber.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 5d226c10e539..5f5beaf04baa 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -63,13 +63,7 @@ if (__DEV__) { // A Fiber is work on a Component that needs to be done or was done. There can // be more than one per component. -export type Fiber = {| - // __DEV__ only - _debugID?: DebugID, - _debugSource?: Source | null, - _debugOwner?: Fiber | ReactInstance | null, // Stack compatible - _debugIsCurrentlyTiming?: boolean, - +export type Fiber = { // These first fields are conceptually members of an Instance. This used to // be split into a separate type and intersected with the other Fiber fields, // but until Flow fixes its intersection bugs, we've merged them into a @@ -154,7 +148,12 @@ export type Fiber = {| // Conceptual aliases // workInProgress : Fiber -> alternate The alternate used for reuse happens // to be the same as work in progress. -|}; + // __DEV__ only + _debugID?: DebugID, + _debugSource?: Source | null, + _debugOwner?: Fiber | ReactInstance | null, // Stack compatible + _debugIsCurrentlyTiming?: boolean, +}; if (__DEV__) { var debugCounter = 1; @@ -189,6 +188,7 @@ function FiberNode( // Effects this.effectTag = NoEffect; this.nextEffect = null; + this.firstEffect = null; this.lastEffect = null; From e6c208b82e57add1587cdc5de99a78df37c9a85c Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 9 Aug 2017 23:01:53 +0100 Subject: [PATCH 12/15] opted for $FlowFixMe instead --- src/renderers/shared/fiber/ReactFiber.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 5f5beaf04baa..930daa862fb2 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -63,7 +63,7 @@ if (__DEV__) { // A Fiber is work on a Component that needs to be done or was done. There can // be more than one per component. -export type Fiber = { +export type Fiber = {| // These first fields are conceptually members of an Instance. This used to // be split into a separate type and intersected with the other Fiber fields, // but until Flow fixes its intersection bugs, we've merged them into a @@ -153,7 +153,7 @@ export type Fiber = { _debugSource?: Source | null, _debugOwner?: Fiber | ReactInstance | null, // Stack compatible _debugIsCurrentlyTiming?: boolean, -}; +|}; if (__DEV__) { var debugCounter = 1; @@ -225,6 +225,7 @@ var createFiber = function( key: null | string, internalContextTag: TypeOfInternalContext, ): Fiber { + // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors return new FiberNode(tag, key, internalContextTag); }; From 1ca665bf8c9f5a0569733d62a843bcfcda0e4d2e Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 9 Aug 2017 22:57:56 +0100 Subject: [PATCH 13/15] removed exact types to make flow pass --- src/renderers/shared/fiber/ReactFiber.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 5d226c10e539..5f5beaf04baa 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -63,13 +63,7 @@ if (__DEV__) { // A Fiber is work on a Component that needs to be done or was done. There can // be more than one per component. -export type Fiber = {| - // __DEV__ only - _debugID?: DebugID, - _debugSource?: Source | null, - _debugOwner?: Fiber | ReactInstance | null, // Stack compatible - _debugIsCurrentlyTiming?: boolean, - +export type Fiber = { // These first fields are conceptually members of an Instance. This used to // be split into a separate type and intersected with the other Fiber fields, // but until Flow fixes its intersection bugs, we've merged them into a @@ -154,7 +148,12 @@ export type Fiber = {| // Conceptual aliases // workInProgress : Fiber -> alternate The alternate used for reuse happens // to be the same as work in progress. -|}; + // __DEV__ only + _debugID?: DebugID, + _debugSource?: Source | null, + _debugOwner?: Fiber | ReactInstance | null, // Stack compatible + _debugIsCurrentlyTiming?: boolean, +}; if (__DEV__) { var debugCounter = 1; @@ -189,6 +188,7 @@ function FiberNode( // Effects this.effectTag = NoEffect; this.nextEffect = null; + this.firstEffect = null; this.lastEffect = null; From 4d9b22d00d3f7d768fc5dce1d021a804fb02e44e Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 9 Aug 2017 23:01:53 +0100 Subject: [PATCH 14/15] opted for $FlowFixMe instead --- src/renderers/shared/fiber/ReactFiber.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 5f5beaf04baa..930daa862fb2 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -63,7 +63,7 @@ if (__DEV__) { // A Fiber is work on a Component that needs to be done or was done. There can // be more than one per component. -export type Fiber = { +export type Fiber = {| // These first fields are conceptually members of an Instance. This used to // be split into a separate type and intersected with the other Fiber fields, // but until Flow fixes its intersection bugs, we've merged them into a @@ -153,7 +153,7 @@ export type Fiber = { _debugSource?: Source | null, _debugOwner?: Fiber | ReactInstance | null, // Stack compatible _debugIsCurrentlyTiming?: boolean, -}; +|}; if (__DEV__) { var debugCounter = 1; @@ -225,6 +225,7 @@ var createFiber = function( key: null | string, internalContextTag: TypeOfInternalContext, ): Fiber { + // $FlowFixMe: the shapes are exact here but Flow doesn't like constructors return new FiberNode(tag, key, internalContextTag); }; From 1a35a20c1c11f0bd657cd83f9b219984391f05e8 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Wed, 9 Aug 2017 23:14:44 +0100 Subject: [PATCH 15/15] run prettier --- src/renderers/shared/fiber/ReactFiber.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderers/shared/fiber/ReactFiber.js b/src/renderers/shared/fiber/ReactFiber.js index 930daa862fb2..2a07cf2dc636 100644 --- a/src/renderers/shared/fiber/ReactFiber.js +++ b/src/renderers/shared/fiber/ReactFiber.js @@ -152,7 +152,7 @@ export type Fiber = {| _debugID?: DebugID, _debugSource?: Source | null, _debugOwner?: Fiber | ReactInstance | null, // Stack compatible - _debugIsCurrentlyTiming?: boolean, + _debugIsCurrentlyTiming?: boolean, |}; if (__DEV__) {