1
+ /* eslint-disable func-names */
1
2
/* eslint-disable no-use-before-define */
2
3
/* eslint-disable no-param-reassign */
3
4
// links component state tree to library
@@ -12,7 +13,6 @@ module.exports = (snap, mode) => {
12
13
// DEV: So that when we are jumping to an old snapshot it wouldn't think we want to create new snapshots
13
14
if ( mode . jumping || mode . paused ) return ;
14
15
const payload = snap . tree . getCopy ( ) ;
15
- console . log ( 'Here is the payload:' , payload ) ;
16
16
// console.log('payload', payload);
17
17
window . postMessage ( {
18
18
action : 'recordSnap' ,
@@ -56,7 +56,7 @@ module.exports = (snap, mode) => {
56
56
// while memoizedState is truthy, save the value to the object
57
57
while ( memoizedState ) {
58
58
// Increment the index by 1
59
- memoizedObj [ `useState ${ index += 1 } ` ] = memoizedState . memoizedState ;
59
+ memoizedObj [ `state ${ index += 1 } ` ] = memoizedState . memoizedState ;
60
60
// Reassign memoizedState to its next value
61
61
memoizedState = memoizedState . next ;
62
62
}
@@ -87,37 +87,83 @@ module.exports = (snap, mode) => {
87
87
if ( memoizedState && memoizedState . hasOwnProperty ( 'baseState' ) ) {
88
88
// console.log('The memoizedState is: ', memoizedState)
89
89
90
- const result = traverseHooks ( memoizedState ) ;
91
- nextTree = tree . appendChild ( result ) ;
90
+ const traversed = traverseHooks ( memoizedState ) ;
91
+ nextTree = tree . appendChild ( traversed ) ;
92
92
}
93
93
94
94
// iterate through siblings
95
95
createTree ( sibling , tree ) ;
96
96
// iterate through children
97
97
createTree ( child , nextTree ) ;
98
- console . log ( 'this is the tree after being traversed' , tree )
98
+
99
99
return tree ;
100
100
}
101
101
102
102
function updateSnapShotTree ( ) {
103
-
104
103
const { current } = fiberRoot ;
105
104
snap . tree = createTree ( current ) ;
106
105
}
106
+ // return container => {
107
+ // console.log('this is the container', container)
108
+ // const {
109
+ // _reactRootContainer: { _internalRoot },
110
+ // _reactRootContainer,
111
+ // } = container;
112
+ // // only assign internal root if it actually exists
113
+ // fiberRoot = _internalRoot || _reactRootContainer;
114
+ // console.log('fiberRoot', fiberRoot);
115
+ // updateSnapShotTree();
107
116
108
- return container => {
109
- const {
110
- _reactRootContainer : { _internalRoot } ,
111
- _reactRootContainer,
112
- } = container ;
113
- // only assign internal root if it actually exists
114
- fiberRoot = _internalRoot || _reactRootContainer ;
115
- console . log ( 'here is the fiberRoot' , fiberRoot )
116
- updateSnapShotTree ( ) ;
117
+ // // send the initial snapshot once the content script has started up
118
+ // window.addEventListener('message', ({ data: { action } }) => {
119
+ // if (action === 'contentScriptStarted') sendSnapshot();
120
+ // });
121
+ // };
117
122
118
- // send the initial snapshot once the content script has started up
119
- window . addEventListener ( 'message' , ( { data : { action } } ) => {
120
- if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
121
- } ) ;
123
+ return {
124
+ _ ( container ) {
125
+ const {
126
+ _reactRootContainer : { _internalRoot } ,
127
+ _reactRootContainer,
128
+ } = container ;
129
+ // only assign internal root if it actually exists
130
+ fiberRoot = _internalRoot || _reactRootContainer ;
131
+ updateSnapShotTree ( ) ;
132
+ // send the initial snapshot once the content script has started up
133
+ window . addEventListener ( 'message' , ( { data : { action } } ) => {
134
+ if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
135
+ } ) ;
136
+ } ,
137
+ testUseState ( useState ) {
138
+ return function ( initial ) {
139
+ // running the original useState and storing its result (state and dispatch function)
140
+ const toReturn = useState ( initial ) ;
141
+ // storing the original dispatch function definition somewhere
142
+ const oldDispatch = toReturn [ 1 ] ;
143
+ // redefining the dispatch function so we can inject our code
144
+ toReturn [ 1 ] = function ( newVal ) {
145
+ oldDispatch ( newVal ) ;
146
+ updateSnapShotTree ( ) ;
147
+ sendSnapshot ( ) ;
148
+ } ;
149
+ return toReturn ;
150
+ } ;
151
+ } ,
152
+ testUseReducer ( useReducer ) {
153
+ return function ( reducer , initialState , init ) {
154
+ // Declare a constant and initialize to the built-in useReducer method
155
+ // Which returns an array with the state and dispatch
156
+ const reduced = useReducer ( reducer , initialState , init ) ;
157
+ // Save the dispatch method
158
+ const oldDispatch = reduced [ 1 ] ;
159
+ // reassign the dispatch method with the additional methods
160
+ reduced [ 1 ] = function ( type ) {
161
+ oldDispatch ( type ) ;
162
+ updateSnapShotTree ( ) ;
163
+ sendSnapshot ( ) ;
164
+ }
165
+ return reduced ;
166
+ }
167
+ } ,
122
168
} ;
123
- } ;
169
+ } ;
0 commit comments