Skip to content

Commit 6c77ebd

Browse files
committed
merged with dev
2 parents ecf6010 + 0262055 commit 6c77ebd

File tree

9 files changed

+114
-41
lines changed

9 files changed

+114
-41
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 react-time-travel
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

readme.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
1-
This is react-time-travel
2-
A debugging tool for react in chrome extension.
1+
# React-Time-Travel
32

4-
TESTING DEV
3+
A debugging tool for React. Records state whenever state is changed and allows user to jump to any previous recorded state.
4+
5+
Two parts are needed for this tool to function. The chrome extension must be installed, and the NPM package must be installed and used in the React code.
6+
7+
## Installing
8+
9+
1. Download the Chrome extension from Chrome Web Store.
10+
11+
2. Install the npm package in your code.
12+
```
13+
npm i react-time-travel
14+
```
15+
3. Call the `linkFiber` method on your root container after rendering your App.
16+
17+
```
18+
const { linkFiber } = require('react-time-travel');
19+
20+
const rootContainer = document.getElementById('root');
21+
ReactDom.render(<App />, rootContainer);
22+
23+
linkFiber(rootContainer);
24+
```
25+
26+
4. Done! That's all you have to do to link your React project to our library.
27+
28+
## How to Use
29+
30+
After installing both the Chrome extension and the npm package, just open up your project in the browser.
31+
32+
Then open up your Chrome DevTools. There'll be a new tab called React-Time-Travel.
33+
34+
## Authors
35+
36+
* **Ryan Dang** - [@rydang](https://github.com/rydang)
37+
* **Bryan Lee** - [@mylee1995](https://github.com/mylee1995)
38+
* **Josh Kim** - [@joshua0308](https://github.com/joshua0308)
39+
* **Sierra Swaby** - [@starkspark](https://github.com/starkspark)
40+
41+
## License
42+
43+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

src/app/components/Action.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const Action = (props) => {
1515
<div
1616
className="jump-button"
1717
onClick={() => handleJumpSnapshot(index)}
18-
onKeyPress={() => console.log('key pressed')}
1918
tabIndex={index}
2019
role="button"
2120
>

src/app/components/Tree.jsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import React from 'react';
22
import JSONTree from 'react-json-tree';
3+
import PropTypes from 'prop-types';
34

45
const getItemString = (type, data, itemType, itemString) => (
56
<span>
6-
{/* //
7-
{type} */}
7+
{data.name}
88
</span>
99
);
1010

1111
const Tree = (props) => {
1212
const { snapshot } = props;
13-
console.log('TREE COMPONENT IS PRINTED');
14-
console.log(snapshot);
1513
return (
1614
<React.Fragment>
1715
{snapshot && (
@@ -20,11 +18,26 @@ const Tree = (props) => {
2018
theme={{ tree: () => ({ className: 'json-tree' }) }}
2119
shouldExpandNode={() => true}
2220
getItemString={getItemString}
23-
// labelRenderer={raw => <strong>{raw}</strong>}
24-
// valueRenderer={raw => <em>{raw}</em>}
21+
labelRenderer={(raw) => {
22+
if (typeof raw[0] !== 'number') return <span>{raw[0]}</span>;
23+
}}
2524
/>
2625
)}
2726
</React.Fragment>
2827
);
2928
};
29+
30+
Tree.propTypes = {
31+
snapshot: PropTypes.shape({
32+
state: PropTypes.oneOfType([
33+
PropTypes.string,
34+
PropTypes.object,
35+
]),
36+
children: PropTypes.arrayOf(
37+
PropTypes.object,
38+
),
39+
name: PropTypes.string,
40+
}).isRequired,
41+
};
42+
3043
export default Tree;

src/app/containers/MainContainer.jsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,11 @@ class MainContainer extends Component {
3939
switch (action) {
4040
case 'sendSnapshots': {
4141
const snapshotIndex = payload.length - 1;
42-
4342
// set state with the information received from the background script
4443
this.setState({ snapshots: payload, snapshotIndex });
4544
break;
4645
}
47-
case 'initialConnectSnapshot': {
46+
case 'initialConnectSnapshots': {
4847
const { snapshots, mode } = payload;
4948
const snapshotIndex = snapshots.length - 1;
5049
this.setState({ snapshots, snapshotIndex, mode });
@@ -83,7 +82,7 @@ class MainContainer extends Component {
8382
}
8483

8584
play() {
86-
globalPlaying = !globalPlaying
85+
globalPlaying = !globalPlaying;
8786
this.setState({ playing: globalPlaying }, () => {
8887
if (this.state.playing) {
8988
intervalId = setInterval(() => {
@@ -101,11 +100,11 @@ class MainContainer extends Component {
101100
} else {
102101
clearInterval(intervalId);
103102
}
104-
})
103+
});
105104
}
106105

107106
pause() {
108-
this.setState({ playing: false }, clearInterval(intervalId))
107+
this.setState({ playing: false }, clearInterval(intervalId));
109108
}
110109

111110
emptySnapshot() {
@@ -145,7 +144,7 @@ class MainContainer extends Component {
145144
exportSnapshots() {
146145
const fileUpload = document.createElement('input');
147146
fileUpload.setAttribute('type', 'file');
148-
147+
149148
fileUpload.click();
150149
this;
151150
}
@@ -183,7 +182,7 @@ class MainContainer extends Component {
183182
handleJumpSnapshot={this.handleJumpSnapshot}
184183
emptySnapshot={this.emptySnapshot}
185184
/>
186-
<StateContainer snapshot={snapshots[snapshotIndex]} />
185+
{(snapshots.length) ? <StateContainer snapshot={snapshots[snapshotIndex]} /> : null}
187186
<TravelContainer
188187
snapshotsLength={snapshots.length}
189188
snapshotIndex={snapshotIndex}

src/app/containers/TravelContainer.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const TravelContainer = ({
1515
}) => (
1616
<div className="travel-container">
1717
<div className="play-button" onClick={play}>
18-
{ playing ? 'Pause': 'Play' }
18+
{playing ? 'Pause' : 'Play'}
1919
</div>
2020
<MainSlider
2121
snapshotLength={snapshotsLength}
@@ -34,13 +34,14 @@ const TravelContainer = ({
3434
);
3535

3636
TravelContainer.propTypes = {
37-
pause: PropTypes.func.isRequried,
37+
pause: PropTypes.func.isRequired,
3838
play: PropTypes.func.isRequired,
3939
moveBackward: PropTypes.func.isRequired,
4040
moveForward: PropTypes.func.isRequired,
4141
snapshotsLength: PropTypes.number.isRequired,
4242
handleChangeSnapshot: PropTypes.func.isRequired,
4343
handleJumpSnapshot: PropTypes.func.isRequired,
4444
snapshotIndex: PropTypes.number.isRequired,
45+
playing: PropTypes.bool.isRequired,
4546
};
4647
export default TravelContainer;

src/extension/background.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ chrome.runtime.onConnect.addListener((port) => {
1515
// send it to devtools as soon as connection to devtools is made
1616
if (snapshotArr.length > 0) {
1717
bg.postMessage({
18-
action: 'initialConnectSnapshot',
18+
action: 'initialConnectSnapshots',
1919
payload: {
2020
snapshots: snapshotArr,
2121
mode,
@@ -57,28 +57,34 @@ chrome.runtime.onMessage.addListener((request) => {
5757
switch (action) {
5858
case 'tabReload':
5959
firstSnapshot = true;
60+
mode.locked = false;
61+
mode.paused = false;
6062
if (!persist) snapshotArr = [];
6163
break;
6264
case 'recordSnap':
63-
// don't do anything for the first snapshot if current mode is persist
64-
if (persist && firstSnapshot) {
65+
if (firstSnapshot) {
6566
firstSnapshot = false;
67+
// don't add anything to snapshot storage if mode is persisting for the initial snapshot
68+
if (!persist) snapshotArr.push(request.payload);
69+
bg.postMessage({
70+
action: 'initialConnectSnapshots',
71+
payload: {
72+
snapshots: snapshotArr,
73+
mode,
74+
},
75+
});
6676
break;
6777
}
68-
firstSnapshot = false;
6978
snapshotArr.push(request.payload);
70-
// if port is not null, send a message to devtools
71-
if (bg) {
72-
// TODO:
73-
// get active tab id
74-
// get snapshot arr from tab object
79+
// TODO:
80+
// get active tab id
81+
// get snapshot arr from tab object
7582

76-
// send message to devtools
77-
bg.postMessage({
78-
action: 'sendSnapshots',
79-
payload: snapshotArr,
80-
});
81-
}
83+
// send message to devtools
84+
bg.postMessage({
85+
action: 'sendSnapshots',
86+
payload: snapshotArr,
87+
});
8288
break;
8389
default:
8490
}

src/extension/contentScript.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
console.log('contentScript running');
2-
31
// listening for messages from npm package
42
window.addEventListener('message', (msg) => {
53
// post initial Message to npm package
6-
const { action, payload } = msg.data;
7-
console.log('npm -> contentScript', msg.data);
4+
const { action } = msg.data;
85
if (action === 'recordSnap') chrome.runtime.sendMessage(msg.data);
96
});
107

118
// listening for messages from background.js
12-
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
9+
chrome.runtime.onMessage.addListener((request) => {
1310
// send the message to npm package
1411
const { action } = request;
1512
switch (action) {
@@ -29,4 +26,3 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
2926
chrome.runtime.sendMessage({ action: 'tabReload' });
3027

3128
window.postMessage({ action: 'contentScriptStarted' });
32-
console.log('contentScriptStarted msg sent');

src/extension/devtools.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
chrome.devtools.panels.create('React Time-Travel', null, 'panel.html', (panel) => {
2-
console.log('devtools.js => panel created');
32
});

0 commit comments

Comments
 (0)