-
Notifications
You must be signed in to change notification settings - Fork 3
React 宣言的なUIの説明の追加 #932
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?
React 宣言的なUIの説明の追加 #932
Changes from 3 commits
ece5102
b7392bd
823e766
216e8d9
11dc3fd
6a2c8e1
ca7d829
17c0339
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
chvmvd marked this conversation as resolved.
chvmvd marked this conversation as resolved.
chvmvd marked this conversation as resolved.
chvmvd marked this conversation as resolved.
chvmvd marked this conversation as resolved.
chvmvd marked this conversation as resolved.
chvmvd marked this conversation as resolved.
chvmvd marked this conversation as resolved.
chvmvd marked this conversation as resolved.
Contributor
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. 骨格はいいと思います!ただ、上下左右で位置がずれている箇所や、余分な空白があるところ、余白が狭いところなどがあるので、例えば、#954 みたいな感じにするのはどうでしょう? |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,9 +47,9 @@ addTodoButton.onclick = () => { | |
|
|
||
| ところが、アプリケーションの本質的な状態というのは、一般的にそこまで多いものではありません。例えば、ToDoリストアプリケーションであれば、各ToDoを表す`string`の配列`string[]`がひとつだけあれば、アプリケーションの状態は全て表現できていることになるはずです。 | ||
|
|
||
| **宣言的UI**は、こういった性質に着目します。より具体的に説明するのであれば、アプリケーションの状態$S$に対し、関数$f(S)$によりUIの状態を表現できるのであれば、開発者の関心を$S$の変化と$f$の定義のみに絞ることができるというわけです。 | ||
| **宣言的UI**は、こういった性質に着目します。より一般的に説明するのであれば、アプリケーションの状態$S$に対し、関数$f(S)$によりUIの状態を表現できるのであれば、開発者の関心を$S$の変化と$f$の定義のみに絞ることができるというわけです。 | ||
|
Contributor
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. ここはもとのままで合っているような気がします。 「宣言的UIは、こういった性質に着目します。」という説明を、「より具体的に」説明すると、「アプリケーションの状態$S$に対し、...」という説明になるという論理展開になっているかと思います。 |
||
|
|
||
| 具体的なコードで確認してみましょう。先ほどのToDoアプリケーションを、宣言的UIのアプローチを用いて書き換えてみましょう。状態を追いやすいよう、TypeScriptを用いて記述します。 | ||
| 具体的なコードで確認してみましょう。先ほどのToDoアプリケーションのコードを、宣言的UIのアプローチを用いて書き換えてみましょう。状態を追いやすいよう、TypeScriptを用いて記述します。 | ||
|
|
||
| まずはアプリケーションの状態と、その状態を格納する変数を宣言します。 | ||
|
|
||
|
|
@@ -88,7 +88,9 @@ function removeTodo(index: number) { | |
|
|
||
| <ViewSource url={import.meta.url} path="_samples/todo-declarative" /> | ||
|
|
||
| これにより、アプリケーション全体の状態が変数`state`に集約され、開発者が意識すべき状態のパターンを大幅に減らすことに成功しました。 | ||
| これにより、アプリケーション全体の状態が変数`state`に集約され、開発者が意識すべき状態のパターンを大幅に減らすことに成功しました。このコードでは、状態$S$は変数`state`に、関数$f(S)$は`render`関数に対応しています。例えば、`remove("寝る")`によって`state`が変化すると、`render`関数が再び呼ばれ、新しい状態に応じたUIが描画されます。 | ||
|
Contributor
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. ここでは、この文より上にある説明で用いられているコード(addTodo関数やremoveTodo関数が宣言されているコード)と、図の中で用いられているコード(remove関数が用いられているコード)の2種類が存在しているかと思います。 |
||
|
|
||
|  | ||
|
|
||
| ## React | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.