You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/backend/controllers/timeJump.ts
+39-43Lines changed: 39 additions & 43 deletions
Original file line number
Diff line number
Diff line change
@@ -19,30 +19,40 @@ const circularComponentTable = new Set();
19
19
*
20
20
*/
21
21
exportdefaultfunctiontimeJump(mode: Status){
22
-
// payload from index.ts is assigned to target
23
22
/**
24
-
* @param target - The target snapshot to re-render
23
+
* The target snapshot to re-render
24
+
*/
25
+
lettarget;
26
+
/**
27
+
* This function is to aid the removeListener for 'popstate'
28
+
*/
29
+
// IMPORTANT: DO NOT move this function into return function. This function is out here so that it will not be redefined any time the return function is invoked. This is importatnt for removeEventListener for popstate to work.
30
+
constpopStateHandler=()=>{
31
+
initiateJump(target,mode);
32
+
};
33
+
34
+
/**
35
+
* @param inputTarget - The target snapshot to re-render. The payload from index.ts is assigned to inputTarget
25
36
* @param firstCall - A boolean flag checking for `firstCall`
// Determine if user is navigating to another route
46
+
// NOTE: Inside routes.navigate, if user is navigating, we will invoke history.go, which will go back/forth based on # of delta steps. This will trigger a popstate event. Since history.go is an async method, the event listener is the only way to invoke timeJump after we have arrived at the desirable route.
// If the user navigate to another page during jumps, Routes methods will popState until find a match => this cause changes in componentActionRecord => keep the if statement, otherwise will run into Uncaught Promise type error.
96
-
if(classComponent?.setState){
97
-
// Update component state
98
-
awaitclassComponent.setState(
99
-
// prevState contains the states of the snapshots we are jumping FROM, not jumping TO
100
-
(prevState)=>state,
101
-
);
102
-
}
103
-
// Else statement is to ensure if a mismatch, this popstate is not the correct componentActionRecord. Return immediately to avoid traverse the entire tree
104
-
elsereturn;
105
-
102
+
// Update component state
103
+
awaitclassComponent.setState(
104
+
// prevState contains the states of the snapshots we are jumping FROM, not jumping TO
105
+
(prevState)=>state,
106
+
);
106
107
// Iterate through new children after state has been set
// If the user navigate to another page during jumps, Routes methods will popState until find a match => this cause changes in componentActionRecord => keep the if statement, otherwise will run into Uncaught Promise type error.
// Else statement is to ensure if a mismatch, this popstate is not the correct componentActionRecord. Return immediately to avoid traverse the entire tree
127
-
elsereturn;
128
-
129
125
// Iterate through new children after state has been set
Copy file name to clipboardExpand all lines: src/backend/models/masterState.ts
+22-5Lines changed: 22 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -4,24 +4,35 @@
4
4
/* eslint-disable guard-for-in */
5
5
/* eslint-disable no-restricted-syntax */
6
6
7
+
/**
8
+
* @type ComponentAction - an array of actions that can be performed on a component
9
+
*/
7
10
typeComponentAction=any[];
8
11
9
-
// HookState is an array that contains a "component" for
10
-
// every single state change that occurs in the app
12
+
// The HookState data structure is an array that holds the current value of a hook's state, as well as a dispatch function that is used to update that state.
11
13
// Information on these components include ComponentData as well as state
12
14
// For class components, there will be one "component" for each snapshot
13
15
// For functional components that utilize Hooks, there will be one "component"
14
16
// for each setter/getter every time we have a new snapshot
15
17
letcomponentActionsRecord: ComponentAction=[];
18
+
// index keeps track of the current position in the array
16
19
letindex: number;
17
20
index=0;
18
21
19
22
exportdefault{
23
+
/**
24
+
* @function clear - Clears componentActionsRecord
25
+
*/
20
26
clear: ()=>{
21
27
componentActionsRecord=[];
22
28
index=0;
23
29
},
24
-
// Adds new component to ComponentActionsRecord
30
+
31
+
/**
32
+
* @function saveNew - Adds a new component to the componentActionsRecord array and returns its index.
* This function is used for Functional Component to retrieve an array of objects that have the bound dispatch methods.
52
+
* @function getComponentByIndexHooks - This function is used for Functional Component to retrieve an array of objects that have the bound dispatch methods.
42
53
* @param inputIndex - index of component inside `componentActionsRecord` coming from `timeJump.ts`
43
54
* @returns - an array of objects containing the bound dispatch methods
Copy file name to clipboardExpand all lines: src/backend/models/tree.ts
+24-12Lines changed: 24 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,12 @@
7
7
/* eslint-disable no-param-reassign */
8
8
import{Route}from'./routes';
9
9
10
-
letcopyInstances=0;// Tells you if we have already made a copy of current tree??
11
-
constcircularComponentTable=newSet<Tree>();// Keeps track of the nodes added to the tree
12
-
letcomponentNames={};// {componentName: frequency of use} => component name as a key and it's frequency of use as its value
10
+
// The circularComponentTable is used to handle circular references in the state object. It keeps tracks of the components that have already been serialized. When a component is encountered for the first time, it is added to the table along with a unique identifier. If the same component is encountered again, the identifier is used to reference the previously serialized component in the output instead of serializing it again, thus avoiding the infinite loop.
11
+
constcircularComponentTable=newSet<Tree>();
12
+
// Used to keep track of which objects have already been copied during the serialization process. This is necessary to handle circular references correctly. When an object is serialized, all its properties are copied to the serialized object. If an object property is an object itself, it needs to be serialized recursively. However, if the object being serialized has already been serialized before, it should not be serialized again to prevent an infinite loop.
13
+
letcopyInstances=0;
14
+
// ComponentNames is used to store a mapping between a component's unique identifier and its name. This mapping is used to reconstruct the component instances during deserialization.
15
+
letcomponentNames={};
13
16
14
17
// Functions dont serialize properly so we need to scrub for that
@@ -20,6 +23,11 @@ export function scrubUnserializableMembers(tree: Tree): Tree {
20
23
}
21
24
22
25
// Making a deep clone of state becuase we want to make a copy
26
+
/**
27
+
* @function serializeState - In the context of React, state is often used to store data that determines the behavior and appearance of a component. By serializing the state, we can preserve the component's data across page refreshes, server-side rendering, and other transitions. Additionally, by serializing the state and passing it to a child component, we can create a deep clone of the state, which allows the child component to manipulate the state without affecting the original component. This is useful in situations where we want to keep the state of the parent component immutable, but still allow child components to modify a copy of the state.
28
+
* @param state - Object that contains the current state of the application or system that needs to be serialized.
29
+
* @returns
30
+
*/
23
31
exportfunctionserializeState(state){
24
32
try{
25
33
// makes a deep clone
@@ -33,15 +41,14 @@ export function serializeState(state) {
33
41
/**
34
42
* This is the current snapshot that is being sent to the snapshots array.
35
43
* Creates a Tree
36
-
* @param state - {string| {}} - the tree's current state
37
-
* @param name - {string} - the tree's name
38
-
* @param componentData - {props: {}} - Data in the component tree
39
-
* @param chilren - {(Tree | string)[]} - An array of children nodes
40
-
* @param parent - {Tree} - the parent node
41
-
* @param isExpanded - {boolean}
42
-
* @param rtid - {any}
43
-
* @param route -
44
-
* @parent generates a new tree (recursive call)
44
+
* @param state - the current state of the component represented by this node.
45
+
* @param name - the name of the component represented by this node.
46
+
* @param componentData - an object containing the props of the component represented by this node.
47
+
* @param chilren - an array of child nodes.
48
+
* @param parent - a reference to the parent node.
49
+
* @param isExpanded - a boolean value indicating whether the node is expanded in the UI.
50
+
* @param rtid - a unique identifier for the node.
51
+
* @param route - an object representing the route associated with the node.
45
52
*/
46
53
classTree{
47
54
state: string|{};
@@ -87,6 +94,11 @@ class Tree {
87
94
}
88
95
89
96
// Returns a unique name ready to be used for when new components gets added to the tree
97
+
/**
98
+
* @function checkForDuplicates - Generates a unique name for a component that is being added to the component tree
0 commit comments