Skip to content

Commit 11afd76

Browse files
committed
merged with dev
2 parents 946442f + 0262055 commit 11afd76

File tree

11 files changed

+163
-38
lines changed

11 files changed

+163
-38
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.

package/linkFiber.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ module.exports = (snap, mode) => {
2424

2525
function newSetState(state, callback = () => { }) {
2626
// dont do anything if state is locked
27-
if (mode.locked) return;
27+
// UNLESS we are currently jumping through time
28+
if (mode.locked && !mode.jumping) return;
2829
// continue normal setState functionality, except add sending message middleware
2930
oldSetState(state, () => {
3031
updateSnapShotTree();

package/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-time-travel",
3-
"version": "1.0.1",
3+
"version": "1.0.4",
44
"description": "A library that helps debug React by memorizing the state of components with every render.",
55
"main": "index.js",
66
"repository": {

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: 20 additions & 3 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 });
@@ -82,11 +81,18 @@ class MainContainer extends Component {
8281
}
8382
}
8483

84+
<<<<<<< HEAD
8585
play(speed = 1000) {
8686
globalPlaying = !globalPlaying;
8787
this.setState({ playing: globalPlaying }, () => {
8888
const { playing } = this.state;
8989
if (playing) {
90+
=======
91+
play() {
92+
globalPlaying = !globalPlaying;
93+
this.setState({ playing: globalPlaying }, () => {
94+
if (this.state.playing) {
95+
>>>>>>> dev
9096
intervalId = setInterval(() => {
9197
const { snapshots, snapshotIndex } = this.state;
9298
if (snapshotIndex < snapshots.length - 1) {
@@ -96,9 +102,15 @@ class MainContainer extends Component {
96102
// clear interval when play reaches the end
97103
globalPlaying = false;
98104
clearInterval(intervalId);
105+
<<<<<<< HEAD
99106
this.setState({ playing: false });
100107
}
101108
}, speed);
109+
=======
110+
this.setState({ playing: false })
111+
}
112+
}, 1000);
113+
>>>>>>> dev
102114
} else {
103115
clearInterval(intervalId);
104116
}
@@ -168,7 +180,7 @@ class MainContainer extends Component {
168180
handleJumpSnapshot={this.handleJumpSnapshot}
169181
emptySnapshot={this.emptySnapshot}
170182
/>
171-
<StateContainer snapshot={snapshots[snapshotIndex]} />
183+
{(snapshots.length) ? <StateContainer snapshot={snapshots[snapshotIndex]} /> : null}
172184
<TravelContainer
173185
snapshotsLength={snapshots.length}
174186
snapshotIndex={snapshotIndex}
@@ -177,9 +189,14 @@ class MainContainer extends Component {
177189
moveBackward={this.moveBackward}
178190
moveForward={this.moveForward}
179191
play={this.play}
192+
<<<<<<< HEAD
180193
pause={this.pause}
181194
playing={playing}
182195
playSpeed={playSpeed}
196+
=======
197+
playing={playing}
198+
pause={this.pause}
199+
>>>>>>> dev
183200
/>
184201
<ButtonsContainer mode={mode} toggleMode={this.toggleMode} />
185202
</div>

src/app/containers/TravelContainer.jsx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
33
import MainSlider from '../components/MainSlider';
44
import Dropdown from '../components/Dropdown';
55

6+
<<<<<<< HEAD
67
const options = [
78
{ value: 2000, label: '0.5x' },
89
{ value: 1000, label: '1.0x' },
@@ -62,15 +63,48 @@ class TravelContainer extends Component {
6263
);
6364
}
6465
}
66+
=======
67+
const TravelContainer = ({
68+
moveBackward,
69+
moveForward,
70+
snapshotsLength,
71+
handleChangeSnapshot,
72+
handleJumpSnapshot,
73+
snapshotIndex,
74+
play,
75+
playing,
76+
pause,
77+
}) => (
78+
<div className="travel-container">
79+
<div className="play-button" onClick={play}>
80+
{playing ? 'Pause' : 'Play'}
81+
</div>
82+
<MainSlider
83+
snapshotLength={snapshotsLength}
84+
handleChangeSnapshot={handleChangeSnapshot}
85+
snapshotIndex={snapshotIndex}
86+
handleJumpSnapshot={handleJumpSnapshot}
87+
pause={pause}
88+
/>
89+
<div className="backward-button" onClick={moveBackward}>
90+
{'<'}
91+
</div>
92+
<div className="forward-button" onClick={moveForward}>
93+
{'>'}
94+
</div>
95+
</div>
96+
);
97+
>>>>>>> dev
6598

6699
TravelContainer.propTypes = {
67-
pause: PropTypes.func.isRequried,
100+
pause: PropTypes.func.isRequired,
68101
play: PropTypes.func.isRequired,
69102
moveBackward: PropTypes.func.isRequired,
70103
moveForward: PropTypes.func.isRequired,
71104
snapshotsLength: PropTypes.number.isRequired,
72105
handleChangeSnapshot: PropTypes.func.isRequired,
73106
handleJumpSnapshot: PropTypes.func.isRequired,
74107
snapshotIndex: PropTypes.number.isRequired,
108+
playing: PropTypes.bool.isRequired,
75109
};
76110
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');

0 commit comments

Comments
 (0)