1
+ /* eslint-disable indent */
2
+ /* eslint-disable brace-style */
3
+ /* eslint-disable comma-dangle */
1
4
/**
2
5
* This file contains core module functionality.
3
6
*
@@ -113,16 +116,20 @@ module.exports = (snap, mode) => {
113
116
114
117
// Check if node is a stateful setState component
115
118
if ( stateNode && stateNode . state && ( tag === 0 || tag === 1 ) ) {
119
+ console . log ( 'in create tree if' )
120
+ console . log ( 'this is currentFiber from createTree' , currentFiber )
116
121
// Save component's state and setState() function to our record for future
117
122
// time-travel state changing. Add record index to snapshot so we can retrieve.
118
123
componentData . index = componentActionsRecord . saveNew ( stateNode . state , stateNode ) ;
119
- newState . state = stateNode . state ;
124
+ newState = stateNode . state ;
120
125
componentFound = true ;
121
126
}
122
127
123
128
// Check if node is a hooks useState function
124
129
let hooksIndex ;
125
130
if ( memoizedState && ( tag === 0 || tag === 1 || tag === 10 ) ) {
131
+ console . log ( 'in create tree if' )
132
+ console . log ( 'this is currentFiber from createTree' , currentFiber )
126
133
if ( memoizedState . queue ) {
127
134
// Hooks states are stored as a linked list using memoizedState.next,
128
135
// so we must traverse through the list and get the states.
@@ -180,10 +187,57 @@ module.exports = (snap, mode) => {
180
187
return tree ;
181
188
}
182
189
190
+
191
+ // function createUnfilteredTree(curFiber, parentNode) {
192
+ // // on call from updateSnapShot, no parentNode provided, so create a root node
193
+ // if(! parentNode) parentNode = new Tree('root');
194
+
195
+ // // Base case: parentNode's child or sibling pointed to null
196
+ // if (!curFiber) return parentNode;
197
+
198
+ // let newChildNode = null;
199
+
200
+ // // If stateful, add to parentNode's children array, then inject new setState into fiber node
201
+ // if (curFiber.stateNode && curFiber.stateNode.state) {
202
+ // newChildNode = parentNode.appendChild(curFiber.stateNode);
203
+ // // changeSetState(curFiber.stateNode);
204
+ // newChildNode.isStateful = true;
205
+ // }
206
+ // else {
207
+
208
+ // }
209
+
210
+ // // Recurse to sibling; siblings that have state should be added to our parentNode
211
+ // createTree(curFiber.sibling, parentNode);
212
+
213
+ // // Recurse to child; If this fiber was stateful, then we added a newChildNode here, and we want
214
+ // // to attach further children to that. If this fiber wasn't stateful, we want to attach any
215
+ // // children to our existing parentNode.
216
+ // createTree(curFiber.child, newChildNode || parentNode);
217
+
218
+ // return parentNode;
219
+ // }
220
+
221
+
183
222
// ! BUG: skips 1st hook click
184
223
function updateSnapShotTree ( ) {
185
- const { current } = fiberRoot ;
186
- snap . tree = createTree ( current ) ;
224
+ /* let current;
225
+ // If concurrent mode, grab current.child
226
+ if (concurrent) {
227
+ // we need a way to wait for current child to populate
228
+ const promise = new Promise((resolve, reject) => {
229
+ setTimeout(() => resolve(fiberRoot.current.child), 400);
230
+ });
231
+ current = await promise;
232
+ current = fiberRoot.current.child;
233
+ } else {
234
+ current = fiberRoot.current;
235
+ } */
236
+ const { current } = fiberRoot ; // Carlos: get rid of concurrent mode for now
237
+
238
+ // console.log('FIBER COMMITTED, new fiber is:', util.inspect(current, false, 4));
239
+ // fs.appendFile('fiberlog.txt', util.inspect(current, false, 10));
240
+ snap . tree = createTree ( current ) ; // Carlos: pass new hooks state here?
187
241
}
188
242
189
243
return async container => {
@@ -199,12 +253,14 @@ module.exports = (snap, mode) => {
199
253
fiberRoot = _internalRoot || _reactRootContainer ;
200
254
}
201
255
const devTools = window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
256
+ console . log ( 'this is devTools' , devTools )
202
257
const reactInstance = devTools ? devTools . renderers . get ( 1 ) : null ;
203
258
204
259
if ( reactInstance && reactInstance . version ) {
205
260
devTools . onCommitFiberRoot = ( function ( original ) {
206
261
return function ( ...args ) {
207
262
fiberRoot = args [ 1 ] ;
263
+ console . log ( 'this is fiberRoot' , fiberRoot )
208
264
updateSnapShotTree ( ) ;
209
265
sendSnapshot ( ) ;
210
266
return original ( ...args ) ;
@@ -221,3 +277,82 @@ module.exports = (snap, mode) => {
221
277
} ) ;
222
278
} ;
223
279
} ;
280
+
281
+
282
+
283
+
284
+ // function createUnfilteredTree(currentFiber, tree = new Tree('root')) {
285
+ // // Base case: child or sibling pointed to null
286
+ // if (!currentFiber) return tree;
287
+
288
+ // const { sibling, stateNode, child, memoizedState, elementType,
289
+ // tag, actualDuration, actualStartTime, selfBaseDuration, treeBaseDuration,
290
+ // } = currentFiber;
291
+
292
+ // const extraProps = {
293
+ // tag, actualDuration, actualStartTime, selfBaseDuration, treeBaseDuration,
294
+ // };
295
+
296
+ // let nextTree = tree;
297
+ // let nextTreeUnfiltered = unfilteredTreeNode = new UnfilteredTreeNode('root');
298
+
299
+ // // Check if stateful component
300
+ // if (stateNode && stateNode.state) {
301
+ // nextTree = tree.appendChild(stateNode); // Add component to tree
302
+ // changeSetState(stateNode); // Change setState functionality
303
+ // }
304
+ // nextTreeUnfiltered = unfilteredTreeNode.appendChild(stateNode);
305
+
306
+ // // TODO: handle Hooks cases...
307
+
308
+ // // Recurse on siblings
309
+ // createTree(sibling, tree);
310
+ // // Recurse on children
311
+ // createTree(child, nextTree);
312
+
313
+ // return tree;
314
+ // }
315
+
316
+
317
+
318
+ // Check if the component uses hooks
319
+ // if (memoizedState && Object.hasOwnProperty.call(memoizedState, 'baseState')) {
320
+ // // 'catch-all' for suspense elements (experimental)
321
+ // if (typeof elementType.$$typeof === 'symbol') return;
322
+ // // Traverse through the currentFiber and extract the getters/setters
323
+ // astHooks = astParser(elementType);
324
+ // saveState(astHooks);
325
+ // // Create a traversed property and assign to the evaluated result of
326
+ // // invoking traverseHooks with memoizedState
327
+ // memoizedState.traversed = traverseHooks(memoizedState);
328
+ // nextTree = tree.appendChild(memoizedState);
329
+ // }
330
+
331
+
332
+
333
+
334
+
335
+
336
+
337
+
338
+ // function createTree(currentFiber, tree = new Tree('root')) {
339
+ // // Base case: child or sibling pointed to null
340
+ // if (!currentFiber) return tree;
341
+
342
+ // const { sibling, stateNode, child, memoizedState, elementType } = currentFiber;
343
+
344
+ // let nextTree = tree;
345
+
346
+ // // Check if stateful component
347
+ // if (stateNode && stateNode.state) {
348
+ // nextTree = tree.appendChild(stateNode); // Add component to tree
349
+ // changeSetState(stateNode); // Change setState functionality
350
+ // }
351
+
352
+ // // Recurse on siblings
353
+ // createTree(sibling, tree);
354
+ // // Recurse on children
355
+ // createTree(child, nextTree);
356
+
357
+ // return tree;
358
+ // }
0 commit comments