LoginSignup
76
53

More than 5 years have passed since last update.

Redux入門 4日目 Reduxの基本・Stores(公式ドキュメント和訳)

Last updated at Posted at 2015-11-23

前回 Redux入門 3日目 Reduxの基本・Reducers

前回に引き続き、今回はStoresについてです。

2.3 Stores

Storesの役割は、

  • stateを保持する
  • stateへアクセスするためのgetState()を提供する
  • stateを更新するためのdispatch(action)を提供する
  • リスナーを登録するためのsubscribe(listener)を提供する

Reduxではstoreは必ず一つにしてください。
dataごとにロジックを分割したい場合は、storeを分割せずにreducer compositionを使用してください。

storeをつくるには、combineReducerでつくられたreducerをcreateStore()へ渡します。

import { createStore } from 'redux'
import todoApp from './reducers'
let store = createStore(todoApp)

stateの初期値を渡したい場合にはcreateStoreの第2引数に入れます。

let store = createStore(todoApp, window.STATE_FROM_SERVER)

ここまで来ると、UIはまだ作成されていませんがReducerとactionCreatorのテストを作ることが出来ます。

続き Redux入門 5日目 Reduxの基本・Data Flow

76
53
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
76
53