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' ) ;
8
- const { saveState } = require ( './masterState' ) ;
7
+ const astParser = require ( './astParser' ) ;
8
+ const { saveState } = require ( './masterState' ) ;
9
9
10
10
module . exports = ( snap , mode ) => {
11
11
let fiberRoot = null ;
@@ -24,8 +24,9 @@ module.exports = (snap, mode) => {
24
24
}
25
25
26
26
function changeSetState ( component ) {
27
+ console . log ( 'Component' , component ) ;
27
28
// check that setState hasn't been changed yet
28
- if ( component . setState . linkFiberChanged ) return ;
29
+ if ( component . setState . linkFiberChanged === true ) return ;
29
30
// make a copy of setState
30
31
const oldSetState = component . setState . bind ( component ) ;
31
32
// replace component's setState so developer doesn't change syntax
@@ -46,12 +47,12 @@ module.exports = (snap, mode) => {
46
47
47
48
function changeUseState ( component ) {
48
49
if ( component . queue . dispatch . linkFiberChanged ) return ;
49
- // store the original dispatch function definition
50
- const oldDispatch = component . queue . dispatch . bind ( component . queue ) ; ;
50
+ // store the original dispatch function definition
51
+ const oldDispatch = component . queue . dispatch . bind ( component . queue ) ;
51
52
// redefine the dispatch function so we can inject our code
52
53
component . queue . dispatch = ( fiber , queue , action ) => {
53
54
// don't do anything if state is locked
54
- if ( mode . locked && ! mode . jumping ) return ;
55
+ if ( mode . locked && ! mode . jumping ) return ;
55
56
oldDispatch ( fiber , queue , action ) ;
56
57
setTimeout ( ( ) => {
57
58
updateSnapShotTree ( ) ;
@@ -63,19 +64,19 @@ module.exports = (snap, mode) => {
63
64
64
65
// Helper function to traverse through the memoized state
65
66
function traverseHooks ( memoizedState ) {
66
- // Declare variables and assigned to 0th index and an empty object, respectively
67
+ // Declare variables and assigned t return nextComponent;o 0th index and an empty object, respectively
67
68
const memoized = { } ;
68
- let index = 0 ;
69
- astHooks = Object . values ( astHooks ) ;
69
+ let index = 0 ;
70
+ astHooks = Object . values ( astHooks ) ;
70
71
// while memoizedState is truthy, save the value to the object
71
72
while ( memoizedState ) {
72
73
changeUseState ( memoizedState ) ;
73
- //memoized[astHooks[index]] = memoizedState.memoizedState;
74
- memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
74
+ // memoized[astHooks[index]] = memoizedState.memoizedState;
75
+ memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
75
76
// Reassign memoizedState to its next value
76
77
memoizedState = memoizedState . next ;
77
78
// Increment the index by 2
78
- index += 2 ;
79
+ index += 2 ;
79
80
}
80
81
return memoized ;
81
82
}
@@ -100,7 +101,7 @@ module.exports = (snap, mode) => {
100
101
}
101
102
// Check if the component uses hooks
102
103
if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
103
- // Add a traversed property and initialize to the evaluated result
104
+ // Add a traversed property and initialize to the evaluated result
104
105
// of invoking traverseHooks, and reassign nextTree
105
106
memoizedState . traversed = traverseHooks ( memoizedState ) ;
106
107
nextTree = tree . appendChild ( memoizedState ) ;
@@ -125,16 +126,17 @@ module.exports = (snap, mode) => {
125
126
} = container ;
126
127
// only assign internal rootp if it actually exists
127
128
fiberRoot = _internalRoot || _reactRootContainer ;
128
- // If hooks are implemented, traverse through the source code
129
+ // If hooks are implemented, traverse through the source code
129
130
// Save the getter/setter combo for timeJump
130
131
if ( entryFile ) {
131
132
astHooks = astParser ( entryFile ) ;
132
- saveState ( astHooks ) ;
133
+ console . log ( 'Ast Hooks' , astHooks ) ;
134
+ saveState ( astHooks ) ;
133
135
}
134
136
updateSnapShotTree ( ) ;
135
137
// send the initial snapshot once the content script has started up
136
138
window . addEventListener ( 'message' , ( { data : { action } } ) => {
137
139
if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
138
140
} ) ;
139
- }
141
+ } ;
140
142
} ;
0 commit comments