三層アーキテクチャ(Three Layer Architecture)は、アプリケーションを「役割ごと」に3つの層に分割して設計するパターン。
これにより、役割ごとに責任が明確になり、保守性や再利用性が高まる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| canvas.water { | |
| display: block; | |
| width: 100%; | |
| height: 100vh; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #canvas { | |
| display: block; | |
| width: 100%; | |
| height: 100vh; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .list { | |
| display: flex; | |
| gap: 16px; | |
| align-items: center; | |
| } | |
| .item { | |
| width: 120px; | |
| aspect-ratio: 1/1; | |
| background-color: orange; | |
| &.-border { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # JWT(JSON Web Token)とセッション方式の違い | |
| ## ざっくり違い列挙 | |
| ### セッション方式(サーバーが状態を持つ) | |
| 1. ユーザーがログインに成功した際に、サーバー側で事前に用意されているセッションストアに新しいセッションレコードを追加し、そのキーであるセッションID(ランダム文字列)をクライアントに渡す。 | |
| 2. ブラウザは、受け取ったセッションIDをCookieに保存する。 | |
| 3. 以降のリクエストでは、ブラウザがCookieに保持しているセッションIDをサーバーに送信することで、サーバー側でセッションストアから該当するセッションレコードを取得し、ユーザーの認証情報を確認する。 | |
| ### JWT方式(サーバーが状態を持たず、状態はトークン自体に内包) | |
| 1. ログイン成功時にサーバーが「署名付きの自己完結型トークン」を発行する。 | |
| 2. ブラウザは、受け取ったJWTをCookieに保存する(Authorizationヘッダーで送信するパターンもある)。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 改善前のコード | |
| async function getUserName(userId) { | |
| const response = await fetch(`https://api.example.com/users/${userId}`); | |
| const user = await response.json(); | |
| return user.name; | |
| } | |
| /* | |
| 改善が必要な点 | |
| ・エラーハンドリングが不十分 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .container { | |
| display: grid; | |
| grid-template-columns: 1fr 1fr; | |
| width: 480px; | |
| height: 280px; | |
| margin-inline: auto; | |
| border: 1px solid black; | |
| overflow-y: auto; | |
| & > .right { | |
| height: 120px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 問題のあるコード | |
| function Counter() { | |
| const [count, setCount] = useState(0); | |
| const handleClick = () => { | |
| // カウントを更新 | |
| setCount(count + 1); | |
| // すぐに新しい値を使おうとする - 期待通り動かない | |
| console.log('Current count:', count); // まだ古い値が表示される | |