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 ( payload ) ;
16
16
// console.log('payload', payload);
17
17
window . postMessage ( {
18
18
action : 'recordSnap' ,
@@ -103,20 +103,55 @@ module.exports = (snap, mode) => {
103
103
snap . tree = createTree ( current ) ;
104
104
}
105
105
106
- return container => {
107
- // console.log('Container', container);
108
- const {
109
- _reactRootContainer : { _internalRoot } ,
110
- _reactRootContainer,
111
- } = container ;
112
- // console.log('Root container', _reactRootContainer);
113
- // only assign internal root if it actually exists
114
- fiberRoot = _internalRoot || _reactRootContainer ;
115
- updateSnapShotTree ( ) ;
106
+ // return container => {
107
+ // // console.log('Container', container);
108
+ // const {
109
+ // _reactRootContainer: { _internalRoot },
110
+ // _reactRootContainer,
111
+ // } = container;
112
+ // // console.log('Root container', _reactRootContainer);
113
+ // // only assign internal root if it actually exists
114
+ // fiberRoot = _internalRoot || _reactRootContainer;
115
+ // updateSnapShotTree();
116
116
117
- // send the initial snapshot once the content script has started up
118
- window . addEventListener ( 'message' , ( { data : { action } } ) => {
119
- if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
120
- } ) ;
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
+ // };
122
+
123
+ return {
124
+ main ( container ) {
125
+ // console.log('Container', container);
126
+ const {
127
+ _reactRootContainer : { _internalRoot } ,
128
+ _reactRootContainer,
129
+ } = container ;
130
+ // console.log('Root container', _reactRootContainer);
131
+ // only assign internal root if it actually exists
132
+ fiberRoot = _internalRoot || _reactRootContainer ;
133
+ updateSnapShotTree ( ) ;
134
+
135
+ // send the initial snapshot once the content script has started up
136
+ window . addEventListener ( 'message' , ( { data : { action } } ) => {
137
+ if ( action === 'contentScriptStarted' ) sendSnapshot ( ) ;
138
+ } ) ;
139
+ } ,
140
+ changeUseState ( useState ) {
141
+ return function ( initial ) {
142
+ // running the original useState and storing its result (state and dispatch function)
143
+ const toReturn = useState ( initial ) ;
144
+ console . log ( toReturn ) ;
145
+ // storing the original dispatch function definition somewhere
146
+ const oldDispatch = toReturn [ 1 ] ;
147
+ // redefining the dispatch function so we can inject our code
148
+ toReturn [ 1 ] = function ( callback ) {
149
+ oldDispatch ( callback ) ;
150
+ updateSnapShotTree ( ) ;
151
+ sendSnapshot ( ) ;
152
+ } ;
153
+ return toReturn ;
154
+ } ;
155
+ } ,
121
156
} ;
122
- } ;
157
+ } ;
0 commit comments