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
+38-43Lines changed: 38 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
-
101
+
// Update component state
102
+
awaitclassComponent.setState(
103
+
// prevState contains the states of the snapshots we are jumping FROM, not jumping TO
104
+
(prevState)=>state,
105
+
);
106
106
// 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
124
// Iterate through new children after state has been set
0 commit comments