47
47
// const Tree = require('./tree').default;
48
48
// const componentActionsRecord = require('./masterState');\
49
49
50
+ const DEBUG_MODE = false ;
51
+
52
+ const alwaysLog = console . log ;
53
+
54
+ console . log = ( original => {
55
+ return ( ...args ) => {
56
+ if ( DEBUG_MODE ) original ( ...args ) ;
57
+ }
58
+ } ) ( console . log ) ;
59
+
50
60
import Tree from './tree' ;
51
61
import componentActionsRecord from './masterState' ;
52
62
@@ -57,6 +67,7 @@ export default (snap, mode) => {
57
67
let fiberRoot = null ;
58
68
59
69
function sendSnapshot ( ) {
70
+ alwaysLog ( 'sendSnapshot called' ) ;
60
71
// Don't send messages while jumping or while paused
61
72
circularComponentTable . clear ( ) ;
62
73
// console.log('sending snapshot');
@@ -105,7 +116,7 @@ export default (snap, mode) => {
105
116
//
106
117
function createTree ( currentFiber , tree = new Tree ( 'root' , 'root' ) , fromSibling = false ) {
107
118
// Base case: child or sibling pointed to null
108
- // console.log('linkFiber.js : creating tree');
119
+ console . log ( 'createTree : creating tree' ) ;
109
120
if ( ! currentFiber ) return null ;
110
121
if ( ! tree ) return tree ;
111
122
@@ -129,10 +140,10 @@ export default (snap, mode) => {
129
140
let componentFound = false ;
130
141
131
142
// Check if node is a stateful setState component
132
- if ( stateNode && stateNode . state && ( tag === 0 || tag === 1 || tag === 2 ) ) {
143
+ if ( stateNode && stateNode . state && ( tag === 0 || tag === 1 ) ) { // { || tag === 2)) {
133
144
// Save component's state and setState() function to our record for future
134
145
// time-travel state changing. Add record index to snapshot so we can retrieve.
135
- // console.log('linkFiber.js: found stateNode component');
146
+ console . log ( 'createTree() found setState component' ) ;
136
147
componentData . index = componentActionsRecord . saveNew ( stateNode . state , stateNode ) ;
137
148
newState = stateNode . state ;
138
149
componentFound = true ;
@@ -142,7 +153,7 @@ export default (snap, mode) => {
142
153
let hooksIndex ;
143
154
if ( memoizedState && ( tag === 0 || tag === 1 || tag === 10 ) ) {
144
155
if ( memoizedState . queue ) {
145
- // console.log('linkFiber.js: found hooks component');
156
+ console . log ( 'createTree() found hooks component' ) ;
146
157
// Hooks states are stored as a linked list using memoizedState.next,
147
158
// so we must traverse through the list and get the states.
148
159
// We then store them along with the corresponding memoizedState.queue,
@@ -163,7 +174,7 @@ export default (snap, mode) => {
163
174
}
164
175
165
176
// This grabs stateless components
166
- if ( ! componentFound && ( tag === 0 || tag === 1 || tag === 2 ) ) {
177
+ if ( ! componentFound && ( tag === 0 || tag === 1 ) ) { // || tag === 2)) {
167
178
newState = 'stateless' ;
168
179
}
169
180
@@ -179,15 +190,18 @@ export default (snap, mode) => {
179
190
let newNode = null ;
180
191
if ( componentFound || newState === 'stateless' ) {
181
192
if ( fromSibling ) {
182
- newNode = tree . addSibling ( newState ,
183
- elementType . name ? elementType . name : elementType ,
193
+ console . log ( 'createTree(), relevant component found in sibling' ) ;
194
+ newNode = tree . addSibling ( newState ,
195
+ elementType ? elementType . name : 'nameless' ,
184
196
componentData ) ;
185
197
} else {
186
- newNode = tree . addChild ( newState ,
187
- elementType . name ? elementType . name : elementType ,
198
+ console . log ( 'createTree(), relevant component found in child' ) ;
199
+ newNode = tree . addChild ( newState ,
200
+ elementType ? elementType . name : 'nameless' ,
188
201
componentData ) ;
189
202
}
190
203
} else {
204
+ console . log ( 'createTree(), no new relevant nodes, continuing from same node' )
191
205
newNode = tree ;
192
206
}
193
207
@@ -197,33 +211,34 @@ export default (snap, mode) => {
197
211
// If this node had state we appended to the children array,
198
212
// so attach children to the newly appended child.
199
213
// Otherwise, attach children to this same node.
200
- // console.log('going into child');
214
+ console . log ( 'going into child' ) ;
201
215
// circularComponentTable.set(child, true);
202
216
createTree ( child , newNode ) ;
203
217
}
204
218
// Recurse on siblings
205
219
if ( sibling ) { // && !circularComponentTable.has(sibling)) {
206
- // console.log('going into sibling');
220
+ console . log ( 'going into sibling' ) ;
207
221
// circularComponentTable.set(sibling, true);
208
222
createTree ( sibling , newNode , true ) ;
209
223
}
210
224
211
- // console.log('linkFiber.js: processed children and sibling, returning tree');
225
+ // // console.log('linkFiber.js: processed children and sibling, returning tree');
212
226
return tree ;
213
227
}
214
228
215
229
function updateSnapShotTree ( ) {
216
- // console.log('linkFiber.js, updateSnapshotTree(), checking if fiberRoot updated');
230
+ // console.log('updateSnapshotTree(), checking if fiberRoot updated');
217
231
if ( fiberRoot ) {
218
- // console.log('linkFiber.js, updateSnapshotTree(), updating snapshot', snap.tree);
232
+ console . log ( 'updateSnapshotTree(), updating snapshot' , snap . tree ) ;
219
233
const { current } = fiberRoot ;
220
234
snap . tree = createTree ( current ) ;
221
- // console.log('linkFiber.js, updateSnapshotTree(), completed snapshot', snap.tree);
235
+ console . log ( 'updateSnapshotTree(), completed snapshot' , snap . tree ) ;
222
236
}
223
237
}
224
238
225
239
return async ( ) => {
226
240
241
+ /*
227
242
const container = document.getElementById('root');
228
243
if (container._internalRoot) {
229
244
fiberRoot = container._internalRoot;
@@ -234,18 +249,21 @@ export default (snap, mode) => {
234
249
} = container;
235
250
// Only assign internal root if it actually exists
236
251
fiberRoot = _internalRoot || _reactRootContainer;
237
- }
252
+ }*/
238
253
239
254
const devTools = window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
240
255
const reactInstance = devTools ? devTools . renderers . get ( 1 ) : null ;
241
256
242
- //console.log('fiberRoot retrieved:', fiberRoot);
257
+ //// console.log('fiberRoot retrieved:', fiberRoot);
243
258
if ( reactInstance && reactInstance . version ) {
244
259
devTools . onCommitFiberRoot = ( function ( original ) {
245
260
return function ( ...args ) {
246
261
fiberRoot = args [ 1 ] ;
262
+ //console.log('Fiber committed, updating snapshot tree with:', fiberRoot);
247
263
updateSnapShotTree ( ) ;
264
+ console . log ( 'Fiber committed, sending latest snapshot' ) ;
248
265
sendSnapshot ( ) ;
266
+ console . log ( 'Fiber committed, latest snapshot sent' ) ;
249
267
return original ( ...args ) ;
250
268
} ;
251
269
} ( devTools . onCommitFiberRoot ) ) ;
0 commit comments