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,6 +116,8 @@ 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 ) ;
@@ -123,6 +128,8 @@ module.exports = (snap, mode) => {
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.
@@ -141,6 +148,18 @@ module.exports = (snap, mode) => {
141
148
componentFound = true ;
142
149
} ) ;
143
150
}
151
+ } else {
152
+ console . log ( 'in create tree else' )
153
+ console . log ( 'this is currentFiber from createTree' , currentFiber )
154
+ console . log ( 'this is memoizedState from createTree' , memoizedState )
155
+ // grab stateless components here
156
+ if ( elementType ) {
157
+ if ( elementType . name ) {
158
+ tree . appendChild ( 'stateless' , elementType . name , index ) ;
159
+ } else {
160
+ tree . appendChild ( 'stateless' , elementType , index ) ;
161
+ }
162
+ }
144
163
}
145
164
146
165
// This grabs stateless components
@@ -180,10 +199,58 @@ module.exports = (snap, mode) => {
180
199
return tree ;
181
200
}
182
201
202
+
203
+ // function createUnfilteredTree(curFiber, parentNode) {
204
+ // // on call from updateSnapShot, no parentNode provided, so create a root node
205
+ // if(! parentNode) parentNode = new Tree('root');
206
+
207
+ // // Base case: parentNode's child or sibling pointed to null
208
+ // if (!curFiber) return parentNode;
209
+
210
+ // let newChildNode = null;
211
+
212
+ // // If stateful, add to parentNode's children array, then inject new setState into fiber node
213
+ // if (curFiber.stateNode && curFiber.stateNode.state) {
214
+ // newChildNode = parentNode.appendChild(curFiber.stateNode);
215
+ // // changeSetState(curFiber.stateNode);
216
+ // newChildNode.isStateful = true;
217
+ // }
218
+ // else {
219
+
220
+ // }
221
+
222
+ // // Recurse to sibling; siblings that have state should be added to our parentNode
223
+ // createTree(curFiber.sibling, parentNode);
224
+
225
+ // // Recurse to child; If this fiber was stateful, then we added a newChildNode here, and we want
226
+ // // to attach further children to that. If this fiber wasn't stateful, we want to attach any
227
+ // // children to our existing parentNode.
228
+ // createTree(curFiber.child, newChildNode || parentNode);
229
+
230
+ // return parentNode;
231
+ // }
232
+
233
+
183
234
// ! BUG: skips 1st hook click
184
235
function updateSnapShotTree ( ) {
185
- const { current } = fiberRoot ;
186
- snap . tree = createTree ( current ) ;
236
+ < << << << HEAD
237
+ /* let current;
238
+ // If concurrent mode, grab current.child
239
+ if (concurrent) {
240
+ // we need a way to wait for current child to populate
241
+ const promise = new Promise((resolve, reject) => {
242
+ setTimeout(() => resolve(fiberRoot.current.child), 400);
243
+ });
244
+ current = await promise;
245
+ current = fiberRoot.current.child;
246
+ } else {
247
+ current = fiberRoot.current;
248
+ } */
249
+ const { current } = fiberRoot ; // Carlos: get rid of concurrent mode for now
250
+
251
+ // console.log('FIBER COMMITTED, new fiber is:', util.inspect(current, false, 4));
252
+ // fs.appendFile('fiberlog.txt', util.inspect(current, false, 10));
253
+ snap . tree = createTree ( current ) ; // Carlos: pass new hooks state here?
187
254
}
188
255
189
256
return async container => {
@@ -199,12 +266,14 @@ module.exports = (snap, mode) => {
199
266
fiberRoot = _internalRoot || _reactRootContainer ;
200
267
}
201
268
const devTools = window . __REACT_DEVTOOLS_GLOBAL_HOOK__ ;
269
+ console . log ( 'this is devTools' , devTools )
202
270
const reactInstance = devTools ? devTools . renderers . get ( 1 ) : null ;
203
271
204
272
if ( reactInstance && reactInstance . version ) {
205
273
devTools . onCommitFiberRoot = ( function ( original ) {
206
274
return function ( ...args ) {
207
275
fiberRoot = args [ 1 ] ;
276
+ console . log ( 'this is fiberRoot' , fiberRoot )
208
277
updateSnapShotTree ( ) ;
209
278
sendSnapshot ( ) ;
210
279
return original ( ...args ) ;
@@ -221,3 +290,82 @@ module.exports = (snap, mode) => {
221
290
} ) ;
222
291
} ;
223
292
} ;
293
+
294
+
295
+
296
+
297
+ // function createUnfilteredTree(currentFiber, tree = new Tree('root')) {
298
+ // // Base case: child or sibling pointed to null
299
+ // if (!currentFiber) return tree;
300
+
301
+ // const { sibling, stateNode, child, memoizedState, elementType,
302
+ // tag, actualDuration, actualStartTime, selfBaseDuration, treeBaseDuration,
303
+ // } = currentFiber;
304
+
305
+ // const extraProps = {
306
+ // tag, actualDuration, actualStartTime, selfBaseDuration, treeBaseDuration,
307
+ // };
308
+
309
+ // let nextTree = tree;
310
+ // let nextTreeUnfiltered = unfilteredTreeNode = new UnfilteredTreeNode('root');
311
+
312
+ // // Check if stateful component
313
+ // if (stateNode && stateNode.state) {
314
+ // nextTree = tree.appendChild(stateNode); // Add component to tree
315
+ // changeSetState(stateNode); // Change setState functionality
316
+ // }
317
+ // nextTreeUnfiltered = unfilteredTreeNode.appendChild(stateNode);
318
+
319
+ // // TODO: handle Hooks cases...
320
+
321
+ // // Recurse on siblings
322
+ // createTree(sibling, tree);
323
+ // // Recurse on children
324
+ // createTree(child, nextTree);
325
+
326
+ // return tree;
327
+ // }
328
+
329
+
330
+
331
+ // Check if the component uses hooks
332
+ // if (memoizedState && Object.hasOwnProperty.call(memoizedState, 'baseState')) {
333
+ // // 'catch-all' for suspense elements (experimental)
334
+ // if (typeof elementType.$$typeof === 'symbol') return;
335
+ // // Traverse through the currentFiber and extract the getters/setters
336
+ // astHooks = astParser(elementType);
337
+ // saveState(astHooks);
338
+ // // Create a traversed property and assign to the evaluated result of
339
+ // // invoking traverseHooks with memoizedState
340
+ // memoizedState.traversed = traverseHooks(memoizedState);
341
+ // nextTree = tree.appendChild(memoizedState);
342
+ // }
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+ // function createTree(currentFiber, tree = new Tree('root')) {
352
+ // // Base case: child or sibling pointed to null
353
+ // if (!currentFiber) return tree;
354
+
355
+ // const { sibling, stateNode, child, memoizedState, elementType } = currentFiber;
356
+
357
+ // let nextTree = tree;
358
+
359
+ // // Check if stateful component
360
+ // if (stateNode && stateNode.state) {
361
+ // nextTree = tree.appendChild(stateNode); // Add component to tree
362
+ // changeSetState(stateNode); // Change setState functionality
363
+ // }
364
+
365
+ // // Recurse on siblings
366
+ // createTree(sibling, tree);
367
+ // // Recurse on children
368
+ // createTree(child, nextTree);
369
+
370
+ // return tree;
371
+ // }
0 commit comments