Skip to content

Commit ff3d219

Browse files
committed
merged dev
2 parents 5e31fb5 + 01eba9e commit ff3d219

20 files changed

+249
-98
lines changed

.eslintrc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
22
"extends": ["airbnb", "plugin:jest/recommended"],
33
"root": true,
4-
"plugins": ["jest"],
4+
"plugins": ["jest"],
55
"env": {
66
"jest/globals": true,
77
"browser": true,
8-
"webextensions": true,
8+
"webextensions": true
99
},
10-
"globals": {
11-
"fetch": false,
10+
"globals": {
11+
"fetch": false
12+
},
13+
"rules": {
14+
"arrow-parens": [2, "as-needed"]
1215
}
1316
}

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
services:
2+
- docker
3+
script:
4+
- docker-compose up --abort-on-container-exit
5+
deploy:
6+
provider: script
7+
skip_cleanup: true
8+
on:
9+
branches:
10+
only:
11+
- dev
12+
- master

docker-compose.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
version: '3'
1+
version: '2'
22
services:
33
test:
44
image: reacttt/test-lint
55
container_name: reacttt-test-lint
66
volumes:
77
- .:/usr/src/app
8-
- node_modules:/usr/src/app/node_modules
9-
command: bash -c "npm run lint && npm test"
10-
volumes:
11-
node_modules:
8+
- /usr/src/app/node_modules
9+
command: npm run docker-test-lint

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"test": "jest --verbose --coverage --watchAll",
99
"lint": "eslint --ext .js --ext .jsx src",
1010
"docker-build": "docker build -t reacttt/test-lint .",
11-
"docker-check": "docker-compose up --abort-on-container-exit"
11+
"docker-check": "docker-compose up --abort-on-container-exit",
12+
"docker-test-lint": "eslint --ext .js --ext .jsx src && jest --verbose"
1213
},
1314
"keywords": [
1415
"react",

package/readme.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# React-Time-Travel
2+
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](https://www.npmjs.com/package/react-time-travel) in your code.
12+
```
13+
npm i react-time-travel
14+
```
15+
3. Call the library method on your root container after rendering your App.
16+
17+
```
18+
const reactTimeTravel = require('react-time-travel');
19+
20+
const rootContainer = document.getElementById('root');
21+
ReactDom.render(<App />, rootContainer);
22+
23+
reactTimeTravel(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+
## Features
35+
36+
### Recording
37+
38+
Whenever state is changed (whenever setState is called), this extension will create a snapshot of the current state tree and record it. Each snapshot will be displayed in Chrome DevTools under the React-Time-Travel panel.
39+
40+
### Viewing
41+
42+
You can click on a snapshot to view your app's state. State can be visualized in a JSON or a tree.
43+
44+
The selected snapshot can also be diffed/compared with the current dom.
45+
46+
### Jumping
47+
48+
The most important feature of all. Jumping to any previous recorded snapshot. Hitting the jump button on any snapshot will change the dom by setting their state. One important thing to note. This library does not work well when mixing React with direct DOM manipulation. Since DOM manipulation doesn't change any React state, this library cannot record or even detect that change. Of course, you should be avoiding mixing the two in the first place.
49+
50+
### Others
51+
52+
Other handy features include:
53+
* multiple tabs support
54+
* a slider to move through snapshots quickly
55+
* a play button to move through snapshots automatically
56+
* a pause which button stops recording each snapshot
57+
* a lock button to freeze the DOM in place. setState will lose all functionality while the extension is locked
58+
* a persist button to keep snapshots upon refresh. handy when changing code and debugging
59+
* export/import the current snapshots in memory
60+
61+
## Authors
62+
63+
* **Ryan Dang** - [@rydang](https://github.com/rydang)
64+
* **Bryan Lee** - [@mylee1995](https://github.com/mylee1995)
65+
* **Josh Kim** - [@joshua0308](https://github.com/joshua0308)
66+
* **Sierra Swaby** - [@starkspark](https://github.com/starkspark)
67+
68+
## License
69+
70+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

package/tree.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ class Tree {
44
// give it a special state = 'root'
55
// a setState function that just calls the callback instantly
66
if (!useStateInstead) {
7-
this.component = (component === 'root') ? { state: 'root', setState: (partial, callback) => callback() } : component;
7+
this.component = component === 'root'
8+
? { state: 'root', setState: (partial, callback) => callback() }
9+
: component;
810
} else {
911
this.state = component;
1012
this.name = name;
@@ -21,7 +23,9 @@ class Tree {
2123
// deep copies only the state of each component and creates a new tree
2224
getCopy(copy = new Tree('root', true)) {
2325
// copy state of children
24-
copy.children = this.children.map(child => new Tree(child.component.state, true, child.component.constructor.name));
26+
copy.children = this.children.map(
27+
child => new Tree(child.component.state, true, child.component.constructor.name),
28+
);
2529

2630
// copy children's children recursively
2731
this.children.forEach((child, i) => child.getCopy(copy.children[i]));
@@ -31,15 +35,14 @@ class Tree {
3135
// print out the tree in the console
3236
print() {
3337
const children = ['children: '];
34-
this.children.forEach((child) => {
38+
this.children.forEach(child => {
3539
children.push(child.state || child.component.state);
3640
});
3741
if (this.name) console.log(this.name);
3842
if (children.length === 1) {
3943
console.log(this.state || this.component.state);
40-
}
41-
else console.log(this.state || this.component.state, ...children);
42-
this.children.forEach((child) => {
44+
} else console.log(this.state || this.component.state, ...children);
45+
this.children.forEach(child => {
4346
child.print();
4447
});
4548
}

readme.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Two parts are needed for this tool to function. The chrome extension must be ins
88

99
1. Download the Chrome extension from Chrome Web Store.
1010

11-
2. Install the npm package in your code.
11+
2. Install the [npm package](https://www.npmjs.com/package/react-time-travel) in your code.
1212
```
1313
npm i react-time-travel
1414
```
@@ -31,6 +31,33 @@ After installing both the Chrome extension and the npm package, just open up you
3131

3232
Then open up your Chrome DevTools. There'll be a new tab called React-Time-Travel.
3333

34+
## Features
35+
36+
### Recording
37+
38+
Whenever state is changed (whenever setState is called), this extension will create a snapshot of the current state tree and record it. Each snapshot will be displayed in Chrome DevTools under the React-Time-Travel panel.
39+
40+
### Viewing
41+
42+
You can click on a snapshot to view your app's state. State can be visualized in a JSON or a tree.
43+
44+
The selected snapshot can also be diffed/compared with the current dom.
45+
46+
### Jumping
47+
48+
The most important feature of all. Jumping to any previous recorded snapshot. Hitting the jump button on any snapshot will change the dom by setting their state. One important thing to note. This library does not work well when mixing React with direct DOM manipulation. Since DOM manipulation doesn't change any React state, this library cannot record or even detect that change. Of course, you should be avoiding mixing the two in the first place.
49+
50+
### Others
51+
52+
Other handy features include:
53+
* multiple tabs support
54+
* a slider to move through snapshots quickly
55+
* a play button to move through snapshots automatically
56+
* a pause which button stops recording each snapshot
57+
* a lock button to freeze the DOM in place. setState will lose all functionality while the extension is locked
58+
* a persist button to keep snapshots upon refresh. handy when changing code and debugging
59+
* export/import the current snapshots in memory
60+
3461
## Authors
3562

3663
* **Ryan Dang** - [@rydang](https://github.com/rydang)

src/app/__tests__/MainContainer.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ global.chrome = chrome;
3838
let eventListener;
3939
const port = {
4040
onMessage: {
41-
addListener: ((fn) => {
41+
addListener: fn => {
4242
eventListener = fn;
43-
}),
43+
},
4444
},
4545
onDisconnect: {
46-
addListener: () => { },
46+
addListener: () => {},
4747
},
4848
};
4949
chrome.runtime.connect.returns(port);

src/app/__tests__/action.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ describe('unit testing for Action.jsx', () => {
5656
});
5757

5858
test('should invoke dispatch method when clicked', () => {
59-
wrapper.find('.jump-button').simulate('click', { stopPropagation() { } });
59+
wrapper.find('.jump-button').simulate('click', { stopPropagation() {} });
6060
expect(props.dispatch).toHaveBeenCalled();
6161
});
6262

6363
test('dispatch should send a changeSlider action', () => {
64-
wrapper.find('.jump-button').simulate('click', { stopPropagation() { } });
64+
wrapper.find('.jump-button').simulate('click', { stopPropagation() {} });
6565
expect(props.dispatch.mock.calls[0][0]).toEqual(changeSlider(props.index));
6666
});
6767
});

src/app/components/Action.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
33

44
import { changeView, changeSlider } from '../actions/actions';
55

6-
const Action = (props) => {
6+
const Action = props => {
77
const {
88
selected, index, sliderIndex, dispatch,
99
} = props;
@@ -18,7 +18,7 @@ const Action = (props) => {
1818
<div className="action-component-text">{index}</div>
1919
<button
2020
className="jump-button"
21-
onClick={(e) => {
21+
onClick={e => {
2222
e.stopPropagation();
2323
dispatch(changeSlider(index));
2424
}}

0 commit comments

Comments
 (0)