Skip to content

Commit

Permalink
Merge pull request #16 from oslabs-beta/dev50
Browse files Browse the repository at this point in the history
Merge into OS Labs Beta master branch
  • Loading branch information
khobread authored Jun 14, 2022
2 parents 89c4310 + 09907b1 commit bd63b09
Show file tree
Hide file tree
Showing 48 changed files with 2,138 additions and 1,330 deletions.
72 changes: 43 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<br>
</h1>

<h4 align="center"> Reactime is a performance and debugging tool for React developers <b>(Beta version for Gatsby and Next.js)</b>. It records a snapshot whenever a target application's state is changed and allows the user to jump to any previously recorded state. It also detects the amount of renders of each component and average time of rendering.</h4>
<h4 align="center"> Reactime is an open source Chrome developer tool for time travel debugging and performance monitoring in React applications. Reactime enables developers to record snapshots of application state, jump between and inspect state snapshots, and monitor performance metrics such as component render time and render frequency. </h4>

<br>
<p align="center">
Expand Down Expand Up @@ -43,18 +43,18 @@
<a href="#how-to-use">How To Use</a> • <a href="#features">Features</a> • <a href="https://reactime.io">Website</a> • <a href="#read-more">Read More</a>
</p>

Currently, Reactime supports React apps using stateful components and Hooks, with beta support for Recoil and Context API and frameworks like Gatsby and Next.js.
Currently, Reactime supports React apps (now including React Router apps) using stateful components and Hooks, with beta support for Recoil and Context API and frameworks like Gatsby and Next.js.

<b>Reactime 13.0</b> has added the exciting features below:
<b>Reactime 14.0</b> has added the exciting features below:

I. Action Comparison Tool
Users now have the ability to name, save, and analyze specific action snapshots within a saved series. This feature allows engineers to compare component render times throughout the development process of their application, providing them with metrics to show any improvements or changes.
I. React Router Compatibility <br>
Reactime is now compatible with React Router applications! Prior to Reactime 14.0, recording state snapshots as the user navigated across various routes was possible, but time travel debugging was only possible for the current route (i.e. jumping back to a prior state at a different route was not possible). In order to streamline debugging of applications with multiple routes, Reactime 14.0 added functionality that allows the user to time-travel back to different routes, including live updating in the browser to reflect the state of their application at that previously visited route.

II. Reactime Visual Tutorial Walkthrough
While Reactime offers a user friendly and intuitive interface, users can now access a guided tutorial, walking the user through each feature while explaining practical use cases and added benefits that Reactime can provide. The walkthrough utilizes the Intro.js library, providing a visual experience that highlights and cycles through each COMPONENT displayed on the app.
II. Classifying State Snapshots by Route <br>
The list of state snapshots in the Reactime dashboard is now classified by route to give the developer visual cues of the snapshot-route relationship and make time travel debugging of various routes easier.

III. State Monitoring Toggle Feature
Added toggle feature allows users to temporarily pause Reactime's state monitoring of the linked application. This allows users to make state changes within their application without populating the actions container within Reactime. Especially useful when trying to limit and compare the number of actions within one series that a user is planning to save. Relinking Reactime to the application is as simple as toggling the record button back to it's original state!
III. Filtering Performance Metrics by Route <br>
The Reactime dashboard includes a stacked bar graph showing render times for each component, with a separate bar stack for each snapshot. With Reactime 14.0, this composite bar graph can now be filtered by route to allow the developer to review detailed performance data by route.

After installing Reactime, you can test its functionalities with your React application in development mode.

Expand Down Expand Up @@ -92,38 +92,52 @@ Reactime is an open source project, and we’d really appreciate your help with

## <b>Features</b>

### 🔹 Re-render Optimization

One of the most common issues that affects performance in React is unnecessary render cycles. This problem can be fixed by checking your renders in the Performance tab in Chrome DevTools under the Reactime panel.

### 🔹 Gatsby
### 🔹 Viewing

Reactime offers fully support for Gatsby applications. You would be able to identify unnecessary renders, duration of each rendering, travel-debugging features and visual representation of the tree components.
You can view your application's file structure and click on a snapshot to view your app's state. State can be visualized in a Component Graph, JSON Tree, or Performance Graph. Snapshots can be diffed with the previous snapshot, which can be viewed in Diff mode.
<br>
<br>
<p align="center">
<img src="./assets/map-viewing.gif" />
</p>
<br>

### 🔹 Next.js
### 🔹 Snapshot Series and Action Comparison

Reactime offers debugging and performance tools for Next.js apps: time-traveling debugging, preventing unnecessary components re-renders and making your application faster.
You can save a series of state snapshots and use it to analyze changes in component render performance between current and previous series of snapshots. You can also name specific snapshots and compare all snapshots with the same name.
<br>
<br>
<p align="center">
<img src="./assets/action-comparison.gif" />
</p>
<br>

### 🔹 Recording

Whenever state is changed (whenever setState, useState 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 Reactime panel.

### 🔹 Snapshot Series and Action Comparison

You can save a series of state snapshots and use it to analyze changes in component render performance between current and previous series of snapshots. You can also name specific snapshots and compare all snapshots with the same name.
<br>
<br>
<p align="center">
<img src="http://g.recordit.co/KNxvT94qxd.gif" />
<img src="./assets/history-tree.gif" />
</p>
<br>

### 🔹 Viewing
### 🔹 Re-render Optimization

You can click on a snapshot to view your app's state. State can be visualized in a Component Graph, JSON Tree, or Performance Graph. Snapshots can be diffed with the previous snapshot, which can be viewed in Diff mode.
One of the most common issues that affects performance in React is unnecessary render cycles. This problem can be fixed by checking your renders in the Performance tab in Chrome DevTools under the Reactime panel.

### 🔹 Jumping

Using the actions sidebar, a user can jump to any previous recorded snapshots. Hitting the jump button on any snapshot will allow a user to view state data at any point in the history of the target application.

### 🔹 Gatsby

Reactime offers full support for Gatsby applications. You would be able to identify unnecessary renders, duration of each rendering, travel-debugging features and visual representation of the tree components.

### 🔹 Next.js

Reactime offers debugging and performance tools for Next.js apps: time-traveling debugging, preventing unnecessary components re-renders and making your application faster.

### 🔹 TypeScript Support

Reactime offers beta support for TypeScript applications using stateful class components and functional components. Further testing and development is required for custom hooks, Context API, and Concurrent Mode.
Expand All @@ -133,11 +147,6 @@ Reactime offers beta support for TypeScript applications using stateful class co
After cloning this repository, developers can simply run `npm run docs` at the root level and serve the dynamically generated `/docs/index.html` file on a browser. Doing so will provide a readable, extensible, and interactive GUI view of the structure and interfaces of the codebase.
<br>

<p align="center">
<img src="./assets/nextjs.gif" />
</p>
<br>

### <b>Additional Features</b>

- Identifying unnecessary re-renders
Expand Down Expand Up @@ -222,6 +231,11 @@ After cloning this repository, developers can simply run `npm run docs` at the r
- **Kristina Wallen** - [@kristinawallen](https://github.com/kristinawallen)
- **Quan Le** - [@blachfog](https://github.com/Blachfog)
- **Robert Maeda** - [@robmaeda](https://github.com/robmaeda)
- **David Kim** - [@codejunkie7](https://github.com/codejunkie7)
- **Robby Tipton** - [@RobbyTipton](https://github.com/RobbyTipton)
- **Kevin HoEun. Lee** - [@khobread](https://github.com/khobread)
- **Christopher LeBrett** - [@fscgolden](https://github.com/fscgolden)
- **Joseph Park** - [@joeepark](https://github.com/joeepark)

## <b>License </b>

Expand Down
Binary file added assets/action-comparison.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/history-tree.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/map-viewing.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/new-reactime.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions demo-app/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

{
"presets": [
"@babel/preset-env",
"@babel/preset-react"
]
}
1 change: 1 addition & 0 deletions demo-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
36 changes: 36 additions & 0 deletions demo-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "typescript-module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server",
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@babel/core": "^7.16.7",
"@babel/preset-env": "^7.16.7",
"@babel/preset-react": "^7.16.7",
"@types/express": "^4.17.13",
"@types/node": "^17.0.8",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
"babel-loader": "^8.2.3",
"copy-webpack-plugin": "^10.2.0",
"css-loader": "^6.5.1",
"html-webpack-plugin": "^5.5.0",
"nodemon": "^2.0.15",
"ts-loader": "^9.2.6",
"typescript": "^4.5.4",
"webpack": "^5.65.0",
"webpack-cli": "^4.9.1",
"webpack-dev-server": "^4.7.2"
},
"dependencies": {
"express": "^4.17.2",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-router-dom": "^6.3.0",
"ts-node": "^10.4.0"
}
}
157 changes: 157 additions & 0 deletions demo-app/src/client/Components/Board.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import React, { Component } from 'react';
import Row from './Row';
import { BoardText, BoardContent, Scoreboard, Player } from './../../types';

type BoardState = {
board: BoardContent;
currentPlayer: Player;
gameOver: boolean;
message: string;
scoreboard: Scoreboard;
};

class Board extends Component<{}, BoardState> {
constructor(props: any) {
super(props);
this.state = {
board: this.newBoard(),
currentPlayer: 'X',
gameOver: false,
message: '',
scoreboard: { X: 0, O: 0 },
};

this.resetBoard = this.resetBoard.bind(this);
this.handleBoxClick = this.handleBoxClick.bind(this);
}

componentDidUpdate() {
this.checkForWinner();
}

/**
* @method newBoard
* @description - returns a blank BoardContent array,
* for the start of a new game
*/
newBoard(): BoardContent {
return [
['-', '-', '-'],
['-', '-', '-'],
['-', '-', '-'],
];
}

/**
* @method resetBoard
* @description - sets to board object to be all '-',
* and sets gameOver and message to default state
*/
resetBoard(): void {
this.setState({
gameOver: false,
board: this.newBoard(),
message: '',
});
}

/**
* @method checkForWinner
* @description - checks to see if either player has filled a row
* if so, ends the game and updates the message to declare winner
*/
checkForWinner(): void {
const { board, gameOver, currentPlayer } = this.state;

const spacesLeft = (): boolean => {
for (let i of board) {
if (i.includes('-')) return true;
}
return false;
};

if (!gameOver) {
// win conditions: matching rows, columns, or diagonals, that are not empty('-')
if (
(board[0][0] === board[0][1] &&
board[0][1] === board[0][2] &&
board[0][2] !== '-') ||
(board[1][0] === board[1][1] &&
board[1][1] === board[1][2] &&
board[1][2] !== '-') ||
(board[2][0] === board[2][1] &&
board[2][1] === board[2][2] &&
board[2][2] !== '-') ||
(board[0][0] === board[1][0] &&
board[1][0] === board[2][0] &&
board[2][0] !== '-') ||
(board[0][1] === board[1][1] &&
board[1][1] === board[2][1] &&
board[2][1] !== '-') ||
(board[0][2] === board[1][2] &&
board[1][2] === board[2][2] &&
board[2][2] !== '-') ||
(board[0][0] === board[1][1] &&
board[1][1] === board[2][2] &&
board[2][2] !== '-') ||
(board[2][0] === board[1][1] &&
board[1][1] === board[0][2] &&
board[0][2] !== '-')
) {
// winner is the person who's turn was previous
const winner: Player = currentPlayer === 'X' ? 'O' : 'X';

this.setState({
gameOver: true,
message: `Player ${winner} wins!`,
});

// draw condition: no '-' remaining in board without above win condition triggering
} else if (!spacesLeft()) {
this.setState({
gameOver: true,
message: 'Draw!',
});
}
}
}

handleBoxClick(row: number, column: number): void {
const boardCopy: BoardContent = [
[...this.state.board[0]],
[...this.state.board[1]],
[...this.state.board[2]],
];
boardCopy[row][column] = this.state.currentPlayer;
const newPlayer: Player = this.state.currentPlayer === 'X' ? 'O' : 'X';
this.setState({ board: boardCopy, currentPlayer: newPlayer });
}

render() {
const rows: Array<JSX.Element> = [];
for (let i = 0; i < 3; i++) {
rows.push(
<Row
key={i}
row={i}
handleBoxClick={this.handleBoxClick}
values={this.state.board[i]}
/>
);
}
const { X, O }: Scoreboard = this.state.scoreboard;

return (
<div className="board">
<h1>Tic Tac Toe</h1>
{this.state.gameOver && <h4>{this.state.message}</h4>}
{rows}
<button id="reset" onClick={this.resetBoard}>
Reset
</button>
</div>
);
}
}

export default Board;
22 changes: 22 additions & 0 deletions demo-app/src/client/Components/Box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { BoardText } from '../../types';

type BoxProps = {
value: BoardText;
row: number;
column: number;
handleBoxClick: (row: number, column: number) => void;
};

const Box = (props: BoxProps) => {
return (
<button
className="box"
onClick={(e) => props.handleBoxClick(props.row, props.column)}
>
{props.value}
</button>
);
};

export default Box;
19 changes: 19 additions & 0 deletions demo-app/src/client/Components/Buttons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from "react";
import Increment from "./Increment";

function Buttons() {
const buttons = [];
for (let i = 0; i < 4; i++){
buttons.push(<Increment />)
}

return(
<div className="buttons">
<h1>Stateful Buttons</h1>
<h4>These buttons are functional components that each manage their own state with the useState hook.</h4>
{buttons}
</div>
)
}

export default Buttons;
Loading

0 comments on commit bd63b09

Please sign in to comment.