Skip to content

Commit b3779a4

Browse files
committed
fixed errors in snapshot hierarchy
1 parent 1fc0413 commit b3779a4

File tree

5 files changed

+45
-63
lines changed

5 files changed

+45
-63
lines changed

dev-reactime/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function getRouteURL(node) {
4545
window.addEventListener('message', ({ data: { action, payload } }) => {
4646
switch (action) {
4747
case 'jumpToSnap':
48-
console.log('payload in jumpToSnap', payload);
48+
// console.log('payload in jumpToSnap', payload);
4949
timeJump(payload); // * This sets state with given payload
5050
// Get the pathname from payload and add new entry to browser history
5151
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState

dev-reactime/linkFiber.js

Lines changed: 30 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,19 @@ export default (snap, mode) => {
5959
function sendSnapshot() {
6060
// Don't send messages while jumping or while paused
6161
circularComponentTable.clear();
62-
console.log('sending snapshot');
62+
// console.log('sending snapshot');
6363
if (mode.jumping || mode.paused) return;
64-
console.log('PAYLOAD: before cleaning', snap.tree);
64+
// console.log('PAYLOAD: before cleaning', snap.tree);
6565

6666
if (!snap.tree) {
67-
console.log('snapshot empty, sending root');
67+
// console.log('snapshot empty, sending root');
6868
snap.tree = new Tree('root');
6969
}
7070
const payload = snap.tree.cleanTreeCopy();// snap.tree.getCopy();
7171

72-
console.log('PAYLOAD: after cleaning', payload);
73-
//try {
74-
//await window.postMessage({
72+
// console.log('PAYLOAD: after cleaning', payload);
73+
// try {
74+
// await window.postMessage({
7575
window.postMessage({
7676
action: 'recordSnap',
7777
payload,
@@ -105,7 +105,7 @@ export default (snap, mode) => {
105105
//
106106
function createTree(currentFiber, tree = new Tree('root'), fromSibling = false) {
107107
// Base case: child or sibling pointed to null
108-
console.log('linkFiber.js: creating tree');
108+
// console.log('linkFiber.js: creating tree');
109109
if (!currentFiber) return null;
110110
if (!tree) return tree;
111111

@@ -132,7 +132,7 @@ export default (snap, mode) => {
132132
if (stateNode && stateNode.state && (tag === 0 || tag === 1 || tag === 2)) {
133133
// Save component's state and setState() function to our record for future
134134
// time-travel state changing. Add record index to snapshot so we can retrieve.
135-
console.log('linkFiber.js: found stateNode component');
135+
// console.log('linkFiber.js: found stateNode component');
136136
componentData.index = componentActionsRecord.saveNew(stateNode.state, stateNode);
137137
newState = stateNode.state;
138138
componentFound = true;
@@ -142,7 +142,7 @@ export default (snap, mode) => {
142142
let hooksIndex;
143143
if (memoizedState && (tag === 0 || tag === 1 || tag === 10)) {
144144
if (memoizedState.queue) {
145-
console.log('linkFiber.js: found hooks component');
145+
// console.log('linkFiber.js: found hooks component');
146146
// Hooks states are stored as a linked list using memoizedState.next,
147147
// so we must traverse through the list and get the states.
148148
// We then store them along with the corresponding memoizedState.queue,
@@ -163,7 +163,7 @@ export default (snap, mode) => {
163163
}
164164

165165
// This grabs stateless components
166-
if (!componentFound && (tag === 0 || tag === 1)) {
166+
if (!componentFound && (tag === 0 || tag === 1 || tag === 2)) {
167167
newState = 'stateless';
168168
}
169169

@@ -176,20 +176,19 @@ export default (snap, mode) => {
176176
treeBaseDuration,
177177
};
178178

179-
console.log('linkFiber.js: adding new state to tree:', newState);
180-
if (componentFound) {
181-
console.log('componentFound, calling tree.addChild');
179+
let newNode = null;
180+
if (componentFound || newState === 'stateless') {
182181
if (fromSibling) {
183-
tree.addSibling(newState, elementType.name ? elementType.name : elementType, componentData);
182+
newNode = tree.addSibling(newState,
183+
elementType.name ? elementType.name : elementType,
184+
componentData);
184185
} else {
185-
tree.addChild(newState, elementType.name ? elementType.name : elementType, componentData);
186-
}
187-
} else if (newState === 'stateless') {
188-
if (fromSibling) {
189-
tree.addSibling(newState, elementType.name ? elementType.name : elementType, componentData);
190-
} else {
191-
tree.addChild(newState, elementType.name ? elementType.name : elementType, componentData);
186+
newNode = tree.addChild(newState,
187+
elementType.name ? elementType.name : elementType,
188+
componentData);
192189
}
190+
} else {
191+
newNode = tree;
193192
}
194193

195194
// Recurse on children
@@ -198,32 +197,28 @@ export default (snap, mode) => {
198197
// If this node had state we appended to the children array,
199198
// so attach children to the newly appended child.
200199
// Otherwise, attach children to this same node.
201-
console.log('going into child');
200+
// console.log('going into child');
202201
// circularComponentTable.set(child, true);
203-
if (tree.children.length > 0) {
204-
createTree(child, tree.children[tree.children.length - 1]);
205-
} else {
206-
createTree(child, tree);
207-
}
202+
createTree(child, newNode);
208203
}
209204
// Recurse on siblings
210205
if (sibling) { // && !circularComponentTable.has(sibling)) {
211-
console.log('going into sibling');
206+
// console.log('going into sibling');
212207
// circularComponentTable.set(sibling, true);
213-
createTree(sibling, tree, true);
208+
createTree(sibling, newNode, true);
214209
}
215210

216-
console.log('linkFiber.js: processed children and sibling, returning tree');
211+
// console.log('linkFiber.js: processed children and sibling, returning tree');
217212
return tree;
218213
}
219214

220215
function updateSnapShotTree() {
221-
console.log('linkFiber.js, updateSnapshotTree(), checking if we have fiberRoot to update');
216+
// console.log('linkFiber.js, updateSnapshotTree(), checking if fiberRoot updated');
222217
if (fiberRoot) {
223-
console.log('linkFiber.js, updateSnapshotTree(), fiberRoot found, updating snapshot', snap.tree);
218+
// console.log('linkFiber.js, updateSnapshotTree(), updating snapshot', snap.tree);
224219
const { current } = fiberRoot;
225220
snap.tree = createTree(current);
226-
console.log('linkFiber.js, updateSnapshotTree(), completed snapshot', snap.tree);
221+
// console.log('linkFiber.js, updateSnapshotTree(), completed snapshot', snap.tree);
227222
}
228223
}
229224

@@ -241,15 +236,13 @@ export default (snap, mode) => {
241236

242237
const devTools = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
243238
const reactInstance = devTools ? devTools.renderers.get(1) : null;
244-
console.log('devTools:', devTools);
239+
// console.log('devTools:', devTools);
245240

246241
if (reactInstance && reactInstance.version) {
247242
devTools.onCommitFiberRoot = (function (original) {
248243
return function (...args) {
249244
fiberRoot = args[1];
250-
console.log('this is fiberRoot', fiberRoot);
251245
updateSnapShotTree();
252-
console.log('snap.tree is: ', snap.tree);
253246
sendSnapshot();
254247
return original(...args);
255248
};
@@ -260,7 +253,7 @@ export default (snap, mode) => {
260253
// This message is sent from contentScript.js in chrome extension bundles
261254
window.addEventListener('message', ({ data: { action } }) => {
262255
if (action === 'contentScriptStarted') {
263-
console.log('content script started received at linkFiber.js')
256+
// console.log('content script started received at linkFiber.js')
264257
sendSnapshot();
265258
}
266259
});

dev-reactime/timeJump.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export default (origin, mode) => {
4242
target.state.hooksState.forEach(hooksState => {
4343
if (component && component.dispatch) {
4444
const hooksComponent = componentActionsRecord.getComponentByIndex(hooksState[1]);
45-
console.log('dispatch going back to hooks state: ', target.state.hooksState[0]);
45+
// console.log('dispatch going back to hooks state: ', target.state.hooksState[0]);
4646
hooksComponent.dispatch(target.state.hooksState[0]);
4747
}
4848
});

dev-reactime/tree.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ function scrubUnserializableMembers(tree) {
99
Object.entries(tree.state).forEach(keyValuePair => {
1010
if (typeof keyValuePair[1] === 'function') tree.state[keyValuePair[0]] = 'function';
1111
});
12-
// console.log('PAYLOAD: unserializable returns:', tree);
1312
return tree;
1413
}
1514

@@ -24,41 +23,31 @@ class Tree {
2423
}
2524

2625
addChild(state, name, componentData) {
27-
console.log('tree.js: in addChild');
28-
this.children.push(new Tree(state, name, componentData));
29-
this.children[this.children.length - 1].parent = this;
26+
// console.log('tree.js: in addChild');
27+
const newChild = new Tree(state, name, componentData);
28+
newChild.parent = this;
29+
this.children.push(newChild);
30+
return newChild;
3031
}
3132

3233
addSibling(state, name, componentData) {
33-
console.log('tree.js: in addChild');
34-
this.parent.children.push(new Tree(state, name, componentData));
35-
this.parent.children[this.children.length - 1].parent = this;
34+
// console.log('tree.js: in addSibling');
35+
const newSibling = new Tree(state, name, componentData);
36+
newSibling.parent = this.parent;
37+
this.parent.children.push(newSibling);
38+
return newSibling;
3639
}
3740

3841
cleanTreeCopy() {
39-
// copies present node
42+
// creates copy of present node
4043
let copy = new Tree(this.state, this.name, this.componentData);
4144
copy = scrubUnserializableMembers(copy);
4245
copy.children = this.children;
4346

4447
// creates copy of each child of the present node
4548
copy.children = this.children.map(child => child.cleanTreeCopy());
4649

47-
// copy.children = this.children.map(child => {
48-
// newChild = new Tree(child.state, child.name, child.componentData);
49-
// newChild.children = child.children;
50-
// return scrubUnserializableMembers(newChild);
51-
// });
52-
53-
/*
54-
if (copy.children.length > 0) {
55-
copy.children.forEach(child => {
56-
if (child !== copy.children) {
57-
child = child.cleanTreeCopy();
58-
}
59-
return null;
60-
});
61-
} */
50+
// returns copy
6251
return copy;
6352
}
6453

src/extension/contentScript.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ window.addEventListener('message', msg => { // runs automatically every second
2121
const { action } = msg.data;
2222

2323
if (action === 'recordSnap') { // this is firing on page load
24-
console.log('DATA AT EXTENSION:', msg.data);
24+
// console.log('DATA AT EXTENSION:', msg.data);
2525
chrome.runtime.sendMessage(msg.data);
2626
}
2727
});

0 commit comments

Comments
 (0)