-
Notifications
You must be signed in to change notification settings - Fork 0
Training0 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Training0 #1
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| nodejs 16.13.0 | ||
| 16.13.0 | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,5 +39,8 @@ | |
| "last 1 firefox version", | ||
| "last 1 safari version" | ||
| ] | ||
| }, | ||
| "devDependencies": { | ||
| "prettier": "2.5.0" | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Y4suyuki There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 空ファイルを置くことが重要です! あと設定についてはそもそもPrettierは(ESlintも個人的には)頑張って設定するものではないです |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,38 @@ | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
| import './index.css'; | ||
| import reportWebVitals from './reportWebVitals'; | ||
| import React from "react"; | ||
| import ReactDOM from "react-dom"; | ||
| import "./index.css"; | ||
| import reportWebVitals from "./reportWebVitals"; | ||
|
|
||
| class Square extends React.Component { | ||
| render() { | ||
| return ( | ||
| <button className="square"> | ||
| {/* TODO */} | ||
| </button> | ||
| ); | ||
| } | ||
| type SquareValue = string | null; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. より厳密な型定義にできないでしょうか? https://www.typescriptlang.org/docs/handbook/2/everyday-types.html
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Y4suyuki |
||
| type SquareProps = { | ||
| value: SquareValue; | ||
| onClick: () => void; | ||
| }; | ||
| function Square(props: SquareProps) { | ||
| return ( | ||
| <button className="square" onClick={props.onClick}> | ||
| {props.value} | ||
| </button> | ||
| ); | ||
| } | ||
|
|
||
| class Board extends React.Component { | ||
| renderSquare(_: number) { | ||
| return <Square />; | ||
| type BoardProps = { | ||
| squares: SquareValue[]; | ||
| onClick: (i: number) => void; | ||
| }; | ||
| class Board extends React.Component<BoardProps> { | ||
| renderSquare(i: number) { | ||
| return ( | ||
| <Square | ||
| value={this.props.squares[i]} | ||
| onClick={() => this.props.onClick(i)} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| render() { | ||
| const status = 'Next player: X'; | ||
|
|
||
| return ( | ||
| <div> | ||
| <div className="status">{status}</div> | ||
| <div className="board-row"> | ||
| {this.renderSquare(0)} | ||
| {this.renderSquare(1)} | ||
|
|
@@ -43,30 +52,110 @@ class Board extends React.Component { | |
| ); | ||
| } | ||
| } | ||
|
|
||
| class Game extends React.Component { | ||
| type GameHistory = { | ||
| squares: SquareValue[]; | ||
| }; | ||
| type GameProps = {}; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ookura-mf ookura-mf 1 hour ago Owner あっているとは何を指していますか?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
一般的な書き方(デファクト)なのかわからない、という意図でした!
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
なるほど、それで言うと一般的な書き方(デファクト)をそこまで意識する必要はないと思います |
||
| type GameState = { | ||
| history: GameHistory[]; | ||
| stepNumber: number; | ||
| xIsNext: boolean; | ||
| }; | ||
| class Game extends React.Component<GameProps, GameState> { | ||
| constructor(props: GameProps) { | ||
| super(props); | ||
| this.state = { | ||
| history: [ | ||
| { | ||
| squares: Array(9).fill(null), | ||
| }, | ||
| ], | ||
| stepNumber: 0, | ||
| xIsNext: true, | ||
| }; | ||
| } | ||
| handleClick(i: number) { | ||
| const history = this.state.history.slice(0, this.state.stepNumber + 1); | ||
| const current = history[this.state.stepNumber]; | ||
| const squares = current.squares.slice(); | ||
| if (calculateWinner(squares) || squares[i]) { | ||
| return; | ||
| } | ||
| squares[i] = this.state.xIsNext ? "X" : "O"; | ||
| this.setState({ | ||
| history: history.concat([ | ||
| { | ||
| squares: squares, | ||
| }, | ||
| ]), | ||
| stepNumber: history.length, | ||
| xIsNext: !this.state.xIsNext, | ||
| }); | ||
| } | ||
| jumpTo(step: number) { | ||
| this.setState({ | ||
| stepNumber: step, | ||
| xIsNext: step % 2 === 0, | ||
| }); | ||
| } | ||
| render() { | ||
| const history = this.state.history; | ||
| const current = history[this.state.stepNumber]; | ||
| const winner = calculateWinner(current.squares); | ||
| let status; | ||
| if (winner) { | ||
| status = "Winner: " + winner; | ||
| } else { | ||
| status = "Next player: " + (this.state.xIsNext ? "X" : "O"); | ||
| } | ||
| const moves = history.map((_, move) => { | ||
| const desc = move ? "Go to move #" + move : "Go to game start"; | ||
| return ( | ||
| <li key={move}> | ||
| <button onClick={() => this.jumpTo(move)}>{desc}</button> | ||
| </li> | ||
| ); | ||
| }); | ||
| return ( | ||
| <div className="game"> | ||
| <div className="game-board"> | ||
| <Board /> | ||
| <Board | ||
| squares={current.squares} | ||
| onClick={(i) => this.handleClick(i)} | ||
| /> | ||
| </div> | ||
| <div className="game-info"> | ||
| <div>{/* status */}</div> | ||
| <ol>{/* TODO */}</ol> | ||
| <div>{status}</div> | ||
| <ol>{moves}</ol> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| // ======================================== | ||
| function calculateWinner(squares: Array<SquareValue>) { | ||
| const lines = [ | ||
| [0, 1, 2], | ||
| [3, 4, 5], | ||
| [6, 7, 8], | ||
| [0, 3, 6], | ||
| [1, 4, 7], | ||
| [2, 5, 8], | ||
| [0, 4, 8], | ||
| [2, 4, 6], | ||
| ]; | ||
| for (let i = 0; i < lines.length; i++) { | ||
| const [a, b, c] = lines[i]; | ||
| if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) { | ||
| return squares[a]; | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| ReactDOM.render( | ||
| <Game />, | ||
| document.getElementById('root') | ||
| ); | ||
| // ======================================== | ||
|
|
||
| ReactDOM.render(<Game />, document.getElementById("root")); | ||
|
|
||
| // If you want to start measuring performance in your app, pass a function | ||
| // to log results (for example: reportWebVitals(console.log)) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
前PRから引き継ぎ
ookura-mf 1 hour ago
nodejsが入ってるとnodejsなんて知らん!ってerror出たので修正したが、実はそのままでいけるのかわかっていない(nodenvのrepositoryでgrepした感じもヒットしなかった)
Owner
@Y4suyuki Y4suyuki 26 minutes ago
もしかしたら僕の用意したのが間違っていたかもです 😅
nodeenv 使ったことなくて、今も使っていません
nodeのバージョン管理だとnvmの方が主流な気がします(スターの数とかブログとかで取り上げられる頻度)
僕はasdfを使って .nvmrc を読むようにしてます
https://github.com/ekalinin/nodeenv
https://github.com/nvm-sh/nvm
https://github.com/asdf-vm/asdf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nvmの方が主流なんですね 👀
anyenvな気持ちですぐ使っちゃった 🙈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Y4suyuki
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
まあnodeenvもnode.jsの公式サイトに紹介されているしバージョンマネージャでもDockerでもnodeのバージョンさえあっていれば良いのでそこは個人の好みでも良いと思います(余程マイナーなものでなければ)