Skip to content

Commit e48557d

Browse files
pulled latest version from dev and fixed merged conflicts 11/7
2 parents 8d6212c + 4d79271 commit e48557d

File tree

9 files changed

+110
-63
lines changed

9 files changed

+110
-63
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
FROM node:10.16.2
2-
WORKDIR /usr/src/app
2+
WORKDIR /usr/src/app
33
COPY package*.json ./
44
RUN npm i

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"build": "webpack --mode production",
66
"dev": "webpack --mode development --watch",
77
"test": "jest --verbose --coverage --watchAll",
8-
"lint": "eslint --ext .js --ext .jsx src"
8+
"docker-test-lint": "eslint --ext .js --ext .jsx src"
99
},
1010
"keywords": [
1111
"react",

package/astParser.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-inner-declarations */
12
const acorn = require('acorn'); // javascript parser
23
// eslint-disable-next-line import/newline-after-import
34
const jsx = require('acorn-jsx');
@@ -11,34 +12,44 @@ module.exports = elementType => {
1112
// All module exports will always start off as a single 'FunctionDeclaration' type
1213
while (Object.hasOwnProperty.call(ast, 'body')) {
1314
// Traverse down .body once before invoking parsing logic and will loop through any .body after
14-
// depending on the type of state mgmt, ast will have varying levels where
15-
// body array appears in the hierarchy. console.log(ast) on various apps to see this.
16-
if (ast.body[0].expression) {
17-
ast = ast.body[0].expression.body.body;
18-
} else {
19-
ast = ast.body[0].body.body;
20-
}
21-
// Iterate through AST of every function declaration
22-
// Check within each function declaration if there are hook declarations
23-
// ast.forEach(functionDec => { // removed 11/6 to account for change on line 16
24-
// const { body } = functionDec.body; // removed 11/6 to account for change on line 16
15+
ast = ast.body;
2516
const statements = [];
26-
// Traverse through the function's funcDecs and Expression Statements
27-
ast.forEach(program => { // changed from body to ast 11/6 to account for change on line 16
17+
18+
function saveAstHooks(st) {
19+
st.forEach((el, i) => {
20+
if (el.match(/_use/)) hookState[el] = statements[i + 2];
21+
});
22+
}
23+
24+
function findHookDeclarations(astVal) {
25+
astVal.forEach(elem => {
26+
if (elem.type === 'VariableDeclaration') {
27+
elem.declarations.forEach(decClar => {
28+
statements.push(decClar.id.name);
29+
});
30+
}
31+
});
32+
}
33+
34+
// handle useState useContext
35+
if (ast[0].expression.body.body) {
36+
ast = ast[0].expression.body.body;
2837
// Hook Declarations will only be under 'VariableDeclaration' type
29-
if (program.type === 'VariableDeclaration') {
30-
program.declarations.forEach(dec => {
31-
statements.push(dec.id.name);
32-
});
33-
}
34-
});
35-
// Iterate through the array and determine getter/setters based on pattern
36-
for (let i = 0; i < statements.length; i += 1) {
37-
if (statements[i].match(/_use/)) {
38-
hookState[statements[i]] = statements[i + 2];
39-
}
38+
findHookDeclarations(ast);
39+
// Iterate array and determine getter/setters based on pattern
40+
saveAstHooks(statements); // add key-value to hookState
41+
} else {
42+
// TODO test if this is needed, backward compatibility?
43+
// Iterate through AST of every function declaration
44+
// Check within each function declaration if there are hook declarations
45+
ast.forEach(functionDec => {
46+
const { body } = functionDec.body;
47+
// Traverse through the function's funcDecs and Expression Statements
48+
findHookDeclarations(body);
49+
// Iterate array and determine getter/setters based on pattern
50+
saveAstHooks(statements); // add key-value to hookState
51+
});
4052
}
41-
// });
4253
}
4354
return hookState;
4455
};

package/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,17 @@ const mode = {
99
const linkFiber = require('./linkFiber')(snapShot, mode);
1010
const timeJump = require('./timeJump')(snapShot, mode);
1111

12-
window.addEventListener('message', ({ data: { action, payload } }) => { //runs automatically twice per second with inspectedElement
12+
window.addEventListener('message', ({ data: { action, payload } }) => {
13+
//runs automatically twice per second with inspectedElement
1314
switch (action) {
1415
case 'jumpToSnap':
1516
timeJump(payload);
17+
// Get the pathname from payload and add new entry to browser history
18+
// MORE: https://developer.mozilla.org/en-US/docs/Web/API/History/pushState
19+
if (payload.children[0].state && payload.children[0].state.location) {
20+
const route = payload.children[0].state.location.pathname;
21+
window.history.pushState('', '', route);
22+
}
1623
break;
1724
case 'setLock':
1825
mode.locked = payload;

package/linkFiber.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,13 @@ module.exports = (snap, mode) => {
7070
let index = 0;
7171
astHooks = Object.values(astHooks);
7272
// while memoizedState is truthy, save the value to the object
73-
while (memoizedState && memoizedState.queue) { // prevents useEffect from crashing on load
74-
if (memoizedState.next && memoizedState.next.queue === null) { // prevents double pushing snapshot updates
75-
changeUseState(memoizedState);
76-
}
77-
// memoized[astHooks[index]] = memoizedState.memoizedState;
73+
while (memoizedState && memoizedState.queue) {
74+
changeUseState(memoizedState);
75+
7876
memoized[astHooks[index]] = memoizedState.memoizedState;
7977
// Reassign memoizedState to its next value
8078
memoizedState = memoizedState.next;
81-
// Increment the index by 2
82-
index += 2;
79+
index += 2; // Increment the index by 2
8380
}
8481
return memoized;
8582
}
@@ -104,7 +101,10 @@ module.exports = (snap, mode) => {
104101
changeSetState(stateNode);
105102
}
106103
// Check if the component uses hooks
107-
if (memoizedState && Object.hasOwnProperty.call(memoizedState, 'baseState')) {
104+
if (
105+
memoizedState
106+
&& Object.hasOwnProperty.call(memoizedState, 'baseState')
107+
) {
108108
// Traverse through the currentFiber and extract the getters/setters
109109
astHooks = astParser(elementType);
110110
saveState(astHooks);

src/app/__tests__/TravelContainer.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ describe('testing the play-button', () => {
8181
wrapper = shallow(<TravelContainer snapshotsLength={2} />);
8282
expect(wrapper.find('.play-button').text()).toBe('Play');
8383
});
84-
});
84+
});

src/app/containers/StateContainer.jsx

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,55 @@
11
import React, { useState } from 'react';
22
import PropTypes from 'prop-types';
33
import {
4-
MemoryRouter as Router, Route, NavLink, Switch,
4+
MemoryRouter as Router,
5+
Route,
6+
NavLink,
7+
Switch,
58
} from 'react-router-dom';
69
import StateRoute from '../components/StateRoute';
710
import DiffRoute from '../components/DiffRoute';
811

9-
1012
// eslint-disable-next-line react/prop-types
1113
const StateContainer = ({ snapshot, hierarchy }) => {
12-
const [ Text, setText ] = useState('State');
14+
const [Text, setText] = useState('State');
1315
return (
1416
<Router>
1517
<div className="state-container">
1618
<div className="main-navbar-container">
17-
<div className="main-navbar-text">
18-
{Text}
19-
</div>
19+
<div className="main-navbar-text">{Text}</div>
2020
<div className="main-navbar">
21-
<NavLink className="main-router-link" activeClassName="is-active" exact to="/">
21+
<NavLink
22+
className="main-router-link"
23+
activeClassName="is-active"
24+
exact
25+
to="/"
26+
>
2227
State
2328
</NavLink>
24-
<NavLink className="main-router-link" activeClassName="is-active" to="/diff">
29+
<NavLink
30+
className="main-router-link"
31+
activeClassName="is-active"
32+
to="/diff"
33+
>
2534
Diff
2635
</NavLink>
2736
</div>
2837
</div>
2938
<Switch>
30-
<Route path="/diff" render={() => { setText('Diff'); return <DiffRoute snapshot={snapshot} />; }} />
31-
<Route path="/" render={() => { setText('State'); return <StateRoute snapshot={snapshot} hierarchy={hierarchy} />; }} />
39+
<Route
40+
path="/diff"
41+
render={() => {
42+
setText('Diff');
43+
return <DiffRoute snapshot={snapshot} />;
44+
}}
45+
/>
46+
<Route
47+
path="/"
48+
render={() => {
49+
setText('State');
50+
return <StateRoute snapshot={snapshot} hierarchy={hierarchy} />;
51+
}}
52+
/>
3253
</Switch>
3354
</div>
3455
</Router>

src/app/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ import App from './components/App';
55
import './styles/main.scss';
66

77
ReactDOM.render(<App />, document.getElementById('root'));
8-
9-
10-
// chris test

src/extension/background.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ const firstSnapshotReceived = {};
88
// there will be the same number of objects in here as there are reactime tabs open for each user application being worked on
99
const tabsObj = {};
1010

11-
console.log("background scripts");
1211

1312
function createTabObj(title) {
14-
1513
// update tabsObj
1614
return {
1715
title,
@@ -62,14 +60,17 @@ function changeCurrLocation(tabObj, rootNode, index) {
6260
return;
6361
// if not, recurse on each one of the children
6462
}
65-
rootNode.children.forEach(child => {
66-
changeCurrLocation(tabObj, child, index);
67-
});
63+
// added if (rootNode.children) { <=======
64+
if (rootNode.children) {
65+
rootNode.children.forEach(child => {
66+
changeCurrLocation(tabObj, child, index);
67+
});
68+
}
6869
}
6970

70-
7171
// establishing connection with devtools
72-
chrome.runtime.onConnect.addListener(port => { // port is one end of the connection - an object
72+
chrome.runtime.onConnect.addListener(port => {
73+
// port is one end of the connection - an object
7374

7475
// push every port connected to the ports array
7576
portsArr.push(port);
@@ -92,8 +93,9 @@ chrome.runtime.onConnect.addListener(port => { // port is one end of the connect
9293
}
9394
});
9495

95-
// receive snapshot from devtools and send it to contentScript -
96-
port.onMessage.addListener(msg => { // msg is action denoting a time jump in devtools
96+
// receive snapshot from devtools and send it to contentScript -
97+
port.onMessage.addListener(msg => {
98+
// msg is action denoting a time jump in devtools
9799

98100
// ---------------------------------------------------------------
99101
// message incoming from devTools should look like this:
@@ -143,7 +145,11 @@ chrome.runtime.onMessage.addListener((request, sender) => {
143145
let isReactTimeTravel = false;
144146

145147
// Filter out tabs that don't have reactime
146-
if (action === 'tabReload' || action === 'recordSnap' || action === 'jumpToSnap') {
148+
if (
149+
action === 'tabReload'
150+
|| action === 'recordSnap'
151+
|| action === 'jumpToSnap'
152+
) {
147153
isReactTimeTravel = true;
148154
} else return;
149155

@@ -191,7 +197,10 @@ chrome.runtime.onMessage.addListener((request, sender) => {
191197
reloaded[tabId] = false;
192198

193199
tabsObj[tabId].snapshots.push(request.payload);
194-
sendToHierarchy(tabsObj[tabId], new Node(request.payload, tabsObj[tabId]));
200+
sendToHierarchy(
201+
tabsObj[tabId],
202+
new Node(request.payload, tabsObj[tabId]),
203+
);
195204
if (portsArr.length > 0) {
196205
portsArr.forEach(bg => bg.postMessage({
197206
action: 'initialConnectSnapshots',
@@ -207,7 +216,10 @@ chrome.runtime.onMessage.addListener((request, sender) => {
207216
} else {
208217
tabsObj[tabId].snapshots.push(request.payload);
209218
//! INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN!!!!
210-
sendToHierarchy(tabsObj[tabId], new Node(request.payload, tabsObj[tabId]));
219+
sendToHierarchy(
220+
tabsObj[tabId],
221+
new Node(request.payload, tabsObj[tabId]),
222+
);
211223
}
212224
// send message to devtools
213225
if (portsArr.length > 0) {
@@ -253,7 +265,6 @@ chrome.runtime.onInstalled.addListener(() => {
253265
// when context menu is clicked, listen for the menuItemId,
254266
// if user clicked on reactime, open the devtools window
255267
chrome.contextMenus.onClicked.addListener(({ menuItemId }) => {
256-
console.log("clicked menu");
257268
const options = {
258269
type: 'panel',
259270
left: 0,

0 commit comments

Comments
 (0)