Skip to content

Commit 187b55a

Browse files
authored
Merge pull request #311 from oslabs-beta/master
Reactime 19 release!
2 parents 6bf4b71 + 42f72a4 commit 187b55a

File tree

227 files changed

+2768
-18448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+2768
-18448
lines changed

.babelrc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
{
2-
"presets": [
3-
"airbnb"
4-
],
2+
"presets": ["airbnb", "@babel/preset-typescript"],
53
"plugins": ["@emotion"]
6-
}
4+
}

.eslintrc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
"airbnb",
44
"plugin:jest/recommended",
55
"plugin:@typescript-eslint/eslint-recommended",
6-
"plugin:@typescript-eslint/recommended"
6+
"plugin:@typescript-eslint/recommended",
7+
"plugin:testing-library/react", // added in for RTL tests
8+
"plugin:jest-dom/recommended" // added in for RTL tests
79
],
810
"root": true,
9-
"plugins": ["jest", "react", "react-hooks", "@typescript-eslint"],
11+
"plugins": ["jest", "react", "react-hooks", "@typescript-eslint", "testing-library", "jest-dom"],
1012
"rules": {
1113
"arrow-parens": [2, "as-needed"],
1214
"import/no-unresolved": "off",

README.md

Lines changed: 103 additions & 175 deletions
Large diffs are not rendered by default.

assets/frontend-diagram.png

12 KB
Loading

assets/v19/Overview.gif

2.45 MB
Loading

assets/v19/history.gif

719 KB
Loading

assets/v19/map.gif

1010 KB
Loading

assets/v19/performance.gif

1.29 MB
Loading

assets/v19/tree-and-diff.gif

830 KB
Loading

demo-app-next/src/components/Board.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from "react";
22
import Row from "./Row";
3-
import { BoardText, BoardContent, Scoreboard, Player } from "../types/types";
3+
import { BoardContent, Scoreboard, Player } from "../types/types";
44

55
type BoardState = {
66
board: BoardContent;
@@ -11,7 +11,7 @@ type BoardState = {
1111
};
1212

1313
class Board extends Component<{}, BoardState> {
14-
constructor(props: any) {
14+
constructor(props: unknown) {
1515
super(props);
1616
this.state = {
1717
board: this.newBoard(),
@@ -25,7 +25,7 @@ class Board extends Component<{}, BoardState> {
2525
this.handleBoxClick = this.handleBoxClick.bind(this);
2626
}
2727

28-
componentDidUpdate() {
28+
componentDidUpdate():void {
2929
this.checkForWinner();
3030
}
3131

@@ -127,7 +127,7 @@ class Board extends Component<{}, BoardState> {
127127
this.setState({ board: boardCopy, currentPlayer: newPlayer });
128128
}
129129

130-
render() {
130+
render(): JSX.Element {
131131
const rows: Array<JSX.Element> = [];
132132
for (let i = 0; i < 3; i++) {
133133
rows.push(
@@ -139,7 +139,7 @@ class Board extends Component<{}, BoardState> {
139139
/>
140140
);
141141
}
142-
const { X, O }: Scoreboard = this.state.scoreboard;
142+
// const { X, O }: Scoreboard = this.state.scoreboard;
143143

144144
return (
145145
<div className="board">

demo-app-next/src/components/Box.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ type BoxProps = {
77
handleBoxClick: (row: number, column: number) => void;
88
};
99

10-
const Box = (props: BoxProps) => {
10+
const Box = (props: BoxProps): JSX.Element => {
1111
return (
1212
<button
1313
className="box"

demo-app-next/src/components/Buttons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Increment from './Increment';
22

3-
export default function Buttons() {
3+
export default function Buttons(): JSX.Element {
44
const buttons = [];
55
for (let i = 0; i < 4; i++) {
66
buttons.push(<Increment key={i} />);

demo-app-next/src/components/Increment.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from "react";
22

3-
export default function Increment() {
3+
export default function Increment(): JSX.Element {
44
const [count, setCount] = useState(0);
55

66
return (

demo-app-next/src/components/navbar.js renamed to demo-app-next/src/components/navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Link from 'next/link';
22

3-
export default function Navbar() {
3+
export default function Navbar(): JSX.Element {
44
return (
55
<div className='nav'>
66
<Link className='link' href='/'>

demo-app-next/src/pages/_app.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

demo-app-next/src/pages/_app.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import "../../styles/style.css";
2+
import React from "react"
3+
4+
export default function MyApp({ Component, pageProps }): JSX.Element {
5+
return <Component {...pageProps} />;
6+
}

demo-app-next/src/pages/buttons/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Buttons from "../../components/Buttons";
22
import Navbar from "../../components/navbar";
33

4-
export default function ButtonsPage() {
4+
export default function ButtonsPage(): JSX.Element {
55
return (
66
<div>
77
<Navbar />

demo-app-next/src/pages/index.js renamed to demo-app-next/src/pages/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Navbar from "../components/navbar";
2+
import React from "react"
23

3-
export default function Home() {
4+
export default function Home():JSX.Element {
45
return (
56
<div>
67
<Navbar />

demo-app-next/src/pages/tictactoe/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Board from '../../components/Board';
22
import Navbar from '../../components/navbar';
33

4-
export default function BoardPage() {
4+
export default function BoardPage():JSX.Element {
55
return (
66
<div>
77
<Navbar />

demo-app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"react": "^18.1.0",
3232
"react-dom": "^18.1.0",
3333
"react-router-dom": "^6.3.0",
34-
"ts-node": "^10.4.0"
34+
"ts-node": "^10.4.0",
35+
"use-immer": "^0.9.0"
3536
}
3637
}

demo-app/src/client/Components/Board.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import React, { Component } from 'react';
22
import Row from './Row';
3-
import { BoardText, BoardContent, Scoreboard, Player } from './../../types';
3+
import { BoardContent, Scoreboard, Player } from './../../types';
4+
//Took away BoardText from import
45

6+
//thinking about changing this to an interface
57
type BoardState = {
68
board: BoardContent;
79
currentPlayer: Player;
@@ -10,8 +12,9 @@ type BoardState = {
1012
scoreboard: Scoreboard;
1113
};
1214

15+
//changed props to unknown instead of any
1316
class Board extends Component<{}, BoardState> {
14-
constructor(props: any) {
17+
constructor(props: unknown) {
1518
super(props);
1619
this.state = {
1720
board: this.newBoard(),
@@ -25,7 +28,8 @@ class Board extends Component<{}, BoardState> {
2528
this.handleBoxClick = this.handleBoxClick.bind(this);
2629
}
2730

28-
componentDidUpdate() {
31+
//added void
32+
componentDidUpdate(): void {
2933
this.checkForWinner();
3034
}
3135

@@ -111,14 +115,15 @@ class Board extends Component<{}, BoardState> {
111115
this.setState({ board: boardCopy, currentPlayer: newPlayer });
112116
}
113117

114-
render() {
118+
//added type for render
119+
render(): JSX.Element {
115120
const rows: Array<JSX.Element> = [];
116121
for (let i = 0; i < 3; i++) {
117122
rows.push(
118123
<Row key={i} row={i} handleBoxClick={this.handleBoxClick} values={this.state.board[i]} />,
119124
);
120125
}
121-
const { X, O }: Scoreboard = this.state.scoreboard;
126+
// const { X, O }: Scoreboard = this.state.scoreboard;
122127

123128
return (
124129
<div className='board'>

demo-app/src/client/Components/Box.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React from 'react'
22
import { BoardText } from '../../types';
33

44
type BoxProps = {
@@ -8,11 +8,13 @@ type BoxProps = {
88
handleBoxClick: (row: number, column: number) => void;
99
};
1010

11-
const Box = (props: BoxProps) => {
11+
const Box = (props: BoxProps) : JSX.Element => {
1212
return (
13+
<>
1314
<button className='box' onClick={(e) => props.handleBoxClick(props.row, props.column)}>
1415
{props.value}
1516
</button>
17+
</>
1618
);
1719
};
1820

demo-app/src/client/Components/Buttons.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import Increment from './Increment';
33

4-
function Buttons() {
4+
function Buttons(): JSX.Element {
55
const buttons = [];
66
for (let i = 0; i < 4; i++) {
77
buttons.push(<Increment key={i} />);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import React, {useState, createContext} from 'react';
2+
import IncrementWithMoreHooks from './IncrementWithMoreHooks';
3+
4+
/**
5+
* This component as well as IncrementWithMoreHooks were made to show where data for different
6+
* hooks show up in the react fiber tree.
7+
*/
8+
9+
/**
10+
* This file is a JSX file, not a TSX file, on purpose. The code won't be converted to common JS
11+
* before being bundled by webpack. There were some errors that weren't showing up for the other
12+
* Increment.tsx file based on how webpack uglifies ES6 files. Maintaining this as a JSX file
13+
* will help check for these types of issues.
14+
*/
15+
16+
/**
17+
* How Reactime extracts useState data and what would have to be done
18+
* to extract useContext and useReducer data:
19+
*
20+
* When extracting a functional component's useState data from the fiber tree in the backend of
21+
* Reactime, said data is stored on said component's fiber tree node at its memoizedState property,
22+
* which is a linked list with each node holding data for each useState invocation (some but
23+
* not all other hooks also store nodes with data here). Each useState memoizedState node includes
24+
* the variable (e.g. user) and its corresponding dispatch function (e.g. setUser). This dispatch
25+
* function is required to use Reactime's timeJump feature.
26+
*
27+
* useContext data is stored on the property "dependencies", and only the data passed into the
28+
* value attritibute of the 'context'.Provider element will be there. For tripContext.Provider,
29+
* we pass down "trip" without "setTrip", so we won't have access to the 'trip' dispatch function
30+
* in the "IncrementWithMoreHooks" component, meaning Reactime's timeJump won't work without
31+
* finding the 'trip' dispatch function by coming into this component where useState was invoked and
32+
* storing it in the appropriate place. This is easy enough for useState variables, but useContext
33+
* is commonly used with useReducer which is an entirely different beast.
34+
*
35+
* I advise solving the puzzle of making useReducer work with the timeJump functionality before
36+
* integrating other hooks. Look at time jumping in the Redux dev tools chrome extension for
37+
* inspiration, because you essentially need to recreate that within Reactime.
38+
*/
39+
40+
// userInCreateContext is different from 'user' to see where this variable name showed up in the AST
41+
export const userContext = createContext({ userInCreateContext: 'null', setUser: undefined });
42+
export const tripContext = createContext({ trip: 'null', setTrip: undefined });
43+
44+
const ButtonsWithMoreHooks = () => {
45+
const [user, setUser] = useState('null');
46+
const userValue = { user, setUser };
47+
const [trip, setTrip ] = useState('Hawaii');
48+
const tripValue = { trip };
49+
50+
return (
51+
<div className='buttons' key='increment container'>
52+
<userContext.Provider value={userValue} key="userContext Provider">
53+
<tripContext.Provider value={tripValue} key="tripContext Provider">
54+
<IncrementWithMoreHooks key={'IncrementWithMoreHooks'} />
55+
</tripContext.Provider>
56+
</userContext.Provider>
57+
</div>
58+
);
59+
}
60+
61+
export default ButtonsWithMoreHooks;

demo-app/src/client/Components/Home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
function Home() {
3+
function Home(): JSX.Element {
44
return (
55
<div className='about'>
66
<h1>Lorem Ipsum</h1>

demo-app/src/client/Components/Increment.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState } from 'react';
2-
function Increment() {
2+
function Increment(): JSX.Element {
33
const [count, setCount] = useState(0);
44
return (
55
<div>

0 commit comments

Comments
 (0)