Skip to content

Commit 2dba4d3

Browse files
authored
Merge pull request #7 from oslabs-beta/pseudocoding
Added psuedocoding to improve future developer experience
2 parents 0561231 + 60dcb94 commit 2dba4d3

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

src/app/components/History.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
/* eslint-disable react-hooks/exhaustive-deps */
22
// @ts-nocheck
33
import React, { Component, useEffect, useState } from 'react';
4+
// ReactHover does not refer to individual nodes within the history tab but rather can only wrap the entire SVG div
45
import ReactHover, { Trigger, Hover } from 'react-hover';
6+
// used in action.tsx to format the return data of findDiff into a react component, not needed since the return of findDiff in History.tsx is simple a divs html
57
import ReactHtmlParser from 'react-html-parser';
8+
// formatting findDiff return data to show the changes with green and red background colors, aligns with actions.tsx
69
import { diff, formatters } from 'jsondiffpatch';
710
import * as d3 from 'd3';
11+
// legend key taken out before ReactimeX(v 10.0)
812
import LegendKey from './legend';
913
import { changeView, changeSlider } from '../actions/actions';
1014

15+
//unused function definition, didnt break reactime when commented out
1116
const filterHooks = (data: any[]) => {
1217
if (data[0].children && data[0].state === 'stateless') {
1318
return filterHooks(data[0].children);
@@ -29,6 +34,7 @@ function History(props: Record<string, unknown>) {
2934
hierarchy,
3035
dispatch,
3136
currLocation,
37+
//snapshots array passed down from state route, needed for findDiff function
3238
snapshots,
3339
} = props;
3440

@@ -106,17 +112,21 @@ function History(props: Record<string, unknown>) {
106112
dispatch(changeView(d.data.index));
107113
dispatch(changeSlider(d.data.index));
108114
})
115+
//added to display state change information to node tree
109116
.on('mouseover', d => {
117+
// created popup div and appended it to display div(returned in this function)
118+
// D3 doesn't utilize z-index for priority, rather decides on placement by order of rendering
119+
// needed to define the return div with a className to have a target to append to with the correct level of priority
110120
const div = d3.select('.display').append('div')
111121
.attr('class', 'tooltip')
112122
.style('opacity', 1)
113123
.style('left', (d3.event.pageX) + 'px')
114124
.style('top', (d3.event.pageY) + 'px')
115-
// .text(JSON.stringify(findDiff(d.data.index)));
116-
// .html(findDiff(d.data.index));
117125
d3.selectAll('.tooltip').html(findDiff(d.data.index));
118126
})
119127
.on('mouseout', d => {
128+
// when appending divs on mouseover the appended dives would not disappear when using D3's 'transition' on mouseover/mouseout
129+
// solution: remove all tooltop divs on mouseout
120130
d3.selectAll('.tooltip').remove();
121131
})
122132
.attr('transform', d => `translate(${d.x},${d.y})`);
@@ -140,7 +150,7 @@ function History(props: Record<string, unknown>) {
140150
return svg.node();
141151
};
142152

143-
// finding difference
153+
// findDiff function uses same logic as ActionContainer.tsx
144154
function findDiff(index) {
145155
const statelessCleanning = (obj: {
146156
name?: string;
@@ -178,24 +188,17 @@ function History(props: Record<string, unknown>) {
178188
);
179189
}
180190
}
181-
// nathan test
182191
return newObj;
183192
};
184-
// displays stateful data
185193

186194
const previousDisplay = statelessCleanning(snapshots[index - 1]);
187195
const delta = diff(previousDisplay, snapshots[index]);
188196
const changedState = findStateChangeObj(delta);
189-
// took out the formatting for History.tsx nodes, Rob 11/4
197+
// figured out the formatting for hover, applying diff.csss
190198
const html = formatters.html.format(changedState[0]);
199+
// uneeded, not returning a react component in SVG div
191200
// const output = ReactHtmlParser(html);
192201
return html;
193-
194-
// if (changedState[0][0] !== 'root') {
195-
// delete changedState[0]['hooksState']['_t'];
196-
// }
197-
198-
// return changedState[0];
199202
}
200203

201204
function findStateChangeObj(delta, changedState = []) {

src/backend/linkFiber.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ function traverseRecoilHooks(
182182
function traverseHooks(memoizedState: any): HookStates {
183183
const hooksStates: HookStates = [];
184184
while (memoizedState && memoizedState.queue) {
185+
// the !== null conditional is necessary here for correctly displaying react hooks because TypeScript recognizes 0 and "" as null - DO NOT REMOVE
185186
if (memoizedState.memoizedState !== null) {
186187
hooksStates.push({
187188
component: memoizedState.queue,
@@ -399,15 +400,12 @@ function createTree(
399400
state.state,
400401
state.component
401402
);
402-
// why is this re-writing componentData.hooksIndex every time? instead, should remove from loop and try to re-write it to be whichever state is being updated
403403
componentData.hooksIndex = hooksIndex;
404404
if (!newState) {
405405
newState = { hooksState: [] };
406-
// }
407406
} else if (!newState.hooksState) {
408407
newState.hooksState = [];
409408
}
410-
// newState[hooksNames[i]] = state.state;
411409
newState.hooksState.push({ [hooksNames[i]]: state.state });
412410
componentFound = true;
413411
});

src/backend/masterState.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,26 @@ import {
1111
HookStates, // array of hook state items
1212
} from './types/backendTypes';
1313

14+
// HookState is an array that contains a "component" for every single state change that occurs in the app
15+
// Information on these components include ComponentData as well as state
16+
// For class components, there will be one "component" for each snapshot
17+
// For functional components that utilize Hooks, there will be one "component" for each setter/getter every time we have a new snapshot
1418
const componentActionsRecord: HookStates = [];
1519
let index = 0;
1620

1721
export default {
18-
componentActionsRecord,
22+
//adds new component to ComponentActionsRecord
1923
saveNew: (state, component): number => {
2024
componentActionsRecord[index] = { state, component };
2125
index++;
2226
return index - 1;
2327
},
2428
getRecordByIndex: (inputIndex: number): HookStateItem => componentActionsRecord[inputIndex],
29+
//this is used for class components - inputIndex will always be a fixed number (coming in timeJump.ts)
2530
getComponentByIndex: (inputIndex: number): any => (componentActionsRecord[inputIndex]
2631
? componentActionsRecord[inputIndex].component
2732
: undefined),
33+
//this is used for react hooks - hooks will be passed in as an array from timeJump.ts
2834
getComponentByIndexHooks: (inputIndex: Array<number> = []): any => {
2935
const multiDispatch = [];
3036
for (let i = 0; i < inputIndex.length; i++) {

src/backend/timeJump.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export default (origin, mode) => {
6262
}
6363
});
6464

65-
// multiple dispatch check
65+
//REACT HOOKS
66+
// check if component states are set with hooks
67+
// if yes, grab all relevant components for this snapshot in numArr
68+
// call dispatch on each component passing in the corresponding currState value
6669
if (target.state && target.state.hooksState) {
6770
const currState = target.state.hooksState;
6871
const numArr: Array<number> = [];

0 commit comments

Comments
 (0)