Skip to content

Commit d25ae85

Browse files
committed
Added documentation for timeJump & index file
1 parent 7cd4927 commit d25ae85

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

src/app/components/StateRoute/ComponentMap/ComponentMap.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ export default function ComponentMap({
353353
</div>
354354

355355
<div className='tooltipWrapper'>
356-
<h2>Context:</h2>
356+
<h2>Initial Context:</h2>
357357
{formatData(tooltipData.componentData.context, 'context')}
358358
</div>
359359

src/backend/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const timeJump = timeJumpStart(mode);
3333
window.addEventListener('message', ({ data: { action, payload } }: MsgData) => {
3434
switch (action) {
3535
case 'jumpToSnap':
36+
console.log('Index ts', { payload });
3637
timeJump(payload, true); // * This sets state with given payload
3738
break;
3839

src/backend/linkFiber.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,6 @@ function traverseHooks(memoizedState: any): HookStates {
154154
return hooksStates;
155155
}
156156

157-
/**
158-
* @function createTree
159-
* @param currentFiber A Fiber object
160-
* @param tree A Tree object, default initialized to an instance given 'root' and 'root'
161-
* @param fromSibling A boolean, default initialized to false
162-
* @return An instance of a Tree object
163-
* This is a recursive function that runs after every Fiber commit using the following logic:
164-
* 1. Traverse from FiberRootNode
165-
* 2. Create an instance of custom Tree class
166-
* 3. Build a new state snapshot
167-
*/
168157
// This runs after every Fiber commit. It creates a new snapshot
169158
const exclude = new Set([
170159
'alternate',
@@ -323,12 +312,16 @@ function trimContextData(memoizedState, componentName, _debugHookTypes: string[]
323312
}
324313
// -------------------------CREATE TREE TO SEND TO FRONT END--------------------
325314
/**
315+
* This is a recursive function that runs after every Fiber commit using the following logic:
316+
* 1. Traverse from FiberRootNode
317+
* 2. Create an instance of custom Tree class
318+
* 3. Build a new state snapshot
326319
* Every time a state change is made in the accompanying app, the extension creates a Tree “snapshot” of the current state, and adds it to the current “cache” of snapshots in the extension
327-
*
328-
* @param currentFiber
329-
* @param tree
330-
* @param fromSibling
331-
* @returns
320+
* @function createTree
321+
* @param currentFiber A Fiber object
322+
* @param tree A Tree object, default initialized to an instance given 'root' and 'root'
323+
* @param fromSibling A boolean, default initialized to false
324+
* @return An instance of a Tree object
332325
*/
333326
function createTree(
334327
currentFiber: Fiber,
@@ -426,10 +419,19 @@ function createTree(
426419
}
427420

428421
// ------------APPEND STATE & CONTEXT DATA FROM REACT DEV TOOL----------------
422+
// stateNode
423+
// 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
424+
// Example: for tic-tac-toe demo-app: Board is a stateful component that use setState to store state data.
429425
if (stateNode?.state) {
430426
Object.assign(componentData.state, stateNode.state);
431427
}
432-
if ((tag === FunctionComponent || tag === ClassComponent) && memoizedState?.memoizedState) {
428+
429+
// memoizedState
430+
// Note: if user use ReactHook, memoizedState.memoizedState can be a falsy value such as null, false, ... => need to specify this data is not undefined
431+
if (
432+
(tag === FunctionComponent || tag === ClassComponent) &&
433+
memoizedState?.memoizedState !== undefined
434+
) {
433435
// If user uses Redux, context data will be stored in memoizedState of the Provider component => grab context object stored in the memoizedState
434436
if (elementType.name === 'Provider') {
435437
Object.assign(
@@ -463,10 +465,10 @@ function createTree(
463465
// componentData.context = convertDataToString(dependencies.firstContext.memoizedValue);
464466
// }
465467

468+
// ----------------------SET UP FOR JUMPING CONDITION-------------------------
466469
// Check if node is a stateful class component
467470
if (
468-
stateNode &&
469-
stateNode.state &&
471+
stateNode?.state &&
470472
(tag === FunctionComponent || tag === ClassComponent || tag === IndeterminateComponent)
471473
) {
472474
// Save component's state and setState() function to our record for future

src/backend/timeJump.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default (mode) => {
3636
// if yes, find the component by its index and assign it to a variable
3737
// call that components setState method to reset state to the state at the time of the jump snapshot
3838
if (component && component.setState) {
39+
console.log('timeJumps', { component });
3940
component.setState(
4041
// prevState contains the states of the snapshots we are jumping FROM, not jumping TO
4142
(prevState) => {

0 commit comments

Comments
 (0)