You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 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
-
// getHooksNames - helper function to grab the getters/setters from `elementType`
// -------------------------CREATE TREE TO SEND TO FRONT END--------------------
83
48
/**
@@ -95,7 +60,7 @@ declare global {
95
60
// TODO: Not sure why the ritd need to be outside of the createTree function. Want to put inside, but in case this need to be keep track for front end.
96
61
letrtidCounter=0;
97
62
98
-
exportfunctioncreateTree(
63
+
exportdefaultfunctioncreateTree(
99
64
currentFiberNode: Fiber,
100
65
circularComponentTable: Set<Fiber>=newSet(),
101
66
tree: Tree=newTree('root','root'),
@@ -366,114 +331,3 @@ export function createTree(
366
331
// -------------RETURN THE TREE OUTPUT & PASS TO FRONTEND FOR RENDERING-------
367
332
returntree;
368
333
}
369
-
370
-
/**
371
-
* linkFiber contains core module functionality, exported as an anonymous function, perform the following logic:
372
-
* 1. Check if React Dev Tool is installed.
373
-
* 2. Check if the target application (on the browser) is a valid react application.
374
-
* 3. Initiate a event listener for visibility update of the target React Applicaiton.
375
-
* 4. Obtain the initial fiberRootNode, which is the root node of a tree of React component.
376
-
* 5. Initialize the tree snapShot on Chrome Extension.
377
-
* 6. Monkey patching the onCommitFiberRoot from REACT DEV TOOL to obtain updated data after React Applicaiton is re-rendered.
378
-
* @param snapShot The current snapshot
379
-
* @param mode The current mode (i.e. jumping, time-traveling, or paused)
380
-
* @return a function to be invoked by index.js that initiates snapshot monitoring
* A boolean value indicate if the target React Application is visible
385
-
*/
386
-
letisVisible: boolean=true;
387
-
/**
388
-
* The `fiberRootNode`, which is the root node of a tree of React component.
389
-
* The `current` property of `fiberRoot` has data structure of a Tree, which can be used to traverse and obtain all child component data.
390
-
*/
391
-
letfiberRoot: FiberRoot;
392
-
/**
393
-
* @constant MIN_TIME_BETWEEN_UPDATE - The minimum time (ms) between each re-render/update of the snapShot tree being displayed on the Chrome Extension.
394
-
*/
395
-
constMIN_TIME_BETWEEN_UPDATE=10;
396
-
/**
397
-
* @function throttledUpdateSnapshot - a function that will wait for at least MIN_TIME_BETWEEN_UPDATE ms, before updating the tree snapShot being displayed on the Chrome Extension.
// react devtools global hook is a global object that was injected by the React Devtools content script, allows access to fiber nodes and react version
// If target application is not a React App, this will return undefined.
428
-
if(!reactInstance){
429
-
return;
430
-
}
431
-
// If target application is a React App, send a message to front end.
432
-
window.postMessage(
433
-
{
434
-
action: 'aReactApp',
435
-
payload: 'aReactApp',
436
-
},
437
-
'*',
438
-
);
439
-
// --------------INITIATE EVENT LISTENER FOR VISIBILITY CHANGE--------------
440
-
/**
441
-
* Initiate an event listener for when there is a change to the visibility of the react target application (the browser tab)
442
-
* @example If tic-tac-toe demo app is loaded on a tab with localhost:8080, whenever user switch tab or switch to another software => 'visibilityChange' => invoke the callback to update doWork boolean value
// ----------INITIALIZE THE TREE SNAP SHOT ON CHROME EXTENSION--------------
455
-
throttledUpdateSnapshot(fiberRoot);// only runs on start up
456
-
457
-
// --------MONKEY PATCHING THE onCommitFiberRoot FROM REACT DEV TOOL--------
458
-
// React has inherent methods that are called with react fiber
459
-
// One of which is the onCommitFiberRoot method, which is invoked after the React application re-render its component(s).
460
-
// we attach new functionality without compromising the original work that onCommitFiberRoot does
461
-
/**
462
-
* @param onCommitFiberRoot - is a callback provided by React that is automatically invoked by React Fiber after the target React application re-renders its components. This callback is used by REACT DEV TOOL to receive updated data about the component tree and its state. See {@link https://medium.com/@aquinojardim/react-fiber-reactime-4-0-f200f02e7fa8}
463
-
* @returns an anonymous function, which will have the same parameters as onCommitFiberRoot and when invoked will update the fiberRoot value & post a request to update the snapShot tree on Chrome Extension
0 commit comments