44// links component state tree to library
55// changes the setState method to also update our snapshot
66const Tree = require ( './tree' ) ;
7- const astParser = require ( './astParser.js' ) ;
7+ const astParser = require ( './astParser' ) ;
8+ const { saveState } = require ( './masterState' ) ;
89
910module . exports = ( snap , mode ) => {
1011 let fiberRoot = null ;
11- let astHooks ;
12+ let astHooks ;
1213
1314 function sendSnapshot ( ) {
1415 // don't send messages while jumping or while paused
@@ -45,14 +46,15 @@ module.exports = (snap, mode) => {
4546
4647 function changeUseState ( component ) {
4748 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 ) ;
5051 // redefine the dispatch function so we can inject our code
5152 component . queue . dispatch = ( fiber , queue , action ) => {
5253 // don't do anything if state is locked
5354 if ( mode . locked && ! mode . jumping ) return ;
54- oldDispatch ( fiber , queue , action ) ;
55+ // oldDispatch(fiber, queue, action);
5556 setTimeout ( ( ) => {
57+ oldDispatch ( fiber , queue , action ) ;
5658 updateSnapShotTree ( ) ;
5759 sendSnapshot ( ) ;
5860 } , 100 ) ;
@@ -61,16 +63,16 @@ module.exports = (snap, mode) => {
6163 }
6264
6365 // Helper function to traverse through the memoized state
64- // TODO: WE NEED TO CLEAN IT UP A BIT
6566 function traverseHooks ( memoizedState ) {
6667 // Declare variables and assigned to 0th index and an empty object, respectively
6768 const memoized = { } ;
6869 let index = 0 ;
6970 astHooks = Object . values ( astHooks ) ;
7071 // while memoizedState is truthy, save the value to the object
71- while ( memoizedState && astHooks ) {
72+ while ( memoizedState ) {
7273 changeUseState ( memoizedState ) ;
73- memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
74+ //memoized[astHooks[index]] = memoizedState.memoizedState;
75+ memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
7476 // Reassign memoizedState to its next value
7577 memoizedState = memoizedState . next ;
7678 // Increment the index by 2
@@ -98,7 +100,7 @@ module.exports = (snap, mode) => {
98100 changeSetState ( stateNode ) ;
99101 }
100102 // Check if the component uses hooks
101- if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
103+ if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
102104 // Add a traversed property and initialize to the evaluated result
103105 // of invoking traverseHooks, and reassign nextTree
104106 memoizedState . traversed = traverseHooks ( memoizedState ) ;
@@ -111,7 +113,8 @@ module.exports = (snap, mode) => {
111113
112114 return tree ;
113115 }
114-
116+ // runs when page initially loads
117+ // but skips 1st hook click
115118 function updateSnapShotTree ( ) {
116119 const { current } = fiberRoot ;
117120 snap . tree = createTree ( current ) ;
@@ -125,9 +128,12 @@ module.exports = (snap, mode) => {
125128 // only assign internal rootp if it actually exists
126129 fiberRoot = _internalRoot || _reactRootContainer ;
127130 // 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 ( ) ;
131137 // send the initial snapshot once the content script has started up
132138 window . addEventListener ( 'message' , ( { data : { action } } ) => {
133139 if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
0 commit comments