Skip to content
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

Translate "Separating Events from Effects" #609

Merged
merged 12 commits into from
Aug 21, 2023

Conversation

kotaesaki
Copy link
Contributor

@kotaesaki kotaesaki commented Jun 14, 2023

"Separating Events from Effects"の翻訳です!

  • Choosing between event handlers and Effects
  • Reactive values and reactive logic
  • Extracting non-reactive logic out of Effects
  • Recap
  • challenges

@kotaesaki
Copy link
Contributor Author

お待たせして申し訳ございません。レビューよろしくお願いします!

@smikitky smikitky requested review from koba04 and smikitky June 20, 2023 17:57
@github-actions
Copy link

github-actions bot commented Jun 29, 2023

Size changes

📦 Next.js Bundle Analysis for react-dev

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Three Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load
/404 77.41 KB (🟡 +5 B) 180.58 KB
/500 77.41 KB (🟡 +5 B) 180.57 KB
/[[...markdownPath]] 78.97 KB (🟡 +5 B) 182.13 KB
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

Next to the size is how much the size has increased or decreased compared with the base branch of this PR. If this percentage has increased by 10% or more, there will be a red status indicator applied, indicating that special attention should be given to this.

@koba04
Copy link
Member

koba04 commented Jul 4, 2023

@smikitky こちらのレビューもお願いできると助かります 🙏

@smikitky
Copy link
Member

smikitky commented Jul 5, 2023

ちょっと勘違いしてこちらが後回しになっており申し訳ありません。
レビューはほぼ完了しているのですが見直しているところです。お待ち下さい。

Copy link
Member

@smikitky smikitky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

大変遅くなり申し訳ありません。数が多いですがよろしくお願いします。

ちなみに interaction は、厳しく統一はしていませんが、他の記事では「インタラクション」よりもどちらかというと「ユーザ操作」「操作」を好む、という感じで訳しています。

src/content/learn/separating-events-from-effects.md Outdated Show resolved Hide resolved
src/content/learn/separating-events-from-effects.md Outdated Show resolved Hide resolved
src/content/learn/separating-events-from-effects.md Outdated Show resolved Hide resolved
src/content/learn/separating-events-from-effects.md Outdated Show resolved Hide resolved
src/content/learn/separating-events-from-effects.md Outdated Show resolved Hide resolved

Fix it so that when you switch from "general" to "travel" and then to "music" very quickly, you see two notifications, the first one being "Welcome to travel" and the second one being "Welcome to music". (For an additional challenge, assuming you've *already* made the notifications show the correct rooms, change the code so that only the latter notification is displayed.)
"general" から "travel"、そして "music" に素早く切り替えると、2 つの通知が表示され、1 つ目は "Welcome to travel"、2 つ目は "Welcome to music" と表示されるように修正してください。(追加の課題として、*すでに*通知が正しい部屋を表示するようになっていると仮定して、後者の通知のみが表示されるようにコードを変更してみてください。)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"general" から "travel"、そして "music" に素早く切り替えると、2 つの通知が表示され、1 つ目は "Welcome to travel"、2 つ目は "Welcome to music" と表示されるように修正してください。(追加の課題として、*すでに*通知が正しい部屋を表示するようになっていると仮定して、後者の通知のみが表示されるようにコードを変更してみてください。)
"general" から "travel"、そして "music" に素早く切り替えると、2 つの通知が表示され、1 つ目は "Welcome to travel"、2 つ目は "Welcome to music" と表示されるように修正してください。追加の課題として、*すでに*通知が正しい部屋を表示するようになっていると仮定して、後者の通知のみが表示されるようにコードを変更してみてください。


Your Effect Event is called with a two second delay. If you're quickly switching from the travel to the music room, by the time the travel room's notification shows, `roomId` is already `"music"`. This is why both notifications say "Welcome to music".
エフェクトイベントは、2 秒間の遅延を伴って呼び出されます。travel room から music room に素早く切り替える場合、travel room の通知が表示される頃には、`roomId` は既に `"music"` になっています。そのため、両方の通知で "Welcome to music" と表示されます。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
エフェクトイベントは、2 秒間の遅延を伴って呼び出されます。travel room から music room に素早く切り替える場合、travel room の通知が表示される頃には`roomId` は既に `"music"` になっています。そのため、両方の通知で "Welcome to music" と表示されます。
今回のエフェクトイベントは、2 秒間の遅延を伴って呼び出されます。travel ルームから music ルームに素早く切り替える場合、travel ルームの通知が表示される頃には`roomId` は既に `"music"` になっています。そのため、両方の通知で "Welcome to music" と表示されます。


To fix the issue, instead of reading the *latest* `roomId` inside the Effect Event, make it a parameter of your Effect Event, like `connectedRoomId` below. Then pass `roomId` from your Effect by calling `onConnected(roomId)`:
この問題を解決するには、エフェクトイベントの中で*最新の* `roomId` を読み込むのではなく、以下の `connectedRoomId` のように、エフェクトイベントのパラメータとして `roomId` を指定します。そして、`onConnected(roomId)` を呼び出すことで、エフェクトから `roomId` を渡します:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
この問題を解決するには、エフェクトイベントの中で*最新の* `roomId` を読み込むのではなく、以下の `connectedRoomId` のように、エフェクトイベントのパラメータとして `roomId` を指定します。そして、`onConnected(roomId)` を呼び出すことで、エフェクトから `roomId` を渡します:
この問題を解決するには、エフェクトイベントの中で*最新の* `roomId` を読み込むのではなく、以下の `connectedRoomId` のように、エフェクトイベントのパラメータとして指定するようにします。そして、`onConnected(roomId)` のように呼び出すことで、エフェクトから `roomId` を渡します:

@@ -1694,9 +1692,9 @@ label { display: block; margin-top: 10px; }

</Sandpack>

The Effect that had `roomId` set to `"travel"` (so it connected to the `"travel"` room) will show the notification for `"travel"`. The Effect that had `roomId` set to `"music"` (so it connected to the `"music"` room) will show the notification for `"music"`. In other words, `connectedRoomId` comes from your Effect (which is reactive), while `theme` always uses the latest value.
`roomId` `"travel"` に設定されていたエフェクト(`"travel"` ルームに接続していた)には、`"travel"` の通知が表示されます。`roomId` `"music"` に設定された(つまり `"music"` ルームに接続した)エフェクトは、`"music"` に対する通知を表示します。つまり、`connectedRoomId` はエフェクト(リアクティブなもの)に由来し、`theme` は常に最新の値を使用します。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`roomId``"travel"` に設定されていたエフェクト(`"travel"` ルームに接続していた)には`"travel"` の通知が表示されます`roomId``"music"` に設定された(つまり `"music"` ルームに接続した)エフェクトは、`"music"` に対する通知を表示します。つまり、`connectedRoomId` はエフェクト(リアクティブなもの)に由来し、`theme` は常に最新の値を使用します
`roomId``"travel"` に設定された(つまり `"travel"` ルームに接続したときの)エフェクトは`"travel"` の通知を表示します`roomId``"music"` に設定された(つまり `"music"` ルームに接続したときの)エフェクトは、`"music"` に対する通知を表示します。つまり、`connectedRoomId` はエフェクト(リアクティブなもの)に由来し、一方で `theme` は常に最新の値を使用するのです


To solve the additional challenge, save the notification timeout ID and clear it in the cleanup function of your Effect:
この追加の課題を解決するには、通知のタイムアウト ID を保存し、エフェクトのクリーンアップ関数でクリアしてください:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
この追加の課題を解決するには、通知のタイムアウト ID を保存し、エフェクトのクリーンアップ関数でクリアしてください:
追加の課題を解決するには、通知のタイムアウト ID を保存し、エフェクトのクリーンアップ関数でクリアしてください:

@koba04
Copy link
Member

koba04 commented Aug 15, 2023

@kotaesaki
翻訳ありがとうございます!こちらのレビュー結果の反映は可能そうでしょうか?

@kotaesaki
Copy link
Contributor Author

@koba04
こちらまだ手がつけられていない状況になっています。遅れていて大変申し訳ございません。

今週日曜までに修正させていただきます。よろしくお願いいたします。

@koba04
Copy link
Member

koba04 commented Aug 15, 2023

@kotaesaki いえいえ、お時間ある時で大丈夫ですのでよろしくお願いします!🙇‍♂️

Co-authored-by: Soichiro Miki <smiki-tky@umin.ac.jp>
Co-authored-by: Soichiro Miki <smiki-tky@umin.ac.jp>
@kotaesaki
Copy link
Contributor Author

@smikitky @koba04
大変遅れました🙇指摘箇所修正致しましたので再度レビューよろしくお願いいたします!

Copy link
Member

@smikitky smikitky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございました!

サイドバーの翻訳・空行追加・翻訳微修正をさせていただきました。

Copy link
Member

@koba04 koba04 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 ありがとうございます!!!

@koba04 koba04 merged commit 5140504 into reactjs:main Aug 21, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants