Sphereとともに

scalaとかplayframeworkとか。技術ブログにしたいなと。環境は Windows7x64, mac です。たまに声優さん情報が混ざります。最近ちょっとClojure触りました。

Redux Reducer 超適当訳

Reducer

Glossary | Redux

A reducer (also called a reducing function) is a function that accepts an accumulation and a value and returns a new accumulation. They are used to reduce a collection of values down to a single value.

reducer とは 関数である。accumulationとvalueを受け取って、新しいaccumulationを返すものである。

valueの集合を一つのvalueにすることを手掛ける。

Reducers are not unique to Redux—they are a fundamental concept in functional programming. Even most non-functional languages, like JavaScript, have a built-in API for reducing. In JavaScript, it's Array.prototype.reduce().

Reducersは関数型プログラミングの基礎概念でありRedux特有のものではない。

In Redux, the accumulated value is the state object, and the values being accumulated are actions. Reducers calculate a new state given the previous state and an action. They must be pure functions—functions that return the exact same output for given inputs. They should also be free of side-effects. This is what enables exciting features like hot reloading and time travel.

Reducers are the most important concept in Redux.

Do not put API calls into reducers.

Reduxにおいて accumulated value は state オブジェクトであり、 accumulate された値はアクションです。 Reducerは以前のstateを受けて新しいstateを返す純粋関数のアクションです。(純粋関数とはインプットが同じであれば必ず同じアウトプットを返す関数のこと) 副作用がなくホットリローディングやタイムトラベルのような特徴がある。 Reducers は Reduxにおいて最も重要な概念である。

APIを呼び出すようなコードをreducersに入れてはならない。

入門 React ―コンポーネントベースのWebフロントエンド開発

入門 React ―コンポーネントベースのWebフロントエンド開発