3
3
/* eslint-disable no-param-reassign */
4
4
// links component state tree to library
5
5
// changes the setState method to also update our snapshot
6
+
7
+ // import loadable from '@loadable/component';
8
+
6
9
const Tree = require ( './tree' ) ;
7
- const astParser = require ( './astParser' ) ;
8
- const { saveState } = require ( './masterState' ) ;
10
+ const astParser = require ( './astParser' ) ;
11
+ const { saveState } = require ( './masterState' ) ;
9
12
10
13
module . exports = ( snap , mode ) => {
11
14
let fiberRoot = null ;
@@ -46,13 +49,13 @@ module.exports = (snap, mode) => {
46
49
47
50
function changeUseState ( component ) {
48
51
if ( component . queue . dispatch . linkFiberChanged ) return ;
49
- // store the original dispatch function definition
52
+ // store the original dispatch function definition
50
53
const oldDispatch = component . queue . dispatch . bind ( component . queue ) ;
51
54
// redefine the dispatch function so we can inject our code
52
55
component . queue . dispatch = ( fiber , queue , action ) => {
53
56
// don't do anything if state is locked
54
- if ( mode . locked && ! mode . jumping ) return ;
55
- //oldDispatch(fiber, queue, action);
57
+ if ( mode . locked && ! mode . jumping ) return ;
58
+ // oldDispatch(fiber, queue, action);
56
59
setTimeout ( ( ) => {
57
60
oldDispatch ( fiber , queue , action ) ;
58
61
updateSnapShotTree ( ) ;
@@ -67,17 +70,17 @@ module.exports = (snap, mode) => {
67
70
function traverseHooks ( memoizedState ) {
68
71
// Declare variables and assigned to 0th index and an empty object, respectively
69
72
const memoized = { } ;
70
- let index = 0 ;
71
- astHooks = Object . values ( astHooks ) ;
73
+ let index = 0 ;
74
+ astHooks = Object . values ( astHooks ) ;
72
75
// while memoizedState is truthy, save the value to the object
73
76
while ( memoizedState ) {
74
77
changeUseState ( memoizedState ) ;
75
- //memoized[astHooks[index]] = memoizedState.memoizedState;
76
- memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
78
+ // memoized[astHooks[index]] = memoizedState.memoizedState;
79
+ memoized [ astHooks [ index ] ] = memoizedState . memoizedState ;
77
80
// Reassign memoizedState to its next value
78
81
memoizedState = memoizedState . next ;
79
82
// Increment the index by 2
80
- index += 2 ;
83
+ index += 2 ;
81
84
}
82
85
return memoized ;
83
86
}
@@ -101,8 +104,8 @@ module.exports = (snap, mode) => {
101
104
changeSetState ( stateNode ) ;
102
105
}
103
106
// Check if the component uses hooks
104
- if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
105
- // Add a traversed property and initialize to the evaluated result
107
+ if ( memoizedState && Object . hasOwnProperty . call ( memoizedState , 'baseState' ) ) {
108
+ // Add a traversed property and initialize to the evaluated result
106
109
// of invoking traverseHooks, and reassign nextTree
107
110
memoizedState . traversed = traverseHooks ( memoizedState ) ;
108
111
nextTree = tree . appendChild ( memoizedState ) ;
@@ -114,8 +117,8 @@ module.exports = (snap, mode) => {
114
117
115
118
return tree ;
116
119
}
117
- // runs when page initially loads
118
- // but skips 1st hook click
120
+ // runs when page initially loads
121
+ // but skips 1st hook click
119
122
function updateSnapShotTree ( ) {
120
123
const { current } = fiberRoot ;
121
124
snap . tree = createTree ( current ) ;
@@ -128,16 +131,25 @@ module.exports = (snap, mode) => {
128
131
} = container ;
129
132
// only assign internal rootp if it actually exists
130
133
fiberRoot = _internalRoot || _reactRootContainer ;
131
- // If hooks are implemented, traverse through the source code
134
+ // If hooks are implemented, traverse through the source code
132
135
// Save the getter/setter combo for timeJump
133
136
if ( entryFile ) {
134
137
astHooks = astParser ( entryFile ) ;
135
- saveState ( astHooks ) ;
138
+ // console.log('Ast Hooks', astHooks);
139
+ saveState ( astHooks ) ;
136
140
}
137
- updateSnapShotTree ( ) ;
141
+ updateSnapShotTree ( ) ;
138
142
// send the initial snapshot once the content script has started up
139
143
window . addEventListener ( 'message' , ( { data : { action } } ) => {
140
144
if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
141
145
} ) ;
146
+ // Testing sending back a function def to client
147
+ // function getNextImport(filePath) {
148
+ // return loadable(() => import(`${filePath}`))
149
+ // Got relative file path to return back to client code
150
+ // return (`myTestString${filePath}`);
151
+ // return getNextImport('./UseStateHook');
152
+ // return 'Testing outside';
153
+ // const OtherComponent = loadable(() => import('./OtherComponent'))
142
154
}
143
- } ;
155
+ } ;
0 commit comments