4
4
// links component state tree to library
5
5
// changes the setState method to also update our snapshot
6
6
const Tree = require ( './tree' ) ;
7
- const astParser = require ( './astParser.js' ) ;
7
+ const astParser = require ( './astParser' ) ;
8
+ const { saveState } = require ( './masterState' ) ;
8
9
9
10
module . exports = ( snap , mode ) => {
10
11
let fiberRoot = null ;
11
- let astHooks ;
12
+ let astHooks ;
12
13
13
14
function sendSnapshot ( ) {
14
15
// don't send messages while jumping or while paused
@@ -45,14 +46,15 @@ module.exports = (snap, mode) => {
45
46
46
47
function changeUseState ( component ) {
47
48
if ( component . queue . dispatch . linkFiberChanged ) return ;
48
- // store the original dispatch function definition
49
- const oldDispatch = component . queue . dispatch . bind ( component . queue ) ; ;
49
+ // store the original dispatch function definition
50
+ const oldDispatch = component . queue . dispatch . bind ( component . queue ) ;
50
51
// redefine the dispatch function so we can inject our code
51
52
component . queue . dispatch = ( fiber , queue , action ) => {
52
53
// don't do anything if state is locked
53
54
if ( mode . locked && ! mode . jumping ) return ;
54
- oldDispatch ( fiber , queue , action ) ;
55
+ // oldDispatch(fiber, queue, action);
55
56
setTimeout ( ( ) => {
57
+ oldDispatch ( fiber , queue , action ) ;
56
58
updateSnapShotTree ( ) ;
57
59
sendSnapshot ( ) ;
58
60
} , 100 ) ;
@@ -61,16 +63,16 @@ module.exports = (snap, mode) => {
61
63
}
62
64
63
65
// Helper function to traverse through the memoized state
64
- // TODO: WE NEED TO CLEAN IT UP A BIT
65
66
function traverseHooks ( memoizedState ) {
66
67
// Declare variables and assigned to 0th index and an empty object, respectively
67
68
const memoized = { } ;
68
69
let index = 0 ;
69
70
astHooks = Object . values ( astHooks ) ;
70
71
// while memoizedState is truthy, save the value to the object
71
- while ( memoizedState && astHooks ) {
72
+ while ( memoizedState ) {
72
73
changeUseState ( memoizedState ) ;
73
- memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
74
+ //memoized[astHooks[index]] = memoizedState.memoizedState;
75
+ memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
74
76
// Reassign memoizedState to its next value
75
77
memoizedState = memoizedState . next ;
76
78
// Increment the index by 2
@@ -98,7 +100,7 @@ module.exports = (snap, mode) => {
98
100
changeSetState ( stateNode ) ;
99
101
}
100
102
// Check if the component uses hooks
101
- if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
103
+ if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
102
104
// Add a traversed property and initialize to the evaluated result
103
105
// of invoking traverseHooks, and reassign nextTree
104
106
memoizedState . traversed = traverseHooks ( memoizedState ) ;
@@ -111,7 +113,8 @@ module.exports = (snap, mode) => {
111
113
112
114
return tree ;
113
115
}
114
-
116
+ // runs when page initially loads
117
+ // but skips 1st hook click
115
118
function updateSnapShotTree ( ) {
116
119
const { current } = fiberRoot ;
117
120
snap . tree = createTree ( current ) ;
@@ -125,9 +128,12 @@ module.exports = (snap, mode) => {
125
128
// only assign internal rootp if it actually exists
126
129
fiberRoot = _internalRoot || _reactRootContainer ;
127
130
// If hooks are implemented, traverse through the source code
128
- if ( entryFile ) astHooks = astParser ( entryFile ) ;
129
-
130
- updateSnapShotTree ( ) ;
131
+ // Save the getter/setter combo for timeJump
132
+ if ( entryFile ) {
133
+ astHooks = astParser ( entryFile ) ;
134
+ saveState ( astHooks ) ;
135
+ }
136
+ updateSnapShotTree ( ) ;
131
137
// send the initial snapshot once the content script has started up
132
138
window . addEventListener ( 'message' , ( { data : { action } } ) => {
133
139
if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
0 commit comments