• API 文档
    • 顶级暴露的方法
    • Store API
    • 引入
      • ES6
      • ES5 (CommonJS)
      • ES5 (UMD build)

    API 文档

    Redux 的 API 非常少。Redux 定义了一系列的约定(contract)来让你来实现(例如 reducers),同时提供少量辅助函数来把这些约定整合到一起。

    这一章会介绍所有的 Redux API。记住,Redux 只关心如何管理 state。在实际的项目中,你还需要使用 UI 绑定库如 react-redux。

    顶级暴露的方法

    • createStore(reducer, [preloadedState], [enhancer])
    • combineReducers(reducers)
    • applyMiddleware(…middlewares)
    • bindActionCreators(actionCreators, dispatch)
    • compose(…functions)

    Store API

    • Store
      • getState()
      • dispatch(action)
      • subscribe(listener)
      • getReducer()
      • replaceReducer(nextReducer)

    引入

    上面介绍的所有函数都是顶级暴露的方法。都可以这样引入:

    ES6

    1. import { createStore } from 'redux';

    ES5 (CommonJS)

    1. var createStore = require('redux').createStore;

    ES5 (UMD build)

    1. var createStore = Redux.createStore;