Skip to content

Commit cffe6e5

Browse files
committed
commiting small changes to pull from Becca's repo
1 parent 528f416 commit cffe6e5

File tree

4 files changed

+41
-40
lines changed

4 files changed

+41
-40
lines changed

src/app/components/AtomsRelationshipLegend.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export default function Legend({ events = false }: { events?: boolean }) {
4848
)}
4949
</LegendOrdinal>
5050
</LegendDemo>
51-
<style jsx>
51+
<style>
5252
{`
5353
.legends {
5454
width: 25%;
@@ -65,7 +65,7 @@ export default function Legend({ events = false }: { events?: boolean }) {
6565
);
6666
}
6767

68-
function LegendDemo({ title, children }: { title: string; children: React.ReactNode }) {
68+
function LegendDemo({ title, children }: { title: string; children: React.reactNode }) {
6969
return (
7070
<div className="legend">
7171
<div className="title">{title}</div>

src/app/components/legend.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import { LegendOrdinal, LegendItem, LegendLabel } from '@visx/legend';
66

77
const legendGlyphSize = 8;
88

9-
type snapHierarchy = {`Record<string, unknown>`}
10-
};
9+
type snapHierarchy = {`Record<string, unknown>`};
1110

1211
export default function LegendKey(props: snapHierarchy) {
1312
const { hierarchy } = props;

src/backend/__tests__/tree.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('Tree unit test', () => {
2929

3030
describe('Adding children', () => {
3131
let newTree = new Tree({});
32-
let returnChild = newTree.addChild('stateful', 'child', {});
32+
let returnChild = newTree.addChild('stateful', 'child', {}, null, null);
3333

3434
it('should be able to add a child', () => {
3535
expect(typeof newTree.children).toEqual('object');
@@ -49,8 +49,8 @@ describe('Tree unit test', () => {
4949

5050
describe('Adding sibling', () => {
5151
let newTree = new Tree({});
52-
let returnChild = newTree.addChild('stateful', 'child', {});
53-
let returnSibling = returnChild.addSibling('stateful', 'child', {});
52+
let returnChild = newTree.addChild('stateful', 'child', {}, null, null);
53+
let returnSibling = returnChild.addSibling('stateful', 'child', {}, null, null);
5454

5555
it('the tree now has 2 children', () => {
5656
expect(newTree.children.length).toBe(2);
@@ -70,8 +70,8 @@ describe('Tree unit test', () => {
7070

7171
describe('Adding sibling', () => {
7272
let newTree = new Tree({});
73-
let returnChild = newTree.addChild('stateful', 'child', {});
74-
let returnSibling = returnChild.addSibling('stateful', 'child', {});
73+
let returnChild = newTree.addChild('stateful', 'child', {}, null, null);
74+
let returnSibling = returnChild.addSibling('stateful', 'child', {}, null, null);
7575
it('the tree now has 2 children', () => {
7676
expect(newTree.children.length).toBe(2);
7777
})
@@ -90,8 +90,8 @@ describe('Tree unit test', () => {
9090

9191
describe('Copy & clean tree', () => {
9292
let newTree = new Tree({});
93-
let returnChild = newTree.addChild('stateful', 'child', {});
94-
let returnSibling = returnChild.addSibling('stateful', 'child', {});
93+
let returnChild = newTree.addChild('stateful', 'child', {}, null, null);
94+
let returnSibling = returnChild.addSibling('stateful', 'child', {}, null, null);
9595
let copy = newTree.cleanTreeCopy();
9696
it('its copy has 2 children', () => {
9797
expect(copy.children.length).toEqual(2);

src/backend/linkFiber.ts

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
2-
/* eslint-disable max-len */
3-
import 'core-js';
4-
/* eslint-disable indent */
5-
/* eslint-disable brace-style */
6-
/* eslint-disable comma-dangle */
7-
/* eslint-disable no-underscore-dangle */
8-
/* eslint-disable func-names */
9-
/* eslint-disable no-use-before-define */
10-
/* eslint-disable no-param-reassign */
1+
// linkFiber checking TYPE of state (stateful, hooks, context, recoil)
2+
// and build current copy of the tree
113

4+
//import typescript types
125
import {
13-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6+
7+
//tree
148
Snapshot,
9+
//jump, pause, lock
1510
Mode,
11+
1612
ComponentData,
13+
// array of state and component
1714
HookStates,
15+
// object with tree structure
1816
Fiber,
1917
} from './types/backendTypes';
18+
//import function that creates a tree
2019
import Tree from './tree';
20+
//passes the data down to its components ?
2121
import componentActionsRecord from './masterState';
22+
23+
// 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
24+
//getHooksNames - helper function to grab the getters/setters from `elementType`
2225
import { throttle, getHooksNames } from './helpers';
2326
import { Console } from 'console';
2427
import AtomsRelationship from '../app/components/AtomsRelationship';
@@ -45,20 +48,6 @@ if (window[`$recoilDebugStates`]) {
4548
isRecoil = true;
4649
}
4750

48-
// function getRecoilState(): any {
49-
// const RecoilSnapshotsLength = window[`$recoilDebugStates`].length;
50-
// const lastRecoilSnapshot =
51-
// window[`$recoilDebugStates`][RecoilSnapshotsLength - 1];
52-
// const nodeToNodeSubs = lastRecoilSnapshot.nodeToNodeSubscriptions;
53-
// const nodeToNodeSubsKeys = lastRecoilSnapshot.nodeToNodeSubscriptions.keys();
54-
// nodeToNodeSubsKeys.forEach((node) => {
55-
// nodeToNodeSubs
56-
// .get(node)
57-
// .forEach((nodeSubs) =>
58-
// allAtomsRelationship.push([node, nodeSubs, 'atoms and selectors'])
59-
// );
60-
// });
61-
// }
6251

6352
/**
6453
* @method sendSnapshot
@@ -71,18 +60,18 @@ if (window[`$recoilDebugStates`]) {
7160
function sendSnapshot(snap: Snapshot, mode: Mode): void {
7261
// Don't send messages while jumping or while paused
7362
if (mode.jumping || mode.paused) return;
63+
// If there is no current tree creates a new one
7464
if (!snap.tree) {
7565
snap.tree = new Tree('root', 'root');
7666
}
7767
const payload = snap.tree.cleanTreeCopy();
78-
68+
// if it's Recoil - run different actions?
7969
if (isRecoil) {
80-
// getRecoilState();
8170
payload.atomsComponents = atomsComponents;
8271
payload.atomSelectors = atomsSelectors;
8372
payload.recoilDomNode = recoilDomNode
8473
}
85-
74+
//method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.
8675
window.postMessage(
8776
{
8877
action: 'recordSnap',
@@ -99,12 +88,18 @@ function sendSnapshot(snap: Snapshot, mode: Mode): void {
9988
* @param mode The current mode (i.e. jumping, time-traveling, locked, or paused)
10089
* Middleware: Updates snap object with latest snapshot, using @sendSnapshot
10190
*/
91+
92+
//updating tree depending on current mode on the panel (pause, locked etc)
10293
function updateSnapShotTree(snap: Snapshot, mode: Mode): void {
94+
//Every React application has one or more DOM elements that act as containers. React creates a fiber root object for each of those containers. This fiber root is where React holds the reference to a fiber tree. It is stored in the current property of the fiber root
10395
if (fiberRoot) {
10496
const { current } = fiberRoot;
97+
//Clears circular component table
10598
circularComponentTable.clear();
99+
//creates snapshot that is a tree based on properties in fiberRoot object
106100
snap.tree = createTree(current);
107101
}
102+
//sends the updated tree back
108103
sendSnapshot(snap, mode);
109104
}
110105

@@ -114,8 +109,12 @@ function updateSnapShotTree(snap: Snapshot, mode: Mode): void {
114109
* @param memoizedProps Property containing props on a stateful fctnl component's FiberNode object
115110
* @return An array of array of HookStateItem objects (state and component properties)
116111
*/
112+
113+
// if type of state - Recoil hooks
117114
function traverseRecoilHooks(
115+
//State of the fiber that was used to create the output. When processing updates it reflects the state that’s currently rendered on the screen.
118116
memoizedState: any,
117+
//Props of the fiber that were used to create the output during the previous render.
119118
memoizedProps: any
120119
): HookStates {
121120
const hooksStates: HookStates = [];
@@ -177,6 +176,8 @@ function traverseHooks(memoizedState: any): HookStates {
177176
let atomsSelectors = {};
178177
let atomsComponents = {};
179178

179+
// Every time a state change is made in the accompanying app, the extension creates a
180+
// Tree “snapshot” of the current state, and adds it to the current “cache” of snapshots in the extension
180181
function createTree(
181182
currentFiber: Fiber,
182183
tree: Tree = new Tree('root', 'root'),
@@ -195,6 +196,7 @@ function createTree(
195196
sibling,
196197
stateNode,
197198
child,
199+
//with memoizedState we can grab the root type and construct an Abstract Syntax Tree from the hooks structure using Acorn in order to extract the hook getters and match them with their corresponding setters in an object
198200
memoizedState,
199201
memoizedProps,
200202
elementType,
@@ -476,7 +478,7 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
476478
if (reactInstance && reactInstance.version) {
477479
devTools.onCommitFiberRoot = (function (original) {
478480
return function (...args) {
479-
// eslint-disable-next-line prefer-destructuring
481+
480482
fiberRoot = args[1];
481483
if (doWork) {
482484
throttledUpdateSnapshot();

0 commit comments

Comments
 (0)