Skip to content

Commit 3ddd160

Browse files
committed
applying merge
2 parents c8d1ebd + ecedb85 commit 3ddd160

File tree

8 files changed

+112
-52
lines changed

8 files changed

+112
-52
lines changed

src/app/components/DetailCards/DetailsNav.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import React, { useState } from 'react';
2-
3-
let NavLink = require('react-router-dom').NavLink;
4-
1+
import React from 'react';
52
// styled component imports
63
import { Buttons, Button, DetailsNavWrapper } from '../../styles/Nav.jsx';
74

5+
const { NavLink } = require('react-router-dom');
86

97
export default function RightNav(props) {
108
return (

src/app/container/Details.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import StateDisplay from '../components/DetailCards/State/StateDisplay.jsx'
1515

1616

1717
export default function Details(props) {
18-
1918
// destructuring required info that's being passed down from App.jsx
2019
// passing these props onto children
2120
const {

src/browser/chrome/background.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
const parseAndGenerate = require('./scripts/parser');
22

3+
let portToDevtools;
4+
const msgsToPanel = [];
5+
36
chrome.tabs.onUpdated.addListener((id, info, tab) => {
47
if (tab.status !== 'complete' || tab.url.startsWith('chrome')) return;
58

9+
// active page action button and inject extension.js
610
chrome.pageAction.show(tab.id);
711
chrome.tabs.executeScript(null, {
812
file: 'extension.js',
913
runAt: 'document_end',
1014
});
15+
16+
// refresh devtool panel everytime we refresh webpage
17+
// console.log('port: ', portToDevtools);
18+
// if (portToDevtools) portToDevtools.postMessage({ action: 'refresh_devtool' });
19+
// else msgsToPanel.push({ action: 'refresh_devtool' });
1120
});
1221

1322

@@ -29,7 +38,6 @@ function handleRequest(request) {
2938
const syncRequest = new XMLHttpRequest();
3039
syncRequest.open('GET', request.url, false);
3140
syncRequest.send(null);
32-
console.log(`Status: ${syncRequest.status} - Size of response: ${syncRequest.responseText.length}`);
3341

3442
sendMessageToContent(parseAndGenerate(syncRequest.responseText));
3543

@@ -40,6 +48,18 @@ function handleRequest(request) {
4048
// The App on the devtools panel start a connection so that it can
4149
// tell us when to start intercepting the script requests.
4250
chrome.runtime.onConnect.addListener((port) => {
51+
portToDevtools = port;
52+
53+
// if (msgsToPanel.length > 0) {
54+
// for (let msg of msgsToPanel) port.postMessage(msg);
55+
// }
56+
// we change the port to null when we disconnect, so that when we refresh
57+
// the page by start recording, we can check if (!port) and not refresh
58+
// the devtools page.
59+
port.onDisconnect.addListener(() => {
60+
portToDevtools = null;
61+
});
62+
4363
port.onMessage.addListener((msg) => {
4464
if (!msg.turnOnDevtool) return;
4565
interceptedUrl = msg.url;
@@ -64,7 +84,6 @@ function addScriptInterception() {
6484
let reqIndex = 0;
6585
function sendMessageToContent(codeString) {
6686
const index = reqIndex++;
67-
console.log(`Sending request ${index}.`);
6887
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
6988
chrome.tabs.sendMessage(tabs[0].id, { codeString, index });
7089
});

src/browser/chrome/devtools.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ chrome.devtools.panels.create('React Rewind',
33
'devtools.html',
44
(extensionPanel) => {
55
const port = chrome.runtime.connect({ name: 'devtools' });
6-
port.onMessage.addListener(() => {});
6+
port.onMessage.addListener((msg) => {
7+
// console.log('got msg: ', msg);
8+
if (msg.action === 'refresh_devtool') extensionPanel.setPage('devtools.html');
9+
});
10+
711
extensionPanel.onShown.addListener((panelWindow) => {
812
panelWindow.backgroundPort = port;
913
});

src/browser/chrome/scripts/inject_script_tags.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@
22
// We need this because our content-injected scripts are executed in an "isolated
33
// world" environment. BUT for the scripts below, we want the edited-React libraries
44
// to have access to the their functionalities.
5-
const linkedListScript = document.createElement('script');
6-
linkedListScript.src = chrome.runtime.getURL('scripts/linked_list.js');
7-
(document.head || document.documentElement).appendChild(linkedListScript);
5+
6+
// const linkedListScript = document.createElement('script');
7+
// linkedListScript.src = chrome.runtime.getURL('scripts/linked_list.js');
8+
// (document.head || document.documentElement).appendChild(linkedListScript);
89

910
const timeTravelScript = document.createElement('script');
1011
timeTravelScript.src = chrome.runtime.getURL('scripts/time_travel.js');
1112
(document.head || document.documentElement).appendChild(timeTravelScript);
1213

13-
linkedListScript.onload = timeTravelScript.onload = function removeScriptTag() {
14+
// linkedListScript.onload =
15+
timeTravelScript.onload = function removeScriptTag() {
1416
this.remove();
1517
};
1618

src/browser/chrome/scripts/linked_list.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
class DoublyLinkedListNode {
2-
constructor(value, next = null, previous = null) {
2+
constructor(value, next = null, prev = null) {
33
this.value = value;
44
this.next = next;
5-
this.previous = previous;
5+
this.prev = prev;
66
}
77
}
88

99
class DoublyLinkedList {
1010
constructor() {
11+
this.head = null;
1112
this.tail = null;
1213
this.current = null;
1314
}
@@ -16,11 +17,12 @@ class DoublyLinkedList {
1617
const newDLLNode = new DoublyLinkedListNode(fiberNode);
1718

1819
if (!this.head) {
20+
this.head = newDLLNode;
1921
this.tail = newDLLNode;
2022
this.current = newDLLNode;
2123
} else {
2224
this.tail.next = newDLLNode;
23-
newDLLNode.previous = this.tail;
25+
newDLLNode.prev = this.tail;
2426
this.tail = newDLLNode;
2527
}
2628

src/browser/chrome/scripts/parser.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function useReducerReplacement() {
88
const dispatcher = resolveDispatcher();
99
function reducerWithTracker(state, action) {
1010
const newState = reducer(state, action);
11-
timeTravelTracker[timeTravelTracker.length - 1].actionDispatched = true;
11+
timeTravelLList.tail.value.actionDispatched = true;
1212
window.postMessage({
1313
type: 'DISPATCH',
1414
data: {
@@ -52,7 +52,8 @@ function commitAllHostEffectsReplacement() {
5252
switch (primaryEffectTag) {
5353
case Placement:
5454
{
55-
timeTravelTracker.push({
55+
// editbyme
56+
timeTravelLList.append({
5657
primaryEffectTag: 'PLACEMENT',
5758
effect: _.cloneDeep(nextEffect),
5859
});
@@ -72,7 +73,8 @@ function commitAllHostEffectsReplacement() {
7273
}
7374
case Update:
7475
{
75-
timeTravelTracker.push({
76+
// editbyme
77+
timeTravelLList.append({
7678
primaryEffectTag: 'UPDATE',
7779
effect: _.cloneDeep(nextEffect),
7880
current: _.cloneDeep(nextEffect.alternate),
@@ -84,7 +86,8 @@ function commitAllHostEffectsReplacement() {
8486
}
8587
case Deletion:
8688
{
87-
timeTravelTracker.push({
89+
// editbyme
90+
timeTravelLList.append({
8891
primaryEffectTag: 'DELETION',
8992
effect: _.cloneDeep(nextEffect),
9093
});
@@ -167,7 +170,7 @@ const parseAndGenerate = (codeString) => {
167170
// parse react code
168171
injectableUseReducer = esprima.parseScript(useReducerReplacement.toString());
169172
traverseTree(injectableUseReducer, 'useReducer', ast);
170-
173+
171174
const code = escodegen.generate(ast);
172175
console.log('returning code.');
173176
return code;

src/browser/chrome/scripts/time_travel.js

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,76 @@
1-
let timeTravelTracker = [];
2-
let timeTravelTrackerIndex = null;
1+
class DoublyLinkedListNode {
2+
constructor(value, next = null, prev = null) {
3+
this.value = value;
4+
this.next = next;
5+
this.prev = prev;
6+
}
7+
}
8+
9+
class DoublyLinkedList {
10+
constructor() {
11+
this.head = null;
12+
this.tail = null;
13+
this.current = null;
14+
}
15+
16+
append(fiberNode) {
17+
const newDLLNode = new DoublyLinkedListNode(fiberNode);
18+
19+
if (!this.head) {
20+
this.head = newDLLNode;
21+
this.tail = newDLLNode;
22+
this.current = newDLLNode;
23+
} else {
24+
this.tail.next = newDLLNode;
25+
newDLLNode.prev = this.tail;
26+
this.tail = newDLLNode;
27+
}
28+
29+
return this;
30+
}
31+
}
32+
33+
334
const funcStorage = {};
4-
let root;
35+
let root = null;
36+
const timeTravelLList = new DoublyLinkedList();
537

638
function timeTravel(direction) {
7-
if (timeTravelTrackerIndex === null) {
8-
// First time we call this function. We need to remove the PLACEMENT entry
9-
// from position [0]. This is originated from the initial mount of the App.
10-
timeTravelTracker = timeTravelTracker.slice(1);
11-
timeTravelTrackerIndex = timeTravelTracker.length - 1;
12-
root = getRootContainerInstance(timeTravelTracker[0].effect);
39+
if (!root) {
40+
root = getRootContainerInstance(timeTravelLList.current.value.effect);
41+
timeTravelLList.current = timeTravelLList.tail;
1342
}
1443

1544
const diff = direction === 'forward' ? 1 : -1;
1645

17-
if ((diff === 1 && timeTravelTrackerIndex === timeTravelTracker.length - 1)
18-
|| (diff === -1 && timeTravelTrackerIndex === 0)) {
46+
if ((diff === 1 && timeTravelLList.current.next === null)
47+
|| (diff === -1 && timeTravelLList.current.prev === null)) {
1948
return;
2049
}
2150

22-
if (diff === 1 && timeTravelTrackerIndex !== 0) timeTravelTrackerIndex += 1;
51+
if (diff === 1 && timeTravelLList.current !== timeTravelLList.tail) {
52+
timeTravelLList.current = timeTravelLList.current.next;
53+
}
54+
55+
const {
56+
commitDeletion,
57+
commitPlacement,
58+
commitWork,
59+
prepareUpdate,
60+
} = funcStorage;
2361

2462
while (true) {
25-
const {
26-
commitDeletion,
27-
commitPlacement,
28-
commitWork,
29-
prepareUpdate,
30-
} = funcStorage;
31-
console.log('doing work for ', timeTravelTrackerIndex);
32-
const { primaryEffectTag, effect } = timeTravelTracker[timeTravelTrackerIndex];
63+
// console.log('doing work for ', timeTravelTrackerIndex);
64+
const { primaryEffectTag, effect } = timeTravelLList.current.value;
3365

3466
switch(primaryEffectTag) {
3567
case 'UPDATE': {
36-
const { current } = timeTravelTracker[timeTravelTrackerIndex];
68+
const { current } = timeTravelLList.current.value;
3769

3870
// if we are moving forwards, we need to commitWork() the same
3971
// way the function was originally called.
4072
if (diff === 1) {
41-
commitWork(current, effect);
73+
commitWork(_.cloneDeep(current), _.cloneDeep(effect));
4274
break;
4375
}
4476

@@ -60,24 +92,23 @@ function timeTravel(direction) {
6092

6193
const currentCopy = _.cloneDeep(current);
6294
currentCopy.updateQueue = payload;
63-
commitWork(effect, currentCopy);
95+
commitWork(_.cloneDeep(effect), currentCopy);
6496
break;
6597
}
6698

67-
commitWork(effect, current);
99+
commitWork(_.cloneDeep(effect), _.cloneDeep(current));
68100
break;
69101
}
70102
case 'PLACEMENT': {
71103
if (diff === 1) {
72-
commitPlacement(effect);
104+
commitPlacement(_.cloneDeep(effect));
73105
} else {
74106
// commitDeletion() will call unmountHostComponents(), which recursively
75107
// deletes all host nodes from the parent. This means that
76108
// effect.return = null. BUT we need that reference for later calls
77109
// on commitPlacement() on this same node. This is why we need to clone
78110
// the effect fiberNode and call commitDeletion() on that instead.
79111
const effectCopy = _.cloneDeep(effect);
80-
console.log(effectCopy);
81112
commitDeletion(effectCopy);
82113
}
83114
break;
@@ -88,7 +119,7 @@ function timeTravel(direction) {
88119
const effectCopy = _.cloneDeep(effect);
89120
commitDeletion(effectCopy);
90121
} else {
91-
commitPlacement(effect);
122+
commitPlacement(_.cloneDeep(effect));
92123
}
93124
break;
94125
}
@@ -97,15 +128,17 @@ function timeTravel(direction) {
97128
}
98129

99130
// break points for the while loop
100-
if (timeTravelTrackerIndex + diff === timeTravelTracker.length
101-
|| (diff === -1 && timeTravelTrackerIndex === 0)
102-
|| (diff === 1 && timeTravelTracker[timeTravelTrackerIndex].actionDispatched)) {
131+
if ((diff === -1 && timeTravelLList.current.prev === null)
132+
|| (diff === 1 && timeTravelLList.current.next === null)
133+
|| (diff === 1 && timeTravelLList.current.value.actionDispatched)) {
103134
return;
104135
}
105136

106-
timeTravelTrackerIndex += diff;
137+
timeTravelLList.current = diff === 1
138+
? timeTravelLList.current.next
139+
: timeTravelLList.current.prev;
107140

108-
if (diff === -1 && timeTravelTracker[timeTravelTrackerIndex].actionDispatched) {
141+
if (diff === -1 && timeTravelLList.current.value.actionDispatched) {
109142
return;
110143
}
111144
}

0 commit comments

Comments
 (0)