@@ -60,6 +60,7 @@ import Tree from './tree';
60
60
// passes the data down to its components
61
61
import componentActionsRecord from './masterState' ;
62
62
import routes from './routes' ;
63
+ import updateSnapShotTree from './snapShot' ;
63
64
64
65
// throttle returns a function that can be called any number of times (possibly in quick succession) but will only invoke the callback at most once every x ms
65
66
// getHooksNames - helper function to grab the getters/setters from `elementType`
@@ -79,63 +80,8 @@ type ComponentData = {
79
80
[ key : string ] : any ;
80
81
} ;
81
82
82
- const circularComponentTable : Set < Fiber > = new Set ( ) ;
83
83
let rtidCounter = 0 ;
84
84
85
- /**
86
- * @method sendSnapshot
87
- * @param snapShot The current snapshot
88
- * @param mode The current mode (i.e. jumping, time-traveling, or paused)
89
- * @return Nothing.
90
- *
91
- * Middleware: Gets a copy of the current snapShot.tree and posts a recordSnap message to the window
92
- */
93
- function sendSnapshot ( snapShot : Snapshot , mode : Status ) : void {
94
- // Don't send messages while jumping or while paused
95
- if ( mode . jumping || mode . paused ) return ;
96
- // If there is no current tree creates a new one
97
- if ( ! snapShot . tree ) {
98
- snapShot . tree = new Tree ( 'root' , 'root' ) ;
99
- }
100
- // Make a deep copy of the tree:
101
- const payload = snapShot . tree . cleanTreeCopy ( ) ;
102
- payload . route = routes . addRoute ( window . location . href ) ;
103
- // method safely enables cross-origin communication between Window objects;
104
- // e.g., between a page and a pop-up that it spawned, or between a page
105
- // and an iframe embedded within it.
106
- // this postMessage will be sending the most up-to-date snapshot of the current React Fiber Tree
107
- // the postMessage action will be received on the content script to later update the tabsObj
108
- // this will fire off everytime there is a change in test application
109
-
110
- window . postMessage (
111
- {
112
- action : 'recordSnap' ,
113
- payload,
114
- } ,
115
- '*' ,
116
- ) ;
117
- }
118
-
119
- /**
120
- * @function updateSnapShotTree
121
- * @param snapShot The current snapshot
122
- * @param mode The current mode (i.e. jumping, time-traveling, or paused)
123
- * Middleware: Updates snapShot object with latest snapshot, using @sendSnapshot
124
- */
125
- // updating tree depending on current mode on the panel (pause, etc)
126
- function updateSnapShotTree ( snapShot : Snapshot , mode : Status , fiberRoot : FiberRoot ) : void {
127
- // this is the currently active root fiber(the mutable root of the tree)
128
- if ( fiberRoot ) {
129
- const { current } = fiberRoot ;
130
- // Clears circular component table
131
- circularComponentTable . clear ( ) ;
132
- // creates snapshot that is a tree based on properties in fiberRoot object
133
- componentActionsRecord . clear ( ) ;
134
- snapShot . tree = createTree ( current ) ;
135
- }
136
- // sends the updated tree back
137
- sendSnapshot ( snapShot , mode ) ;
138
- }
139
85
140
86
/**
141
87
* @function traverseHooks
@@ -329,8 +275,9 @@ function trimContextData(
329
275
* @param fromSibling A boolean, default initialized to false
330
276
* @return An instance of a Tree object
331
277
*/
332
- function createTree (
278
+ export function createTree (
333
279
currentFiberNode : Fiber ,
280
+ circularComponentTable : Set < Fiber > = new Set ( ) ,
334
281
tree : Tree = new Tree ( 'root' , 'root' ) ,
335
282
fromSibling = false ,
336
283
) : Tree {
@@ -355,22 +302,22 @@ function createTree(
355
302
dependencies,
356
303
_debugHookTypes,
357
304
} = currentFiberNode ;
358
- console . log ( 'LinkFiber' , {
359
- currentFiberNode,
360
- // tag,
361
- // elementType,
362
- componentName :
363
- elementType ?. _context ?. displayName || //For ContextProvider
364
- elementType ?. _result ?. name || //For lazy Component
365
- elementType ?. render ?. name ||
366
- elementType ?. name ||
367
- elementType ,
368
- // memoizedProps,
369
- // memoizedState,
370
- // stateNode,
371
- // dependencies,
372
- // _debugHookTypes,
373
- } ) ;
305
+ // console.log('LinkFiber', {
306
+ // currentFiberNode,
307
+ // // tag,
308
+ // // elementType,
309
+ // componentName:
310
+ // elementType?._context?.displayName || //For ContextProvider
311
+ // elementType?._result?.name || //For lazy Component
312
+ // elementType?.render?.name ||
313
+ // elementType?.name ||
314
+ // elementType,
315
+ // // memoizedProps,
316
+ // // memoizedState,
317
+ // // stateNode,
318
+ // // dependencies,
319
+ // // _debugHookTypes,
320
+ // });
374
321
375
322
// TODO: Understand this if statement
376
323
if ( tag === HostComponent ) {
@@ -556,7 +503,6 @@ function createTree(
556
503
if ( componentFound || newState === 'stateless' ) {
557
504
// Grab JSX Component & replace the 'fromLinkFiber' class value
558
505
if ( currentFiberNode . child ?. stateNode ?. setAttribute ) {
559
- console . log ( elementType . name ) ;
560
506
rtid = `fromLinkFiber${ rtidCounter } ` ;
561
507
// rtid = rtidCounter;
562
508
// check if rtid is already present
@@ -600,13 +546,13 @@ function createTree(
600
546
// so attach children to the newly appended child.
601
547
// Otherwise, attach children to this same node.
602
548
circularComponentTable . add ( child ) ;
603
- createTree ( child , newNode ) ;
549
+ createTree ( child , circularComponentTable , newNode ) ;
604
550
}
605
551
606
552
// Recurse on siblings
607
553
if ( sibling && ! circularComponentTable . has ( sibling ) ) {
608
554
circularComponentTable . add ( sibling ) ;
609
- createTree ( sibling , newNode , true ) ;
555
+ createTree ( sibling , circularComponentTable , newNode , true ) ;
610
556
}
611
557
612
558
// -------------RETURN THE TREE OUTPUT & PASS TO FRONTEND FOR RENDERING-------
@@ -698,7 +644,7 @@ export default function linkFiber(snapShot: Snapshot, mode: Status): () => void
698
644
console . log ( 'linkFiber' , { fiberRoot } ) ;
699
645
700
646
// ----------INITIALIZE THE TREE SNAP SHOT ON CHROME EXTENSION--------------
701
- throttledUpdateSnapshot ( ) ; // only runs on start up
647
+ throttledUpdateSnapshot ( fiberRoot ) ; // only runs on start up
702
648
703
649
// --------MONKEY PATCHING THE onCommitFiberRoot FROM REACT DEV TOOL--------
704
650
// React has inherent methods that are called with react fiber
0 commit comments