33/* eslint-disable no-param-reassign */
44// links component state tree to library
55// changes the setState method to also update our snapshot
6+
7+ // import loadable from '@loadable/component';
8+
69const Tree = require ( './tree' ) ;
7- const astParser = require ( './astParser' ) ;
8- const { saveState } = require ( './masterState' ) ;
10+ const astParser = require ( './astParser' ) ;
11+ const { saveState } = require ( './masterState' ) ;
912
1013module . exports = ( snap , mode ) => {
1114 let fiberRoot = null ;
@@ -46,13 +49,13 @@ module.exports = (snap, mode) => {
4649
4750 function changeUseState ( component ) {
4851 if ( component . queue . dispatch . linkFiberChanged ) return ;
49- // store the original dispatch function definition
52+ // store the original dispatch function definition
5053 const oldDispatch = component . queue . dispatch . bind ( component . queue ) ;
5154 // redefine the dispatch function so we can inject our code
5255 component . queue . dispatch = ( fiber , queue , action ) => {
5356 // 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);
5659 setTimeout ( ( ) => {
5760 oldDispatch ( fiber , queue , action ) ;
5861 updateSnapShotTree ( ) ;
@@ -67,17 +70,17 @@ module.exports = (snap, mode) => {
6770 function traverseHooks ( memoizedState ) {
6871 // Declare variables and assigned to 0th index and an empty object, respectively
6972 const memoized = { } ;
70- let index = 0 ;
71- astHooks = Object . values ( astHooks ) ;
73+ let index = 0 ;
74+ astHooks = Object . values ( astHooks ) ;
7275 // while memoizedState is truthy, save the value to the object
7376 while ( memoizedState ) {
7477 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 ;
7780 // Reassign memoizedState to its next value
7881 memoizedState = memoizedState . next ;
7982 // Increment the index by 2
80- index += 2 ;
83+ index += 2 ;
8184 }
8285 return memoized ;
8386 }
@@ -101,8 +104,8 @@ module.exports = (snap, mode) => {
101104 changeSetState ( stateNode ) ;
102105 }
103106 // 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
106109 // of invoking traverseHooks, and reassign nextTree
107110 memoizedState . traversed = traverseHooks ( memoizedState ) ;
108111 nextTree = tree . appendChild ( memoizedState ) ;
@@ -114,8 +117,8 @@ module.exports = (snap, mode) => {
114117
115118 return tree ;
116119 }
117- // runs when page initially loads
118- // but skips 1st hook click
120+ // runs when page initially loads
121+ // but skips 1st hook click
119122 function updateSnapShotTree ( ) {
120123 const { current } = fiberRoot ;
121124 snap . tree = createTree ( current ) ;
@@ -128,16 +131,25 @@ module.exports = (snap, mode) => {
128131 } = container ;
129132 // only assign internal rootp if it actually exists
130133 fiberRoot = _internalRoot || _reactRootContainer ;
131- // If hooks are implemented, traverse through the source code
134+ // If hooks are implemented, traverse through the source code
132135 // Save the getter/setter combo for timeJump
133136 if ( entryFile ) {
134137 astHooks = astParser ( entryFile ) ;
135- saveState ( astHooks ) ;
138+ // console.log('Ast Hooks', astHooks);
139+ saveState ( astHooks ) ;
136140 }
137- updateSnapShotTree ( ) ;
141+ updateSnapShotTree ( ) ;
138142 // send the initial snapshot once the content script has started up
139143 window . addEventListener ( 'message' , ( { data : { action } } ) => {
140144 if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
141145 } ) ;
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'))
142154 }
143- } ;
155+ } ;
0 commit comments