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 ;
@@ -46,13 +46,13 @@ module.exports = (snap, mode) => {
46
46
47
47
function changeUseState ( component ) {
48
48
if ( component . queue . dispatch . linkFiberChanged ) return ;
49
- // store the original dispatch function definition
49
+ // store the original dispatch function definition
50
50
const oldDispatch = component . queue . dispatch . bind ( component . queue ) ;
51
51
// redefine the dispatch function so we can inject our code
52
52
component . queue . dispatch = ( fiber , queue , action ) => {
53
53
// don't do anything if state is locked
54
- if ( mode . locked && ! mode . jumping ) return ;
55
- //oldDispatch(fiber, queue, action);
54
+ if ( mode . locked && ! mode . jumping ) return ;
55
+ // oldDispatch(fiber, queue, action);
56
56
setTimeout ( ( ) => {
57
57
oldDispatch ( fiber , queue , action ) ;
58
58
updateSnapShotTree ( ) ;
@@ -66,17 +66,17 @@ module.exports = (snap, mode) => {
66
66
function traverseHooks ( memoizedState ) {
67
67
// Declare variables and assigned to 0th index and an empty object, respectively
68
68
const memoized = { } ;
69
- let index = 0 ;
70
- astHooks = Object . values ( astHooks ) ;
69
+ let index = 0 ;
70
+ astHooks = Object . values ( astHooks ) ;
71
71
// while memoizedState is truthy, save the value to the object
72
72
while ( memoizedState ) {
73
73
changeUseState ( memoizedState ) ;
74
- //memoized[astHooks[index]] = memoizedState.memoizedState;
75
- memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
74
+ // memoized[astHooks[index]] = memoizedState.memoizedState;
75
+ memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
76
76
// Reassign memoizedState to its next value
77
77
memoizedState = memoizedState . next ;
78
78
// Increment the index by 2
79
- index += 2 ;
79
+ index += 2 ;
80
80
}
81
81
return memoized ;
82
82
}
@@ -100,8 +100,8 @@ module.exports = (snap, mode) => {
100
100
changeSetState ( stateNode ) ;
101
101
}
102
102
// Check if the component uses hooks
103
- if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
104
- // Add a traversed property and initialize to the evaluated result
103
+ if ( memoizedState && Object . hasOwnProperty . call ( memoizedState , 'baseState' ) ) {
104
+ // Add a traversed property and initialize to the evaluated result
105
105
// of invoking traverseHooks, and reassign nextTree
106
106
memoizedState . traversed = traverseHooks ( memoizedState ) ;
107
107
nextTree = tree . appendChild ( memoizedState ) ;
@@ -113,8 +113,8 @@ module.exports = (snap, mode) => {
113
113
114
114
return tree ;
115
115
}
116
- // runs when page initially loads
117
- // but skips 1st hook click
116
+ // runs when page initially loads
117
+ // but skips 1st hook click
118
118
function updateSnapShotTree ( ) {
119
119
const { current } = fiberRoot ;
120
120
snap . tree = createTree ( current ) ;
@@ -127,16 +127,25 @@ module.exports = (snap, mode) => {
127
127
} = container ;
128
128
// only assign internal rootp if it actually exists
129
129
fiberRoot = _internalRoot || _reactRootContainer ;
130
- // If hooks are implemented, traverse through the source code
130
+ // If hooks are implemented, traverse through the source code
131
131
// Save the getter/setter combo for timeJump
132
132
if ( entryFile ) {
133
133
astHooks = astParser ( entryFile ) ;
134
- saveState ( astHooks ) ;
134
+ console . log ( 'Ast Hooks' , astHooks ) ;
135
+ saveState ( astHooks ) ;
135
136
}
136
- updateSnapShotTree ( ) ;
137
+ updateSnapShotTree ( ) ;
137
138
// send the initial snapshot once the content script has started up
138
139
window . addEventListener ( 'message' , ( { data : { action } } ) => {
139
140
if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
140
141
} ) ;
141
- }
142
+ //
143
+ if ( astHooks ) {
144
+ function consoleLoggerTest ( someString ) {
145
+ return someString ;
146
+ }
147
+ const testFunction = consoleLoggerTest ( 'Hello from reactime' ) ;
148
+ return testFunction ;
149
+ }
150
+ } ;
142
151
} ;
0 commit comments