Skip to content

Commit e544ca8

Browse files
authored
Merge pull request #35 from oslabs-beta/staging
Staging
2 parents e80de1f + 12edde8 commit e544ca8

File tree

13 files changed

+212
-446
lines changed

13 files changed

+212
-446
lines changed

.eslintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"extends": ["airbnb", "plugin:jest/recommended"],
33
"root": true,
4-
"plugins": ["jest", "react"],
4+
"plugins": ["jest", "react", "react-hooks"],
55
"rules": {
66
"arrow-parens": [2, "as-needed"],
77
"import/no-unresolved": "off",
8-
"import/extensions": "off"
8+
"import/extensions": "off",
9+
"react-hooks/rules-of-hooks": "error", // Checks rules of Hooks
10+
"react-hooks/exhaustive-deps": "warn" // Checks effect dependencies
911
},
1012
"env": {
1113
"es6": true,

dev-reactime/linkFiber.js

Lines changed: 6 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ module.exports = (snap, mode) => {
116116

117117
// Check if node is a stateful setState component
118118
if (stateNode && stateNode.state && (tag === 0 || tag === 1)) {
119-
console.log('in create tree if')
120-
console.log('this is currentFiber from createTree', currentFiber)
119+
console.log('in create tree if');
120+
console.log('this is currentFiber from createTree', currentFiber);
121121
// Save component's state and setState() function to our record for future
122122
// time-travel state changing. Add record index to snapshot so we can retrieve.
123123
componentData.index = componentActionsRecord.saveNew(stateNode.state, stateNode);
@@ -128,8 +128,8 @@ module.exports = (snap, mode) => {
128128
// Check if node is a hooks useState function
129129
let hooksIndex;
130130
if (memoizedState && (tag === 0 || tag === 1 || tag === 10)) {
131-
console.log('in create tree if')
132-
console.log('this is currentFiber from createTree', currentFiber)
131+
console.log('in create tree if');
132+
console.log('this is currentFiber from createTree', currentFiber);
133133
if (memoizedState.queue) {
134134
// Hooks states are stored as a linked list using memoizedState.next,
135135
// so we must traverse through the list and get the states.
@@ -187,38 +187,6 @@ module.exports = (snap, mode) => {
187187
return tree;
188188
}
189189

190-
191-
// function createUnfilteredTree(curFiber, parentNode) {
192-
// // on call from updateSnapShot, no parentNode provided, so create a root node
193-
// if(! parentNode) parentNode = new Tree('root');
194-
195-
// // Base case: parentNode's child or sibling pointed to null
196-
// if (!curFiber) return parentNode;
197-
198-
// let newChildNode = null;
199-
200-
// // If stateful, add to parentNode's children array, then inject new setState into fiber node
201-
// if (curFiber.stateNode && curFiber.stateNode.state) {
202-
// newChildNode = parentNode.appendChild(curFiber.stateNode);
203-
// // changeSetState(curFiber.stateNode);
204-
// newChildNode.isStateful = true;
205-
// }
206-
// else {
207-
208-
// }
209-
210-
// // Recurse to sibling; siblings that have state should be added to our parentNode
211-
// createTree(curFiber.sibling, parentNode);
212-
213-
// // Recurse to child; If this fiber was stateful, then we added a newChildNode here, and we want
214-
// // to attach further children to that. If this fiber wasn't stateful, we want to attach any
215-
// // children to our existing parentNode.
216-
// createTree(curFiber.child, newChildNode || parentNode);
217-
218-
// return parentNode;
219-
// }
220-
221-
222190
// ! BUG: skips 1st hook click
223191
function updateSnapShotTree() {
224192
/* let current;
@@ -253,14 +221,14 @@ module.exports = (snap, mode) => {
253221
fiberRoot = _internalRoot || _reactRootContainer;
254222
}
255223
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
256-
console.log('this is devTools', devTools)
224+
console.log('this is devTools', devTools);
257225
const reactInstance = devTools ? devTools.renderers.get(1) : null;
258226

259227
if (reactInstance && reactInstance.version) {
260228
devTools.onCommitFiberRoot = (function (original) {
261229
return function (...args) {
262230
fiberRoot = args[1];
263-
console.log('this is fiberRoot', fiberRoot)
231+
console.log('this is fiberRoot', fiberRoot);
264232
updateSnapShotTree();
265233
sendSnapshot();
266234
return original(...args);
@@ -277,82 +245,3 @@ module.exports = (snap, mode) => {
277245
});
278246
};
279247
};
280-
281-
282-
283-
284-
// function createUnfilteredTree(currentFiber, tree = new Tree('root')) {
285-
// // Base case: child or sibling pointed to null
286-
// if (!currentFiber) return tree;
287-
288-
// const { sibling, stateNode, child, memoizedState, elementType,
289-
// tag, actualDuration, actualStartTime, selfBaseDuration, treeBaseDuration,
290-
// } = currentFiber;
291-
292-
// const extraProps = {
293-
// tag, actualDuration, actualStartTime, selfBaseDuration, treeBaseDuration,
294-
// };
295-
296-
// let nextTree = tree;
297-
// let nextTreeUnfiltered = unfilteredTreeNode = new UnfilteredTreeNode('root');
298-
299-
// // Check if stateful component
300-
// if (stateNode && stateNode.state) {
301-
// nextTree = tree.appendChild(stateNode); // Add component to tree
302-
// changeSetState(stateNode); // Change setState functionality
303-
// }
304-
// nextTreeUnfiltered = unfilteredTreeNode.appendChild(stateNode);
305-
306-
// // TODO: handle Hooks cases...
307-
308-
// // Recurse on siblings
309-
// createTree(sibling, tree);
310-
// // Recurse on children
311-
// createTree(child, nextTree);
312-
313-
// return tree;
314-
// }
315-
316-
317-
318-
// Check if the component uses hooks
319-
// if (memoizedState && Object.hasOwnProperty.call(memoizedState, 'baseState')) {
320-
// // 'catch-all' for suspense elements (experimental)
321-
// if (typeof elementType.$$typeof === 'symbol') return;
322-
// // Traverse through the currentFiber and extract the getters/setters
323-
// astHooks = astParser(elementType);
324-
// saveState(astHooks);
325-
// // Create a traversed property and assign to the evaluated result of
326-
// // invoking traverseHooks with memoizedState
327-
// memoizedState.traversed = traverseHooks(memoizedState);
328-
// nextTree = tree.appendChild(memoizedState);
329-
// }
330-
331-
332-
333-
334-
335-
336-
337-
338-
// function createTree(currentFiber, tree = new Tree('root')) {
339-
// // Base case: child or sibling pointed to null
340-
// if (!currentFiber) return tree;
341-
342-
// const { sibling, stateNode, child, memoizedState, elementType } = currentFiber;
343-
344-
// let nextTree = tree;
345-
346-
// // Check if stateful component
347-
// if (stateNode && stateNode.state) {
348-
// nextTree = tree.appendChild(stateNode); // Add component to tree
349-
// changeSetState(stateNode); // Change setState functionality
350-
// }
351-
352-
// // Recurse on siblings
353-
// createTree(sibling, tree);
354-
// // Recurse on children
355-
// createTree(child, nextTree);
356-
357-
// return tree;
358-
// }

dev-reactime/tree.js

Lines changed: 4 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -44,72 +44,7 @@ class Tree {
4444
});
4545
}
4646
return copy;
47-
48-
// This is a regular old tree version of the above, but above version
49-
// is better suited for D3 chart displays
50-
// class Tree {
51-
// constructor(state, name = 'nameless', index) {
52-
// this.state = state === 'root' ? 'root' : JSON.parse(JSON.stringify(state));
53-
// this.name = name;
54-
// this.index = index;
55-
// this.child = null;
56-
// this.sibling = null;
57-
// }
58-
59-
// setNode(state, name, index) {
60-
// this.state = { ...this.child.state, ...state };
61-
// this.name = name;
62-
// this.index = index;
63-
// }
64-
65-
// appendToChild(state, name = this.name, index = this.index) {
66-
// if (this.child) {
67-
// this.child.state = { ...this.child.state, ...state };
68-
// this.child.name = name;
69-
// this.child.index = index;
70-
// } else {
71-
// this.child = new Tree(state, name, index);
72-
// }
73-
// }
74-
75-
// appendToSibling(state, name = this.name, index = this.index) {
76-
// if (this.sibling) {
77-
// state = { ...this.sibling.state, ...state };
78-
// this.sibling.name = name;
79-
// this.sibling.index = index;
80-
// } else {
81-
// this.sibling = new Tree(state, name, index);
82-
// }
83-
// }
84-
85-
// cleanTreeCopy() {
86-
// const copy = new Tree(this.state, this.name, this.index);
87-
// if (this.sibling) {
88-
// copy.sibling = new Tree(this.sibling.state, this.sibling.name, this.sibling.index);
89-
// copy.sibling = scrubUnserializableMembers(copy.sibling);
90-
// copy.sibling = this.sibling.sibling;
91-
// copy.sibling.cleanTreeCopy();
92-
// }
93-
94-
// if (this.child) {
95-
// copy.child = new Tree(this.child.state, this.child.name, this.child.index);
96-
// copy.child = scrubUnserializableMembers(copy.child);
97-
// copy.child = this.child.child;
98-
// copy.child.cleanTreeCopy();
99-
// }
100-
//
101-
// // unfinished:
102-
// cleanD3Copy(children = []) {
103-
// copy = D3Tree(this.state, this.name, this.index, this.isStateless);
104-
// let nextSibling = this.sibling;
105-
// while(nextSibling = this.sibling) {
106-
// copy.cleanD3Copy(copy.)
107-
// }
108-
109-
}
110-
111-
// return copy;
112-
// }
47+
}
11348

11449
// print out the tree structure in the console
11550
// DEV: Process may be different for useState components
@@ -119,7 +54,8 @@ class Tree {
11954
// console.log('current tree structure for *this : ', this);
12055
const children = ['children: '];
12156
// DEV: What should we push instead for components using hooks (it wouldn't be state)
122-
this.children.forEach(child => { // if this.children is always initialized to empty array, when would there ever be anything to iterate through here?
57+
// if this.children is always initialized to empty array, when would there ever be anything to iterate through here?
58+
this.children.forEach(child => {
12359
children.push(child.state || child.component.state);
12460
});
12561
if (this.name) console.log('this.name if exists: ', this.name);
@@ -132,52 +68,4 @@ class Tree {
13268
}
13369
}
13470

135-
// class UnfilteredTreeNode extends Tree {
136-
// constructor(component, useStateInstead = false, name, unfilteredProps) {
137-
// super(component, useStateInstead, name);
138-
// // this.isStateful = unfilteredProps.isStateful;
139-
// // this.tagLabel = reactWorkTags[unfilteredProps.tag];
140-
// if(unfilteredProps) {
141-
// this.tag = unfilteredProps.tag;
142-
// this.actualDuration = unfilteredProps.actualDuration;
143-
// this.actualStartTime = unfilteredProps.actualStartTime;
144-
// this.selfBaseDuration = unfilteredProps.selfBaseDuration;
145-
// this.treeBaseDuration = unfilteredProps.treeBaseDuration;
146-
// }
147-
// }
148-
149-
// appendChild(component) {
150-
// const newChild = new UnfilteredTreeNode(component);
151-
// this.children.push(newChild);
152-
// return newChild;
153-
// }
154-
// }
155-
156-
module.exports = Tree
157-
// module.exports = {
158-
// Tree,
159-
// UnfilteredTreeNode,
160-
// };
161-
162-
163-
164-
165-
// // print out the tree structure in the console
166-
// // DEV: Process may be different for useState components
167-
// // BUG FIX: Don't print the Router as a component
168-
// // Change how the children are printed
169-
// print() {
170-
// console.log("current tree structure for *this : ", this);
171-
// const children = ['children: '];
172-
// // DEV: What should we push instead for components using hooks (it wouldn't be state)
173-
// this.children.forEach(child => { // if this.children is always initialized to empty array, when would there ever be anything to iterate through here?
174-
// children.push(child.state || child.component.state);
175-
// });
176-
// if (this.name) console.log("this.name if exists: ", this.name);
177-
// if (children.length === 1) {
178-
// console.log(`children length 1. ${this.state ? `this.state: ` : `this.component.state: `}`, this.state || this.component.state);
179-
// } else console.log(`children length !== 1. ${this.state ? `this.state: ` : `this.component.state, children: `}`, this.state || this.component.state, ...children);
180-
// this.children.forEach(child => {
181-
// child.print();
182-
// });
183-
// }
71+
module.exports = Tree;

src/app/components/Action.jsx

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,37 @@ import { changeView, changeSlider } from '../actions/actions';
66
// viewIndex and handleonkeyDown added to props
77
const Action = props => {
88
const {
9-
selected, last, index, sliderIndex, dispatch, displayName, componentName, state, viewIndex, handleOnkeyDown,
9+
selected, last, index, sliderIndex, dispatch, displayName, componentName, componentData, state, viewIndex, handleOnkeyDown,
1010
} = props;
11-
console.log('last', last)
12-
console.log('index', index)
13-
console.log('viewIndex', viewIndex)
14-
console.log('selected', selected)
15-
selected
11+
12+
// display render time for state change in seconds and miliseconds
13+
const cleanTime = () => {
14+
let seconds;
15+
let miliseconds = componentData.actualDuration;
16+
if (Math.floor(componentData.actualDuration) > 60) {
17+
seconds = Math.floor(componentData.actualDuration / 60);
18+
seconds = JSON.stringify(seconds);
19+
if (seconds.length < 2) {
20+
seconds = '0'.concat(seconds);
21+
}
22+
miliseconds = Math.floor(componentData.actualDuration % 60);
23+
} else {
24+
seconds = '00';
25+
}
26+
miliseconds = JSON.stringify(miliseconds);
27+
const arrayMiliseconds = miliseconds.split('.');
28+
if (arrayMiliseconds[0].length < 2) {
29+
arrayMiliseconds[0] = '0'.concat(arrayMiliseconds[0]);
30+
}
31+
if (arrayMiliseconds[1].length > 3) {
32+
arrayMiliseconds[1] = arrayMiliseconds[1].slice(0, 2);
33+
}
34+
if (index == 0) {
35+
return `${seconds}:${arrayMiliseconds[0]}.${arrayMiliseconds[1]}`;
36+
}
37+
return `+${seconds}:${arrayMiliseconds[0]}.${arrayMiliseconds[1]}`;
38+
};
39+
const displayTime = cleanTime();
1640

1741
return (
1842
<div
@@ -29,6 +53,12 @@ const Action = props => {
2953
<div className="action-component-text">
3054
{`${displayName}: ${componentName} `}
3155
</div>
56+
<button
57+
className="time-button"
58+
type="button"
59+
>
60+
{displayTime}
61+
</button>
3262
<button
3363
className="jump-button"
3464
onClick={e => {
@@ -50,8 +80,8 @@ Action.propTypes = {
5080
selected: PropTypes.bool.isRequired,
5181
index: PropTypes.number.isRequired,
5282
dispatch: PropTypes.func.isRequired,
53-
displayName: PropTypes.string.isRequired,
54-
componentName: PropTypes.string.isRequired,
83+
displayName: PropTypes.string.isRequired,
84+
componentName: PropTypes.string.isRequired,
5585
state: PropTypes.object.isRequired,
5686
handleOnkeyDown: PropTypes.func.isRequired,
5787
viewIndex: PropTypes.number.isRequired,

src/app/components/Chart.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Chart extends Component {
3434
componentDidUpdate() {
3535
const { hierarchy } = this.props;
3636
root = JSON.parse(JSON.stringify(hierarchy));
37+
console.log("Chart -> componentDidUpdate -> hierarchy", hierarchy);
3738
this.maked3Tree();
3839
}
3940

0 commit comments

Comments
 (0)