Skip to content

Commit 034fa73

Browse files
authored
Merge pull request #7 from oslabs-beta/everyone/filter
Everyone/filter
2 parents 18ae98f + 3e003f6 commit 034fa73

File tree

5 files changed

+115
-27
lines changed

5 files changed

+115
-27
lines changed

src/app/components/ComponentMap.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ export default function ComponentMap({
133133
return `${time} ms `;
134134
};
135135

136-
//put all nodes into an array
136+
//places all nodes into a flat array
137137
const nodeList = [];
138138

139139
const collectNodes = (node) => {
140140
nodeList.splice(0, nodeList.length);
141+
console.log("Root node:", node);
141142
nodeList.push(node);
142143
for (let i = 0; i < nodeList.length; i++) {
143144
const cur = nodeList[i];
@@ -345,6 +346,10 @@ export default function ComponentMap({
345346
State:
346347
{tooltipData.state}
347348
</div>
349+
<div>
350+
Props:
351+
{JSON.stringify(tooltipData.componentData.props)}
352+
</div>
348353
<div>
349354
{' '}
350355
Render time:

src/app/components/LinkControls.tsx

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type Props = {
3333
const nodeList = [];
3434

3535
const collectNodes = (node) => {
36-
nodeList.splice(0, nodeList.length);
36+
console.log("This is the root node", node);
37+
nodeList.splice(0, nodeList.length); { /* We used the .splice method here to ensure that nodeList did not accumulate with page refreshes */ }
3738
nodeList.push(node);
3839
for (let i = 0; i < nodeList.length; i++) {
3940
const cur = nodeList[i];
@@ -44,7 +45,6 @@ const collectNodes = (node) => {
4445
}
4546
}
4647
console.log('NODELIST looks like: ', nodeList);
47-
4848
}
4949

5050
export default function LinkControls({
@@ -72,7 +72,7 @@ export default function LinkControls({
7272
<select
7373
onClick={e => e.stopPropagation()}
7474
onChange={e => setLayout(e.target.value)}
75-
value={layout}
75+
// value={layout}
7676
style={dropDownStyle}
7777
>
7878
<option value="cartesian">Cartesian</option>
@@ -86,7 +86,7 @@ export default function LinkControls({
8686
<select
8787
onClick={e => e.stopPropagation()}
8888
onChange={e => setOrientation(e.target.value)}
89-
value={orientation}
89+
// value={orientation}/
9090
disabled={layout === 'polar'}
9191
style={dropDownStyle}
9292
>
@@ -101,7 +101,7 @@ export default function LinkControls({
101101
<select
102102
onClick={e => e.stopPropagation()}
103103
onChange={e => setLinkType(e.target.value)}
104-
value={linkType}
104+
// value={linkType}
105105
style={dropDownStyle}
106106
>
107107
<option value="diagonal">Diagonal</option>
@@ -111,23 +111,17 @@ export default function LinkControls({
111111

112112
{/* Controls for the select selections. */}
113113
<label>Select:</label>
114-
&nbsp;
115-
<select
116-
onClick={e => e.stopPropagation()}
114+
&nbsp; {/*This is a non-breaking space - Prevents an automatic line break at this position */}
115+
<input list='nodeOptions' type='text' name="nodeOptions"
117116
onChange={e => {
118-
const val = e.target.value;
119-
console.log("You selected: ", val);
120117
setSelectedNode(e.target.value)
121118
}}
122-
value={selectedNode}
123-
style={dropDownStyle}
124-
>
125-
{console.log("snapShots: ", snapShots)}
126-
119+
/>
120+
<datalist id='nodeOptions'>
127121
{nodeList.map(node => (
128122
<option value={node.name}>{node.name}</option>
129123
))}
130-
</select>
124+
</datalist>
131125

132126
{/* This is the slider control for the step option */}
133127
{linkType === 'step' && layout !== 'polar' && (

src/backend/linkFiber.ts

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ function traverseHooks(memoizedState: any): HookStates {
197197

198198
/**
199199
* @method createTree
200-
* @param currentFiber A Fiber object dajshdgajshdgajshdgasjh
200+
* @param currentFiber A Fiber object
201201
* @param tree A Tree object, default initialized to an instance given 'root' and 'root'
202202
* @param fromSibling A boolean, default initialized to false
203203
* @return An instance of a Tree object
@@ -210,6 +210,24 @@ function traverseHooks(memoizedState: any): HookStates {
210210
let atomsSelectors = {};
211211
let atomsComponents = {};
212212

213+
function convertFunctionToString(obj: {}) {
214+
const newPropData = {};
215+
// const newPropData = Array.isArray(obj) === true ? {} : [];
216+
for (const key in obj) {
217+
if (typeof obj[key] === 'function') {
218+
newPropData[key] = 'function';
219+
// console.log('we changed the function', newPropData[key]);
220+
} else if (typeof obj[key] === 'object') {
221+
// console.log('this is going to enter a recursive call', obj[key]);
222+
// convertFunctionToString(obj[key]);
223+
newPropData[key] = JSON.stringify(obj[key]);
224+
} else {
225+
newPropData[key] = obj[key];
226+
}
227+
}
228+
// console.log(newPropData);
229+
return newPropData;
230+
}
213231
// Every time a state change is made in the accompanying app, the extension creates a
214232
// Tree “snapshot” of the current state, and adds it to the current “cache” of snapshots in the extension
215233
function createTree(
@@ -236,7 +254,28 @@ function createTree(
236254
selfBaseDuration,
237255
treeBaseDuration,
238256
} = currentFiber;
239-
257+
//new feature adds props/state into the component
258+
if (tag === 5) {
259+
try {
260+
// console.log('this is the tree', tree);
261+
262+
if (memoizedProps.children[0]._owner.memoizedProps !== undefined) {
263+
const propsData = memoizedProps.children[0]._owner.memoizedProps;
264+
const newPropData = convertFunctionToString(propsData);
265+
tree.componentData = {
266+
...tree.componentData,
267+
props: newPropData
268+
};
269+
}
270+
// console.log('CHECKING THE TREE FOR THE DATA', tree);
271+
// console.log('looking for the owner', memoizedProps.children);
272+
// console.log('this is working but whats going on', propsData,);
273+
// console.log('this should display the stuff we want', memoizedProps.children[0]._owner.memoizedState);
274+
// console.log('current fiber', currentFiber);
275+
} catch (error) {
276+
// console.log('this is the error', error);
277+
}
278+
}
240279
// Checks Recoil Atom and Selector Relationships
241280
if (
242281
currentFiber.memoizedState
@@ -399,9 +438,11 @@ function createTree(
399438
let pointer = currentFiber;
400439
// end of repeat code
401440

441+
402442
while (pointer !== null) {
403443
if (pointer.stateNode !== null) {
404444
rtid = `fromLinkFiber${rtidCounter++}`;
445+
// rtid = rtidCounter++;
405446
recoilDomNode[currentFiber.elementType.name].push(rtid);
406447
// check if rtid is already present
407448
// remove existing rtid before adding a new one
@@ -419,12 +460,14 @@ function createTree(
419460
pointer = pointer.child;
420461
}
421462
} else {
463+
422464
if (
423465
currentFiber.child
424466
&& currentFiber.child.stateNode
425467
&& currentFiber.child.stateNode.setAttribute
426468
) {
427469
rtid = `fromLinkFiber${rtidCounter}`;
470+
// rtid = rtidCounter;
428471
// check if rtid is already present
429472
// remove existing rtid before adding a new one
430473
if (currentFiber.child.stateNode.classList.length > 0) {
@@ -438,6 +481,7 @@ function createTree(
438481
currentFiber.child.stateNode.classList.add(rtid);
439482
}
440483
rtidCounter++;
484+
console.log('rtidCounter', rtidCounter);
441485
}
442486
// checking if tree fromSibling is true
443487
if (fromSibling) {
@@ -463,13 +507,15 @@ function createTree(
463507
}
464508

465509
// Recurse on children
510+
466511
if (child && !circularComponentTable.has(child)) {
467512
// If this node had state we appended to the children array,
468513
// so attach children to the newly appended child.
469514
// Otherwise, attach children to this same node.
470515
circularComponentTable.add(child);
471516
createTree(child, newNode);
472517
}
518+
473519
// Recurse on siblings
474520
if (sibling && !circularComponentTable.has(sibling)) {
475521
circularComponentTable.add(sibling);
@@ -508,7 +554,7 @@ export default (snap: Snapshot, mode: Mode): (() => void) => {
508554
document.addEventListener('visibilitychange', onVisibilityChange);
509555

510556
if (reactInstance && reactInstance.version) {
511-
console.log('888888888888888888888THIS IS GETTING CALLED LINE 503 888888888888888888888888888888');
557+
// console.log('888888888888888888888 THIS IS GETTING CALLED LINE 503 888888888888888888888888888888');
512558
devTools.onCommitFiberRoot = (function (original) {
513559
return function (...args) {
514560
// eslint-disable-next-line prefer-destructuring

src/backend/tree.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
/* eslint-disable no-console */
88
/* eslint-disable no-param-reassign */
99

10+
import { createGenerateClassName } from "@material-ui/styles";
11+
1012
let copyInstances = 0;
1113
const circularComponentTable = new Set<Tree>();
14+
let componentNames = {}
1215

1316
// Removes unserializable state data such as functions
1417
function scrubUnserializableMembers(tree: Tree): Tree {
@@ -26,6 +29,7 @@ function serializeState(state) {
2629
}
2730
}
2831

32+
2933
/**
3034
* This is the current snapshot that is being sent to the snapshots array.
3135
* Creates a Tree
@@ -53,32 +57,71 @@ class Tree {
5357

5458
recoilDomNode: any;
5559

60+
//Duplicate names: add a unique number ID
61+
//Create an object 'componentNames' to store each component name as a key and it's frequency of use as its value
62+
//When a new component is made on the tree, check if the new component's name already exists in 'componentNames' (possibly with the .hasOwnProperty method)
63+
//If the name already exists, add its value (an integer) to the name
64+
//Also, increment the value after
65+
//If not, create the new component and also a new key: value pair in 'componentNames' with the component's name as the key and 0 as its value
66+
//EXAMPLE OF COMPONENTNAMES OBJECT: {editableInput: 1, Provider: 0, etc}
67+
68+
//Empty names:
69+
//If string, rtid without 'fromLinkFiber"
70+
//If object
71+
//If null
72+
5673
constructor(state: string | {}, name = 'nameless', componentData: {} = {}, rtid: any = null, recoilDomNode: any = null) {
5774
this.state = state === 'root' ? 'root' : serializeState(state);
58-
this.name = name === "" ? rtid : name;
75+
this.name = name;
5976
this.componentData = componentData ? JSON.parse(JSON.stringify(componentData)) : {};
6077
this.children = [];
6178
this.parent = null; // ref to parent so we can add siblings
6279
this.rtid = rtid;
6380
this.recoilDomNode = recoilDomNode;
6481
}
6582

83+
// Returns a unique name ready to be used
84+
checkForDuplicates(name: string) {
85+
//check for empty name
86+
if (name === "" && typeof this.rtid === 'string') {
87+
name = this.rtid.replace('fromLinkFiber', '');
88+
}
89+
if (this.state === 'root') {
90+
componentNames = {};
91+
}
92+
//check for duplicate
93+
else if (componentNames[name] !== undefined) {
94+
const count = componentNames[name] + 1;
95+
const newName = name + count;
96+
componentNames[name] = count;
97+
return newName;
98+
}
99+
componentNames[name] = 0;
100+
return name;
101+
}
102+
66103
addChild(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode: any): Tree {
67-
const newChild: Tree = new Tree(state, name, componentData, rtid, recoilDomNode);
104+
const uniqueName = this.checkForDuplicates(name);
105+
console.log("ChildName:", uniqueName);
106+
this.name = uniqueName;
107+
const newChild: Tree = new Tree(state, uniqueName, componentData, rtid, recoilDomNode);
68108
newChild.parent = this;
69109
this.children.push(newChild);
70110
return newChild;
71111
}
72112

73113
addSibling(state: string | {}, name: string, componentData: {}, rtid: any, recoilDomNode: any): Tree {
74-
const newSibling: Tree = new Tree(state, name, componentData, rtid, recoilDomNode);
114+
const uniqueName = this.checkForDuplicates(name);
115+
console.log("SiblingName:", uniqueName);
116+
this.name = uniqueName;
117+
const newSibling: Tree = new Tree(state, uniqueName, componentData, rtid, recoilDomNode);
75118
newSibling.parent = this.parent;
76119
this.parent.children.push(newSibling);
77120
return newSibling;
78121
}
79122

80123
/**
81-
* @function cleanTreeCopy : Adds a sibing to the current tree
124+
* @function cleanTreeCopy : Adds a sibling to the current tree
82125
*/
83126
cleanTreeCopy(): Tree {
84127
/**
@@ -91,6 +134,7 @@ class Tree {
91134
}
92135
// creates copy of present node
93136
let copy: Tree = new Tree(this.state, this.name, this.componentData, this.rtid, this.recoilDomNode);
137+
console.log('CLEANTREECOPY TEST', copy);
94138
delete copy.parent;
95139
circularComponentTable.add(this);
96140
copy = scrubUnserializableMembers(copy);

src/backend/types/backendTypes.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
/* eslint-disable @typescript-eslint/no-explicit-any */
44
import Tree from '../tree';
55

6-
76
export interface Snapshot {
87
tree: Tree;
98
unfilteredTree: null;
@@ -82,7 +81,7 @@ export const ClassComponent = 1;
8281
export const IndeterminateComponent = 2; // Before we know whether it is function or class
8382
export const HostRoot = 3; // Root of a host tree. Could be nested inside another node.
8483
export const HostPortal = 4; // A subtree. Could be an entry point to a different renderer.
85-
export const HostComponent = 5;
84+
export const HostComponent = 5; // has stateNode of html elements
8685
export const HostText = 6;
8786
export const Fragment = 7;
8887
export const Mode = 8;
@@ -92,7 +91,7 @@ export const ForwardRef = 11;
9291
export const Profiler = 12;
9392
export const SuspenseComponent = 13;
9493
export const MemoComponent = 14;
95-
export const SimpleMemoComponent = 15;
94+
export const SimpleMemoComponent = 15; // A higher order component where if the component renders the same result given the same props, react skips rendering the component and uses last rendered result. Has memoizedProps/memoizedState but no stateNode
9695
export const LazyComponent = 16;
9796
export const IncompleteClassComponent = 17;
9897
export const DehydratedFragment = 18;

0 commit comments

Comments
 (0)