Skip to content

Commit a258cd0

Browse files
RobbyTiptonfscgoldenjoeeparkdavidkim7773khobread
committed
Added comments to routes.ts. Reverted previous change saveNew in masterState that is no longer relevant. Made accompanying changes in linkFiber and backendTypes.
Co-authored-by: Chris LeBrett <[email protected]> Co-authored-by: Robby Tipton <[email protected]> Co-authored-by: Joseph Park <[email protected]> Co-authored-by: David Kim <[email protected]> Co-authored-by: Kevin HoEun Lee <[email protected]>
1 parent b986fc8 commit a258cd0

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/backend/linkFiber.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ function createTree(
359359
componentData.index = componentActionsRecord.saveNew(
360360
stateNode.state,
361361
stateNode,
362-
currentFiber.elementType.name,
363362
);
364363
newState = stateNode.state;
365364
componentFound = true;
@@ -415,7 +414,6 @@ function createTree(
415414
hooksIndex = componentActionsRecord.saveNew(
416415
state.state,
417416
state.component,
418-
currentFiber.elementType.name,
419417
);
420418
componentData.hooksIndex = hooksIndex;
421419
if (!newState) {

src/backend/masterState.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export default {
2424
index = 0;
2525
},
2626
// adds new component to ComponentActionsRecord
27-
saveNew: (state, component, name): number => {
28-
componentActionsRecord[index] = { state, component, name };
27+
saveNew: (state, component): number => {
28+
componentActionsRecord[index] = { state, component };
2929
index++;
3030

3131
return index - 1;

src/backend/routes.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
/* eslint-disable max-classes-per-file */
2+
/* eslint-disable max-len */
23

4+
/**
5+
* @class Route instances are created by the addRoute method on Routes. A Route instance has two properties: the url of the route and a unique id.
6+
*/
37
class Route {
48
url: string;
59

@@ -11,13 +15,34 @@ class Route {
1115
}
1216
}
1317

18+
/**
19+
* @class An instance of this class is the default export from routes.ts. It includes the logic that allows Reactime to work with target applications built with React Router. The addRoute method is invoked in linkFiber.ts within the sendSnapshot function. The navigate method is invoked in timeJump.ts immediately before invoking jump.
20+
*/
21+
1422
class Routes {
23+
/**
24+
* @property A stack of visited routes that matches the browser history stack.
25+
*/
1526
values: Route[] = [new Route(null, null)];
1627

28+
/**
29+
* @property Used to assign unique ids to routes in the values stack in case the same route is added to the stack more than once.
30+
*/
1731
id = 0;
1832

33+
/**
34+
* @property The index of the current route in the values stack.
35+
*/
1936
current: number | null = 0;
2037

38+
/**
39+
* @method addRoute
40+
* @param url - A url string.
41+
* @returns Either the current route if the user has not navigated away from it or a new instance of a route constructed from the url.
42+
*
43+
* Ensures that the values stack always matches the browser history stack.
44+
*/
45+
2146
addRoute(url: string): Route {
2247
let route: Route = this.values[this.current];
2348

@@ -35,7 +60,13 @@ class Routes {
3560
return route;
3661
}
3762

38-
rebuildHistory(url: string): void {
63+
/**
64+
* @method rebuildHistory
65+
* @param url - A url string.
66+
*
67+
* Rebuilds the browser history stack using the copy of the stack maintained in the values stack. https://developer.mozilla.org/en-US/docs/Web/API/History/replaceState, https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
68+
*/
69+
private rebuildHistory(url: string): void {
3970
window.history.replaceState('', '', this.values[this.current + 1].url);
4071

4172
for (let i = this.current + 2; i < this.values.length; i += 1) {
@@ -45,6 +76,13 @@ class Routes {
4576
window.history.pushState('', '', url);
4677
}
4778

79+
/**
80+
* @method navigate
81+
* @param route - The target route in the values stack that is being navigated to.
82+
* @returns A boolean indicating whether or not a new route was navigated to.
83+
*
84+
* Invokes history.go passing in the delta between the current route and the target route. https://developer.mozilla.org/en-US/docs/Web/API/History/go
85+
*/
4886
navigate(route: Route): boolean {
4987
let targetIndex: number | null = null;
5088

src/backend/types/backendTypes.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export interface ComponentData {
4141
export interface HookStateItem {
4242
state: any;
4343
component: any;
44-
name?: string;
4544
}
4645

4746
export type HookStates = Array<HookStateItem>;

0 commit comments

Comments
 (0)