Skip to content

Commit 4fec3d6

Browse files
committed
added documentation for createTree, statePropExtractor, filterConditions
1 parent e66fa2f commit 4fec3d6

File tree

9 files changed

+42
-91
lines changed

9 files changed

+42
-91
lines changed

src/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,18 @@ src/
4545
│   │ # Focus especially on linkFiber, timeJump, tree, and helpers
4646
│   ├── __tests__/ #
4747
│   ├── controllers/ #
48-
│   ├── createComponentActionsRecord.ts #
49-
│   ├── createTree.ts #
50-
│   ├── statePropExtractor.ts #
51-
│   ├── throttle.ts #
48+
│   ├── createComponentActionsRecord.ts # Update the componentActionsRecord with new bound state-update methods
49+
│   ├── createTree.ts # Construct a tree snapshot from the FiberRoot tree given by ReactFiber.
50+
│   ├── statePropExtractor.ts # Helper functions to extract & format prop, state, and context data
51+
│   ├── throttle.ts #
5252
│   ├── timeJump.ts # Rerenders DOM based on snapshot from background script
5353
│   ├── models/
5454
│   ├── filterConditions.ts #
5555
│   ├── masterState.ts # Component action record interface
5656
│   ├── routes.ts # Interfaces with the browser history stack
5757
│   ├── tree.ts # Custom structure to send to background
5858
│   ├── routers/
59-
│   ├── linkFiber.ts #
59+
│   ├── linkFiber.ts # Check for all requirement to start Reactime and
6060
│   ├── snapShot.ts #
6161
│   ├── types/ # Typescript interfaces
6262
│   ├── index.ts # Starting point for backend functionality

src/backend/__tests__/linkFiber.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,14 @@ import {
1212
mixComponents,
1313
mixPayload,
1414
} from './ignore/stateComponents-testcases';
15-
import { Snapshot, Status, FiberRoot } from '../types/backendTypes';
15+
import { Status, FiberRoot } from '../types/backendTypes';
1616
import Tree from '../models/tree';
1717
import { DevTools } from '../types/linkFiberTypes';
1818
import { JSDOM } from 'jsdom';
1919
import path from 'path';
2020
import fs from 'fs';
2121

2222
describe('linkFiber', () => {
23-
let snapshot: Snapshot;
2423
let mode: Status;
2524
let linkFiber: () => Promise<void>;
2625
let linkFiberDelayed: (resolve: any) => NodeJS.Timeout;
@@ -46,18 +45,14 @@ describe('linkFiber', () => {
4645
});
4746

4847
beforeEach(() => {
49-
// Create snapshot and mode objects
50-
snapshot = {
51-
tree: new Tree('root', 'root'),
52-
};
5348
mode = {
5449
jumping: false,
5550
};
5651
// Initialize Fiber Root:
5752
fiberRoot = { current: root };
5853

5954
// Initialize linkFiber
60-
linkFiber = linkFiberInitialization(snapshot, mode);
55+
linkFiber = linkFiberInitialization(mode);
6156
// Since linkFiber invoke a throttle function that get delay for 70 ms, between each test, linkFiber need to be delayed for 75 ms to ensure no overlapping async calls.
6257
linkFiberDelayed = (resolve) => setTimeout(async () => resolve(await linkFiber()), DELAY);
6358

src/backend/controllers/createTree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
* @param currentFiberNode A Fiber object
3333
* @return An instance of a Tree object
3434
*/
35-
// TODO: Not sure why the ritd need to be outside of the createTree function. Want to put inside, but in case this need to be keep track for front end.
35+
// TODO: Not sure why the ritd need to be outside of the _createTree function. Want to put inside, but in case this need to be keep track for front end.
3636
export default function createTree(currentFiberNode: Fiber): Tree {
3737
let rtidCounter = 0;
3838
return _createTree(currentFiberNode, new Tree('root', 'root'));

src/backend/controllers/statePropExtractors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const acorn = require('acorn');
22
const jsx = require('acorn-jsx');
33
const JSXParser = acorn.Parser.extend(jsx());
4-
import { HookStates, HookStateItem, Fiber } from '../types/backendTypes';
4+
import { HookStateItem, Fiber } from '../types/backendTypes';
55
import { exclude } from '../models/filterConditions';
66

77
type ReactimeData = {

src/backend/index.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,15 @@ import timeJumpInitialization from './controllers/timeJump';
1010
import { Snapshot, Status, MsgData } from './types/backendTypes';
1111
import routes from './models/routes';
1212

13-
// -------------------------INITIALIZE SNAPSHOT & MODE--------------------------
14-
/** The snapshot of the current ReactFiber tree */
15-
const snapShot: Snapshot = {
16-
tree: null,
17-
};
18-
13+
// -------------------------INITIALIZE MODE--------------------------
1914
/** Indicate if mode is jumping/not jumping or navigating during jumping */
2015
const mode: Status = {
2116
jumping: false,
2217
};
2318

2419
// ---------------------INITIALIZE LINKFIBER & TIMEJUMP-------------------------
2520
// linkFiber is now assigned the default ASYNC function exported from the file linkFiber.ts
26-
const linkFiber = linkFiberInitialization(snapShot, mode);
21+
const linkFiber = linkFiberInitialization(mode);
2722
// timeJump is now assigned the default ASYNC function exported from the file timeJump.ts
2823
const timeJump = timeJumpInitialization(mode);
2924

src/backend/models/filterConditions.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,7 @@ import {
22
FunctionComponent,
33
ClassComponent,
44
IndeterminateComponent, // Before we know whether it is function or class
5-
HostRoot, // Root of a host tree. Could be nested inside another node.
6-
HostPortal, // A subtree. Could be an entry point to a different renderer.
7-
/**
8-
* Host Component: a type of component that represents a native DOM element in the browser environment, such as div, span, input, h1 etc.
9-
*/
10-
HostComponent, // has stateNode of html elements
11-
HostText,
12-
Fragment,
13-
Mode,
14-
ContextConsumer,
155
ContextProvider,
16-
ForwardRef,
17-
Profiler,
18-
SuspenseComponent,
19-
MemoComponent,
20-
SimpleMemoComponent, // A higher order component where if the component renders the same result given the same props, react skips rendering the component and uses last rendered result. Has memoizedProps/memoizedState but no stateNode
21-
LazyComponent,
22-
IncompleteClassComponent,
23-
DehydratedFragment,
24-
SuspenseListComponent,
25-
FundamentalComponent,
26-
ScopeComponent,
27-
Block,
28-
OffscreenComponent,
29-
LegacyHiddenComponent,
306
WorkTag,
317
} from '../types/backendTypes';
328

@@ -72,11 +48,10 @@ export const remixDefaultComponents = new Set([
7248
'Scripts',
7349
'LiveReload2',
7450
]);
75-
76-
export /**
51+
/**
7752
* A set of excluded props and variable name
7853
*/
79-
const exclude = new Set([
54+
export const exclude = new Set([
8055
'alternate',
8156
'basename',
8257
'baseQueue',

src/backend/routers/linkFiber.ts

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,25 @@ const MIN_TIME_BETWEEN_UPDATE = 70;
2323
* @param mode - mode is jumping/not jumping or navigating during jumping
2424
* @param snapShot - the tree snapshot to send to Front End or obtained from Front End during timeJump
2525
*/
26-
const throttledUpdateSnapshot = throttle(
27-
async (fiberRoot: FiberRoot, mode: Status, snapShot: Snapshot) => {
28-
// If not jumping
29-
if (!mode.jumping) {
30-
// Update and Send SnapShot tree to front end
31-
updateAndSendSnapShotTree(snapShot, fiberRoot);
32-
}
26+
const throttledUpdateSnapshot = throttle(async (fiberRoot: FiberRoot, mode: Status) => {
27+
// If not jumping
28+
if (!mode.jumping) {
29+
// Update and Send SnapShot tree to front end
30+
updateAndSendSnapShotTree(fiberRoot);
31+
}
3332

34-
// If navigating to another route during jumping:
35-
else if (mode.navigating) {
36-
// Reset the array containing update methods:
37-
componentActionsRecord.clear();
38-
// Obtain new update methods for the current route:
39-
const { current } = fiberRoot;
40-
createComponentActionsRecord(current);
41-
// Invoke timeJump, which is stored in mode.navigating, to update React Application FiberTree based on the snapshotTree
42-
await mode.navigating();
43-
}
44-
// NOTE: if not navigating during jumping, timeJump is invoked in index.ts file.
45-
},
46-
MIN_TIME_BETWEEN_UPDATE,
47-
);
33+
// If navigating to another route during jumping:
34+
else if (mode.navigating) {
35+
// Reset the array containing update methods:
36+
componentActionsRecord.clear();
37+
// Obtain new update methods for the current route:
38+
const { current } = fiberRoot;
39+
createComponentActionsRecord(current);
40+
// Invoke timeJump, which is stored in mode.navigating, to update React Application FiberTree based on the snapshotTree
41+
await mode.navigating();
42+
}
43+
// NOTE: if not navigating during jumping, timeJump is invoked in index.ts file.
44+
}, MIN_TIME_BETWEEN_UPDATE);
4845

4946
/**
5047
* @function linkFiber - linkFiber contains core module functionality, exported as an anonymous function, perform the following logic:
@@ -58,7 +55,7 @@ const throttledUpdateSnapshot = throttle(
5855
* @param mode The current mode (i.e. jumping, time-traveling, or paused)
5956
* @return a function to be invoked by index.js that initiates snapshot monitoring
6057
*/
61-
export default function linkFiber(snapShot: Snapshot, mode: Status): () => Promise<void> {
58+
export default function linkFiber(mode: Status): () => Promise<void> {
6259
/** A boolean value indicate if the target React Application is visible */
6360
let isVisible: boolean = true;
6461
/**
@@ -115,7 +112,7 @@ export default function linkFiber(snapShot: Snapshot, mode: Status): () => Promi
115112
fiberRoot = devTools.getFiberRoots(1).values().next().value;
116113

117114
// ----------INITIALIZE THE TREE SNAP SHOT ON CHROME EXTENSION--------------
118-
await throttledUpdateSnapshot(fiberRoot, mode, snapShot); // only runs on start up
115+
await throttledUpdateSnapshot(fiberRoot, mode); // only runs on start up
119116

120117
// --------MONKEY PATCHING THE onCommitFiberRoot FROM REACT DEV TOOL--------
121118
// React has inherent methods that are called with react fiber
@@ -131,7 +128,7 @@ export default function linkFiber(snapShot: Snapshot, mode: Status): () => Promi
131128
// Obtain the updated FiberRootNode, after the target React application re-renders
132129
const fiberRoot = args[1];
133130
// If the target React application is visible, send a request to update the snapShot tree displayed on Chrome Extension
134-
if (isVisible) throttledUpdateSnapshot(fiberRoot, mode, snapShot);
131+
if (isVisible) throttledUpdateSnapshot(fiberRoot, mode);
135132
// After our added work is completed we invoke the original onComitFiberRoot function
136133
return onCommitFiberRoot(...args);
137134
};

src/backend/routers/snapShot.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Snapshot, Status, FiberRoot } from '../types/backendTypes';
2-
// passes the data down to its components
1+
import { Snapshot, FiberRoot } from '../types/backendTypes';
32
import componentActionsRecord from '../models/masterState';
43
import routes from '../models/routes';
54
import createTree from '../controllers/createTree';
@@ -13,22 +12,16 @@ import createTree from '../controllers/createTree';
1312
* @param fiberRoot The `fiberRootNode`, which is the root node of the fiber tree is stored in the current property of the fiber root object which we can use to traverse the tree
1413
*/
1514
// updating tree depending on current mode on the panel (pause, etc)
16-
export default function updateAndSendSnapShotTree(snapshot: Snapshot, fiberRoot: FiberRoot): void {
15+
export default function updateAndSendSnapShotTree(fiberRoot: FiberRoot): void {
1716
// This is the currently active root fiber(the mutable root of the tree)
1817
const { current } = fiberRoot;
19-
// Clear all of the legacy actions from old fiber tree becuase we are about to create a new one
18+
// Clear all of the legacy actions from old fiber tree because we are about to create a new one
2019
componentActionsRecord.clear();
21-
// Calls the createTree function which creates the new Fiber tree and adds it to tree property on the snapShot object
22-
snapshot.tree = createTree(current);
23-
// Make a deep copy of the tree:
24-
const payload = snapshot.tree;
20+
// Calls the createTree function which creates the new snapshot tree and store new state update method to compoenActionsRecord
21+
/** The snapshot of the current ReactFiber tree */
22+
const payload = createTree(current);
2523
// Save the current window url to route
2624
payload.route = routes.addRoute(window.location.href);
27-
// console.log('send snapshot', {
28-
// payload: payload.children[0],
29-
// componentAction: componentActionsRecord.getAllComponents(),
30-
// });
31-
3225
// method safely enables cross-origin communication between Window objects;
3326
// e.g., between a page and a pop-up that it spawned, or between a page
3427
// and an iframe embedded within it.

src/backend/types/backendTypes.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,12 @@ export interface ComponentData {
8181
* @member component - contains bound dispatch method to update state of the current functional component
8282
*/
8383
export interface HookStateItem {
84+
/** states within the current functional component */
8485
state: any;
86+
/** an object contains bound dispatch method to update state of the current functional component */
8587
component: any;
8688
}
8789

88-
/**
89-
* HookeStates is an array of HookeStateItem
90-
* Each HookStateItem is an object with state & component properties
91-
*/
92-
export type HookStates = Array<HookStateItem>;
93-
9490
export type WorkTag =
9591
| 0
9692
| 1

0 commit comments

Comments
 (0)