Skip to content

Commit 4889332

Browse files
authored
Merge pull request #26 from oslabs-beta/staging
Staging
2 parents b079e27 + b9d01bc commit 4889332

File tree

8 files changed

+160
-94
lines changed

8 files changed

+160
-94
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ src/extension/build.crx
1010
src/extension/build.pem
1111
bower_components
1212
sandboxes/manual-tests/NextJS/.next
13+
.vscode

dev-reactime/linkFiber.js

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ module.exports = (snap, mode) => {
5252
async function sendSnapshot() {
5353
// Don't send messages while jumping or while paused
5454
if (mode.jumping || mode.paused) return;
55-
// console.log('PAYLOAD: before cleaning', snap.tree);
55+
console.log('PAYLOAD: before cleaning', snap.tree);
5656
const payload = snap.tree.cleanTreeCopy();// snap.tree.getCopy();
57-
// console.log('PAYLOAD: after cleaning', payload);
57+
console.log('PAYLOAD: after cleaning', payload);
5858
try {
5959
await window.postMessage({
6060
action: 'recordSnap',
@@ -91,7 +91,9 @@ module.exports = (snap, mode) => {
9191
//
9292
function createTree(currentFiber, tree = new Tree('root')) {
9393
// Base case: child or sibling pointed to null
94-
if (!currentFiber) return tree;
94+
if (!currentFiber) return null;
95+
if (!tree) return tree;
96+
9597

9698
// These have the newest state. We update state and then
9799
// called updateSnapshotTree()
@@ -102,40 +104,72 @@ module.exports = (snap, mode) => {
102104
memoizedState,
103105
elementType,
104106
tag,
107+
actualDuration,
108+
actualStartTime,
109+
selfBaseDuration,
110+
treeBaseDuration,
105111
} = currentFiber;
106112

107-
let index;
113+
let newState = null;
114+
let componentData = {};
115+
let componentFound = false;
108116
// Check if node is a stateful component
109117
if (stateNode && stateNode.state && (tag === 0 || tag === 1)) {
110118
// Save component's state and setState() function to our record for future
111119
// time-travel state changing. Add record index to snapshot so we can retrieve.
112-
index = componentActionsRecord.saveNew(stateNode.state, stateNode);
113-
tree.appendChild(stateNode.state, elementType.name, index); // Add component to tree
114-
} else {
120+
componentData.index = componentActionsRecord.saveNew(stateNode.state, stateNode);
121+
newState = stateNode.state;
122+
componentFound = true;
123+
// tree.appendToChild(stateNode.state, elementType.name, index); // Add component to tree
124+
} else if (tag === 0 || tag === 1) {
115125
// grab stateless components here
126+
newState = 'stateless';
127+
// tree.appendChild({}, elementType.name) // Add component to tree
116128
}
117129

118130
// Check if node is a hooks function
131+
let hooksIndex;
119132
if (memoizedState && (tag === 0 || tag === 1 || tag === 10)) {
120133
if (memoizedState.queue) {
121134
const hooksComponents = traverseHooks(memoizedState);
122135
hooksComponents.forEach(c => {
123-
if (elementType.name) {
124-
index = componentActionsRecord.saveNew(c.state, c.component);
125-
tree.appendChild(c.state, elementType.name ? elementType.name : 'nameless', index);
136+
hooksIndex = componentActionsRecord.saveNew(c.state, c.component);
137+
if (newState.hooksState) {
138+
newState.hooksState.push([c.state, hooksIndex]);
139+
} else {
140+
newState.hooksState = [[c.state, hooksIndex]];
126141
}
142+
componentFound = true;
143+
// newState = { ...newState, hooksState: c.state };
144+
// tree.appendSibling(c.state, elementType.name ? elementType.name : 'nameless', index);
127145
});
128146
}
129147
}
130148

131-
// Recurse on siblings
132-
createTree(sibling, tree);
149+
componentData = {
150+
...componentData,
151+
actualDuration,
152+
actualStartTime,
153+
selfBaseDuration,
154+
treeBaseDuration,
155+
};
156+
157+
if (componentFound) {
158+
tree.addChild(newState, elementType.name ? elementType.name : elementType, componentData);
159+
} else if (newState === 'stateless') {
160+
tree.addChild(newState, elementType.name ? elementType.name : elementType, componentData);
161+
}
162+
133163
// Recurse on children
134-
if (tree.children.length > 0) {
135-
createTree(child, tree.children[0]);
136-
} else {
137-
createTree(child, tree);
164+
if (child) {
165+
if (tree.children.length > 0) {
166+
createTree(child, tree.children[tree.children.length - 1]);
167+
} else {
168+
createTree(child, tree);
169+
}
138170
}
171+
// Recurse on siblings
172+
if (sibling) createTree(sibling, tree);
139173

140174
return tree;
141175
}
@@ -179,8 +213,6 @@ module.exports = (snap, mode) => {
179213
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
180214
const reactInstance = devTools ? devTools.renderers.get(1) : null;
181215
const overrideHookState = reactInstance ? reactInstance.overrideHookState : null;
182-
console.log('DEVTOOLS:', devTools);
183-
console.log('roots:', reactInstance.getCurrentFiber())
184216

185217
if (reactInstance && reactInstance.version) {
186218
devTools.onCommitFiberRoot = (function (original) {

dev-reactime/timeJump.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,11 @@ module.exports = (origin, mode) => {
2020
// Carlos: target is past state we are travelling to
2121

2222
function jump(target, originNode = origin.tree) {
23-
console.log('origin (link to current app state) in jump():', origin);
24-
console.log('target state is: ', target);
2523
// Set the state of the origin tree if the component is stateful
2624
if (!target) return;
27-
const component = componentActionsRecord.getComponentByIndex(target.index);
28-
if (component) {
29-
console.log('time-travel component is true');
30-
if (component.setState) {
31-
console.log('time-travel component setState is true');
32-
}
33-
}
34-
25+
if (target.state === 'stateless') target.children.forEach(child => jump(child));
26+
const component = componentActionsRecord.getComponentByIndex(target.componentData.index);
3527
if (component && component.setState) {
36-
console.log('time-travel calling setState', component);
3728
component.setState(prevState => {
3829
Object.keys(prevState).forEach(key => {
3930
if (target.state[key] === undefined) {
@@ -43,16 +34,24 @@ module.exports = (origin, mode) => {
4334
return target.state;
4435
// Iterate through new children after state has been set
4536
}, () => target.children.forEach(child => jump(child)));
46-
} else if (component && component.dispatch) {
47-
// ** not entering here
48-
console.log('time-travel calling dispatch', component);
49-
component.dispatch(target.state);
37+
}
38+
39+
if (target.state.hooksState) {
40+
target.state.hooksState.forEach(hooksState => {
41+
if (component && component.dispatch) {
42+
const hooksComponent = componentActionsRecord.getComponentByIndex(hooksState[1]);
43+
hooksComponent.dispatch(target.state.hooksState[0]);
44+
}
45+
});
5046
target.children.forEach(child => jump(child));
51-
} else {
52-
console.log('time-travel did not call setState nor dispatch', component);
47+
}
48+
49+
if ((!component || !component.state) && !target.state.hooksState) {
5350
target.children.forEach(child => jump(child));
5451
}
5552

53+
54+
5655
/*
5756
if (originNode.component.setState) {
5857
console.log('stateful component jump, originNode: ', originNode.component);

dev-reactime/tree.js

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@ function scrubUnserializableMembers(tree) {
1212

1313
// this is the current snapshot that is being sent to the snapshots array.
1414
class Tree {
15-
constructor(state, name = 'nameless', index) {
15+
constructor(state, name = 'nameless', componentData = {}) {
1616
this.state = state === 'root' ? 'root' : JSON.parse(JSON.stringify(state));
1717
this.name = name;
18-
this.index = index;
18+
this.componentData = JSON.parse(JSON.stringify(componentData));
1919
this.children = [];
2020
}
2121

22-
appendChild(state, name, index) {
23-
const child = new Tree(state, name, index);
24-
this.children.push(child);
22+
addChild(state, name = this.name, componentData = this.componentData) {
23+
this.children.push(new Tree(state, name, componentData));
2524
}
2625

2726
cleanTreeCopy() {
28-
const copy = new Tree(this.state, this.name, this.index);
27+
const copy = new Tree(this.state, this.name, this.componentData);
2928
let newChild;
3029
copy.children = this.children.map(child => {
31-
newChild = new Tree(child.state, child.name, child.index);
30+
newChild = new Tree(child.state, child.name, child.componentData);
3231
newChild.children = child.children;
3332
return scrubUnserializableMembers(newChild);
3433
});
@@ -42,7 +41,72 @@ class Tree {
4241
});
4342
}
4443
return copy;
45-
}
44+
45+
// This is a regular old tree version of the above, but above version
46+
// is better suited for D3 chart displays
47+
// class Tree {
48+
// constructor(state, name = 'nameless', index) {
49+
// this.state = state === 'root' ? 'root' : JSON.parse(JSON.stringify(state));
50+
// this.name = name;
51+
// this.index = index;
52+
// this.child = null;
53+
// this.sibling = null;
54+
// }
55+
56+
// setNode(state, name, index) {
57+
// this.state = { ...this.child.state, ...state };
58+
// this.name = name;
59+
// this.index = index;
60+
// }
61+
62+
// appendToChild(state, name = this.name, index = this.index) {
63+
// if (this.child) {
64+
// this.child.state = { ...this.child.state, ...state };
65+
// this.child.name = name;
66+
// this.child.index = index;
67+
// } else {
68+
// this.child = new Tree(state, name, index);
69+
// }
70+
// }
71+
72+
// appendToSibling(state, name = this.name, index = this.index) {
73+
// if (this.sibling) {
74+
// state = { ...this.sibling.state, ...state };
75+
// this.sibling.name = name;
76+
// this.sibling.index = index;
77+
// } else {
78+
// this.sibling = new Tree(state, name, index);
79+
// }
80+
// }
81+
82+
// cleanTreeCopy() {
83+
// const copy = new Tree(this.state, this.name, this.index);
84+
// if (this.sibling) {
85+
// copy.sibling = new Tree(this.sibling.state, this.sibling.name, this.sibling.index);
86+
// copy.sibling = scrubUnserializableMembers(copy.sibling);
87+
// copy.sibling = this.sibling.sibling;
88+
// copy.sibling.cleanTreeCopy();
89+
// }
90+
91+
// if (this.child) {
92+
// copy.child = new Tree(this.child.state, this.child.name, this.child.index);
93+
// copy.child = scrubUnserializableMembers(copy.child);
94+
// copy.child = this.child.child;
95+
// copy.child.cleanTreeCopy();
96+
// }
97+
//
98+
// // unfinished:
99+
// cleanD3Copy(children = []) {
100+
// copy = D3Tree(this.state, this.name, this.index, this.isStateless);
101+
// let nextSibling = this.sibling;
102+
// while(nextSibling = this.sibling) {
103+
// copy.cleanD3Copy(copy.)
104+
// }
105+
106+
}
107+
108+
// return copy;
109+
// }
46110

47111
// print out the tree structure in the console
48112
// DEV: Process may be different for useState components

src/app/components/Tree.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import PropTypes from 'prop-types';
55
const getItemString = (type, data) => {
66
// check to make sure that we are on the tree node, not anything else
77
if (
8-
Object.keys(data).length === 3
8+
Object.keys(data).length > 3
99
&& typeof data.state === 'object'
1010
&& typeof data.name === 'string'
1111
&& Array.isArray(data.children)

src/app/containers/ActionContainer.jsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,9 @@ function ActionContainer() {
3838
});
3939
}
4040
}
41-
<<<<<<< HEAD
42-
};
43-
// gabi :: the hierarchy get set on the first click in the page, when page in refreshed we don't have a hierarchy so we need to check if hierarchy was inicialize involk displayArray to display the hierarchy
44-
if (hierarchy) displayArray(hierarchy);
45-
// console.log('this is hierarchyArr', hierarchyArr)
46-
=======
4741
}
4842
// gabi :: the hierarchy get set on the first click in the page, when page in refreshed we don't have a hierarchy so we need to check if hierarchy was inicialize involk displayArray to display the hierarchy
4943
if (hierarchy) displayArray(hierarchy)
50-
>>>>>>> master
5144

5245
// Edwin: handles keyboard presses, function passes an event and index of each action-component
5346
function handleOnKeyDown(e, i) {

src/app/reducers/mainReducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default (state, action) => produce(state, draft => {
1010
} = tabs[currentTab] || {};
1111

1212

13-
// gabi and nate :: function that find the index in the hiearachy and extract the name of the equivalent index to add to the post message
13+
// gabi and nate :: function that find the index in the hierarchy and extract the name of the equivalent index to add to the post message
1414
const findName = (index, hierarchy) => {
1515
if(hierarchy.index == index){
1616
return hierarchy.name;
@@ -93,7 +93,7 @@ export default (state, action) => produce(state, draft => {
9393
}
9494
case types.CHANGE_SLIDER: {
9595
// gabi and nate :: finds the name by the action.payload, parsing through the hierarchy to send to background.js the current name in the jump action
96-
const nameFromIndex = findName(action.payload, hierarchy)
96+
const nameFromIndex = findName(action.payload, hierarchy);
9797

9898
port.postMessage({
9999
action: 'jumpToSnap',

0 commit comments

Comments
 (0)