@@ -28,67 +28,53 @@ export default function timeJump(mode) {
28
28
// Base Case: if has visited, return
29
29
if ( circularComponentTable . has ( target ) ) {
30
30
return ;
31
- } else circularComponentTable . add ( target ) ;
31
+ } else {
32
+ circularComponentTable . add ( target ) ;
33
+ }
32
34
// ------------------------STATELESS/ROOT COMPONENT-------------------------
33
35
// Since stateless component has no data to update, continue to traverse its child nodes:
34
36
if ( target . state === 'stateless' || target . state === 'root' ) {
35
37
target . children . forEach ( ( child ) => jump ( child ) ) ;
36
38
return ;
37
39
}
38
- // Obtain component data & its update method at the given index
39
- const component = componentActionsRecord . getComponentByIndex ( target . componentData . index ) ;
40
40
41
+ // Destructure component data:
42
+ const { index, state, hooksIndex, hooksState } = target . componentData ;
41
43
// ------------------------STATEFUL CLASS COMPONENT-------------------------
42
44
// for stateful class components
43
45
// check if it is a stateful class component
44
46
// if yes, find the component by its index and assign it to a variable
45
47
// call that components setState method to reset state to the state at the time of the jump snapshot
46
- if ( component && component . setState ) {
47
- console . log ( 'timeJump CLASS' , componentActionsRecord ) ;
48
- await component . setState (
49
- // prevState contains the states of the snapshots we are jumping FROM, not jumping TO
50
- ( prevState ) => target . state ,
51
- // (prevState) => {
52
- // Object.keys(prevState).forEach((key) => {
53
- // // the if conditional below does not appear to ever be reached if all states are defined - leaving code in just in case codebases do have undefined states
54
- // // if (target.state[key] !== undefined) {
55
- // // target.state[key] = undefined;
56
- // // }
57
- // });
58
- // return target.state;
59
- // }
60
-
61
- // Iterate through new children after state has been set
62
- ( ) => target . children . forEach ( ( child ) => jump ( child ) ) ,
63
- ) ;
48
+ //index can be zero => falsy value => DO NOT REMOVE UNDEFINED
49
+ if ( index !== undefined ) {
50
+ // Obtain component data & its update method at the given index
51
+ const classComponent = componentActionsRecord . getComponentByIndex ( index ) ;
52
+ if ( classComponent && classComponent . setState ) {
53
+ await classComponent . setState (
54
+ // prevState contains the states of the snapshots we are jumping FROM, not jumping TO
55
+ ( prevState ) => state ,
56
+ ) ;
57
+ }
58
+ // Iterate through new children after state has been set
59
+ target . children . forEach ( ( child ) => jump ( child ) ) ;
64
60
return ;
65
61
}
66
62
67
- // target.children.forEach((child) => {
68
- // if (!circularComponentTable.has(child)) {
69
- // circularComponentTable.add(child);
70
- // jump(child);
71
- // }
72
- // });
73
-
74
63
// ----------------------STATEFUL FUNCTIONAL COMPONENT----------------------
75
- // REACT HOOKS
76
64
// check if component states are set with hooks
77
- // if yes, grab all relevant components for this snapshot in numArr
65
+ // if yes, grab all relevant components for this snapshot by its index
78
66
// call dispatch on each component passing in the corresponding currState value
79
- if ( target . state && target . state . hooksState ) {
80
- const currState = target . state . hooksState ;
81
- const numArr : number [ ] = [ ] ;
82
- let counter = 1 ;
83
- while ( counter < currState . length + 1 ) {
84
- numArr . push ( target . componentData . hooksIndex - currState . length + counter ) ;
85
- counter += 1 ;
86
- }
87
- const hooksComponent = componentActionsRecord . getComponentByIndexHooks ( numArr ) ;
88
- console . log ( 'timeJumps' , { hooksComponent, currState } ) ;
89
- for ( let i = 0 ; i < currState . length ; i += 1 ) {
90
- hooksComponent [ i ] . dispatch ( Object . values ( currState [ i ] ) [ 0 ] ) ;
67
+ //index can be zero => falsy value => DO NOT REMOVE UNDEFINED
68
+ if ( hooksIndex !== undefined ) {
69
+ // Obtain component data & its update method at the given index
70
+ const functionalComponent = componentActionsRecord . getComponentByIndexHooks ( hooksIndex ) ;
71
+ if ( functionalComponent . length ) {
72
+ for ( let i = 0 ; i < hooksState . length ; i += 1 ) {
73
+ await functionalComponent [ i ] . dispatch ( Object . values ( hooksState [ i ] ) [ 0 ] ) ;
74
+ }
91
75
}
76
+ target . children . forEach ( ( child ) => jump ( child ) ) ;
77
+ return ;
92
78
}
93
79
}
94
80
0 commit comments