Skip to content

Commit 23e1ac4

Browse files
create component actions record clean up
1 parent 8a83b97 commit 23e1ac4

File tree

1 file changed

+9
-35
lines changed

1 file changed

+9
-35
lines changed

src/backend/controllers/createComponentActionsRecord.ts

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
// import typescript types
2-
import {
3-
// object with tree structure
4-
Fiber,
5-
} from '../types/backendTypes';
1+
import { Fiber } from '../types/backendTypes';
62
import {
73
FunctionComponent,
84
ClassComponent,
9-
IndeterminateComponent, // Before we know whether it is function or class
5+
IndeterminateComponent,
106
ContextProvider,
117
} from '../types/backendTypes';
12-
// passes the data down to its components
138
import componentActionsRecord from '../models/masterState';
149
import { getHooksStateAndUpdateMethod } from './statePropExtractors';
1510
import {
@@ -20,14 +15,14 @@ import {
2015

2116
// ------------------------CREATE COMPONENT ACTIONS RECORD----------------------
2217
/**
23-
* This is a recursive function that runs after Fiber commit, if user navigating to a new route during jumping. This function performs the following logic:
18+
* This is a recursive function that runs after Fiber commit, if user is navigating to a new route during jumping. This function performs the following logic:
2419
* 1. Traverse from FiberRootNode
2520
* 2. If the component is stateful, extract its update methods & push to the `componentActionRecord` array
2621
* @param currentFiberNode A Fiber object
2722
*/
2823
export default function createComponentActionsRecord(currentFiberNode: Fiber): void {
2924
// ------------------OBTAIN DATA FROM THE CURRENT FIBER NODE----------------
30-
// Destructure the current fiber node:
25+
// Destructure the current fiber node
3126
const {
3227
sibling,
3328
stateNode,
@@ -46,28 +41,13 @@ export default function createComponentActionsRecord(currentFiberNode: Fiber): v
4641
elementType?.name ||
4742
'nameless';
4843

49-
// console.log('createComponentActionsRecord', {
50-
// currentFiberNode,
51-
// // tag,
52-
// // elementType,
53-
// componentName:
54-
// elementType?._context?.displayName || //For ContextProvider
55-
// elementType?._result?.name || //For lazy Component
56-
// elementType?.render?.name ||
57-
// elementType?.name ||
58-
// elementType,
59-
// // memoizedState,
60-
// // stateNode,
61-
// // _debugHookTypes,
62-
// });
63-
6444
// --------------------FILTER COMPONENTS/FIBER NODE-------------------------
6545
/**
6646
* For the snapshot tree,
67-
* 1. We will only interested in components that are one of these types: Function Component, Class Component, Indeterminate Component or Context Provider.
47+
* 1. We are only interested in components that are one of these types: Function Component, Class Component, Indeterminate Component or Context Provider.
6848
* NOTE: this list of components may change depending on future use
69-
* 2. If user use Next JS, filter out default NextJS components
70-
* 3. If user use Remix JS, filter out default Remix components
49+
* 2. If user is using Next JS, filter out default NextJS components
50+
* 3. If user is using Remix JS, filter out default Remix components
7151
*/
7252

7353
if (
@@ -90,20 +70,15 @@ export default function createComponentActionsRecord(currentFiberNode: Fiber): v
9070
// ---------OBTAIN STATE & SET STATE METHODS FROM CLASS COMPONENT-----------
9171
// Check if node is a stateful class component when user use setState.
9272
// If user use setState to define/manage state, the state object will be stored in stateNode.state => grab the state object stored in the stateNode.state
93-
// Example: for tic-tac-toe demo-app: Board is a stateful component that use setState to store state data.
9473
if ((tag === ClassComponent || tag === IndeterminateComponent) && stateNode?.state) {
9574
// Save component setState() method to our componentActionsRecord for use during timeJump
9675
componentActionsRecord.saveNew(stateNode);
9776
}
98-
9977
// --------OBTAIN STATE & DISPATCH METHODS FROM FUNCTIONAL COMPONENT--------
10078
// Check if node is a stateful class component when user use setState.
10179
// If user use useState to define/manage state, the state object will be stored in memoizedState.queue => grab the state object stored in the memoizedState.queue
10280
if (
103-
(tag === FunctionComponent ||
104-
tag === IndeterminateComponent ||
105-
//TODO: Need to figure out why we need context provider
106-
tag === ContextProvider) &&
81+
(tag === FunctionComponent || tag === IndeterminateComponent || tag === ContextProvider) &&
10782
memoizedState
10883
) {
10984
if (memoizedState.queue) {
@@ -114,7 +89,7 @@ export default function createComponentActionsRecord(currentFiberNode: Fiber): v
11489
// which includes the dispatch() function we use to change their state.
11590
const hooksStates = getHooksStateAndUpdateMethod(memoizedState);
11691
hooksStates.forEach(({ component }) => {
117-
// Save component's state and dispatch() function to our record for future time-travel state changing. Add record index to snapshot so we can retrieve.
92+
// Save component's state and dispatch() function to our record for future time-travel state changing. Add record index to snapshot so we can retrieve later
11893
componentActionsRecord.saveNew(component);
11994
});
12095
} catch (err) {
@@ -124,7 +99,6 @@ export default function createComponentActionsRecord(currentFiberNode: Fiber): v
12499
}
125100
}
126101
}
127-
128102
// ---------------------TRAVERSE TO NEXT FIBERNODE--------------------------
129103
// If currentFiberNode has children, recurse on children
130104
if (child) createComponentActionsRecord(child);

0 commit comments

Comments
 (0)