Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/4-advanced/04-react/declarative-ui.drawio.svg
Copy link
Contributor

Choose a reason for hiding this comment

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

おそらくv1の画像が使われていそうです。

Copy link
Contributor

Choose a reason for hiding this comment

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

let stateconst stateの方が適切かと思います。

Copy link
Contributor

Choose a reason for hiding this comment

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

コードのフォーマットがPrettierに準拠していないため、Prettierのフォーマットに準拠したフォーマットとすると良いかと思います。

Copy link
Contributor

Choose a reason for hiding this comment

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

細かいですが、特に理由がなければ、removeよりもaddを使用した方がわかりやすいかと思います。というのも、基本的にremoveよりもaddの方が実装しやすくより単純だからです。

Copy link
Contributor

Choose a reason for hiding this comment

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

Todo List → ToDoリスト

などにした方が良いかと思います。(TodoではなくToDoの方がよく使われる表記であり、さらに日本語にした方がわかりやすい)

Copy link
Contributor

Choose a reason for hiding this comment

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

ToDoリストのUIの図のレイアウトが少し崩れているので、グリッドを使用して揃えるとよいかと思います。

Copy link
Contributor

Choose a reason for hiding this comment

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

全体的に不必要に文字サイズが小さい(あるいは図の横幅が不必要に大きい)ところがあるので、適切な大きさにすると良いかと思います。また、同じ意味論を持つテキストに対して別の文字サイズが使われているため、それぞれのテキストの意味に応じた文字サイズにすると良いかと思います。(タイトルは〇〇px, 地の文は〇〇pxなどのように揃えるイメージです。)

Copy link
Contributor

Choose a reason for hiding this comment

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

状態からUIへ向かう矢印の大きさと位置が左右で異なるので、揃えるとよいかと思います(グリッドを用いて合わせるとよいかと思います)。また、矢印の始点と終点の位置も見やすいように調整するかと良いと思います。

Copy link
Contributor

Choose a reason for hiding this comment

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

removeを表す矢印が左側の箱(すなわち、状態とUIの両方を含んだもの)から右側の箱に向かっており、左側の状態 + UIから右側の状態 + UIに向かう矢印となってしまっています。状態から状態へと向かう矢印という意味を表したいはずなので、食い違ってしまっているように思います。

Copy link
Contributor

Choose a reason for hiding this comment

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

テキストでの説明に合わせて、

render() → render関数

のようにするとよいかと思います。

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions docs/4-advanced/04-react/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ addTodoButton.onclick = () => {

ところが、アプリケーションの本質的な状態というのは、一般的にそこまで多いものではありません。例えば、ToDoリストアプリケーションであれば、各ToDoを表す`string`の配列`string[]`がひとつだけあれば、アプリケーションの状態は全て表現できていることになるはずです。

**宣言的UI**は、こういった性質に着目します。より具体的に説明するのであれば、アプリケーションの状態$S$に対し、関数$f(S)$によりUIの状態を表現できるのであれば、開発者の関心を$S$の変化と$f$の定義のみに絞ることができるというわけです。
**宣言的UI**は、こういった性質に着目します。より一般的に説明するのであれば、アプリケーションの状態$S$に対し、関数$f(S)$によりUIの状態を表現できるのであれば、開発者の関心を$S$の変化と$f$の定義のみに絞ることができるというわけです。

具体的なコードで確認してみましょう。先ほどのToDoアプリケーションを、宣言的UIのアプローチを用いて書き換えてみましょう。状態を追いやすいよう、TypeScriptを用いて記述します。
具体的なコードで確認してみましょう。先ほどのToDoアプリケーションのコードを、宣言的UIのアプローチを用いて書き換えてみましょう。状態を追いやすいよう、TypeScriptを用いて記述します。

まずはアプリケーションの状態と、その状態を格納する変数を宣言します。

Expand Down Expand Up @@ -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が描画されます。

![宣言的UIの概念図](./declarative-ui.drawio.svg)

## React

Expand Down