LoginSignup
0
1

More than 3 years have passed since last update.

【公式私家訳】Reduxの基本概念:Actions(アクション), Reducers(リデューサ), Store(ストア)とは何か?

Last updated at Posted at 2020-04-17

はじめに

 目下、reduxを使ったフロントエンド開発に従事している。そのさなか、teratailでの回答に対するコメントで、アクション、リデューサ、ストアとは? にお答えする機会があった。こういう基礎知識を自分が点検する機会を作るためにteratailに回答しているようなものなのでまとめておく。
 アクション、リデューサ、ストアとは何か?
 こといった基本知識、特に基幹となるフレームワークのコアとなる諸概念の定義を問われたときにやってはいけないことは、自分の語彙や想像の範囲にある言葉で勝手な説明を作ってしまうことだと考えている。そうやって「俺のリダックス」なるものを作ってしまうのはいただけない。ということで、公式から引用、翻訳する。

Actions (アクション)

https://redux.js.org/basics/actions より引用。

Actions are payloads of information that send data from your application to your store.
・・・
Actions are plain JavaScript objects. Actions must have a type property that indicates the type of action being performed.

以下は、上記を私家訳して箇条書きにしたもの。


【私家訳】
- アクションは情報のペイロードで、アプリケーションからstoreにデータを送るものである。
- アクションは、Javascriptのプレーンオブジェクトである。
- アクションは、そのアクションが行うことを示唆するtypeプロパティを持っていなければならない。


Reducers (リデューサ)

https://redux.js.org/basics/reducers より引用。

Reducers specify how the application's state changes in response to actions sent to the store. Remember that actions only describe what happened, but don't describe how the application's state changes.

以下は、上記の私家訳


【私家訳】
リデューサーは、ストアに送られるアクションに対応して、アプリケーションの状態がどのように変わるかを明示する。アクションには、何が起こったかだけが記述されており、アプリーションの状態変更については何も記述されていないことを銘記されたい。


Store (ストア)

https://redux.js.org/basics/store より引用。

In the previous sections, we defined the actions that represent the facts about “what happened” and the reducers that update the state according to those actions.

The Store is the object that brings them together. The store has the following responsibilities:

・Holds application state;
・Allows access to state via getState();
・Allows state to be updated via dispatch(action);
・Registers listeners via subscribe(listener);
・Handles unregistering of listeners via the function returned by subscribe(listener).

以下は、上記の私家訳


【私家訳】

前節(上記に引用したアクションとリデューサーの説明)において、アクションを「何が起こったか」を表すものとし、リデューサを、アクションによって状態を更新するものとして定義した。ストア(The Store)は、それら(アクションとリデューサー)を引き合わせる。ストア(The Store)は、以下の責務を持つ。

・アプリケーションの状態を保持する。
・アプリケーションの状態に対しては、getState() で参照する。
・状態の更新は、dispatch(action) によって行う。
・リスナーの登録は、subscribe(listener) によって行う。
・リスナーの解除は、subscribe(listener) の返す関数によって行う。


補足: Reducers (リデューサ) とは何か?を補強する私見

※以下は私見(In My Opinion)なので、考え方として採用するかは、読者の皆様におまかせします。


【IMO】
個人的には、リデューサとは、決定性有限オートマトンでいえば、状態遷移関数に相当するものと理解している。つまり、オートマトンの状態集合Q、文字集合Σとするときの、状態遷移関数 δ : Q × Σ → Q が、リデューサに相当する、というのが個人的なイメージ。


もし、「リデューサーを、オートマトンの状態遷移関数になぞらえるのはよろしくない」というご意見の識者の方がいらっしゃいましたら、ぜひ、その理由を伺って勉強させて頂きたいので、コメント頂ければ幸いです。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1