# `compose(...functions)`
從右到左來組合多個函數。
這是函數式編程中的方法,為了方便,被放到了 Redux 里。
當需要把多個 [store 增強器](../Glossary.md#store-enhancer) 依次執行的時候,需要用到它。
#### 參數
1. (_arguments_): 需要合成的多個函數。預計每個函數都接收一個參數。它的返回值將作為一個參數提供給它左邊的函數,以此類推。例外是最右邊的參數可以接受多個參數,因為它將為由此產生的函數提供簽名。(譯者注:`compose(funcA, funcB, funcC)` 形象為 `compose(funcA(funcB(funcC())))`)
#### 返回值
(_Function_): 從右到左把接收到的函數合成后的最終函數。
#### 示例
下面示例演示了如何使用 `compose` 增強 [store](Store.md),這個 store 與 [`applyMiddleware`](applyMiddleware.md) 和 [redux-devtools](https://github.com/gaearon/redux-devtools) 一起使用。
```js
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import DevTools from './containers/DevTools'
import reducer from '../reducers'
const store = createStore(
reducer,
compose(
applyMiddleware(thunk),
DevTools.instrument()
)
)
```
#### 小貼士
- `compose` 做的只是讓你在寫深度嵌套的函數時,避免了代碼的向右偏移(譯者注:可以參考[上述的譯者注](#參數))。不要覺得它很復雜。
- 自述
- 介紹
- 動機
- 核心概念
- 三大原則
- 先前技術
- 學習資源
- 生態系統
- 示例
- 基礎
- Action
- Reducer
- Store
- 數據流
- 搭配 React
- 示例:Todo List
- 高級
- 異步 Action
- 異步數據流
- Middleware
- 搭配 React Router
- 示例:Reddit API
- 下一步
- 技巧
- 配置 Store
- 遷移到 Redux
- 使用對象展開運算符
- 減少樣板代碼
- 服務端渲染
- 編寫測試
- 計算衍生數據
- 實現撤銷重做
- 子應用隔離
- 組織 Reducer
- Reducer 基礎概念
- Reducer 基礎結構
- Reducer 邏輯拆分
- Reducer 重構示例
- combineReducers 用法
- combineReducers 進階
- State 范式化
- 管理范式化數據
- Reducer 邏輯復用
- 不可變更新模式
- 初始化 State
- 結合 Immutable.JS 使用 Redux
- 常見問題
- 綜合
- Reducer
- 組織 State
- 創建 Store
- Action
- 不可變數據
- 代碼結構
- 性能
- 設計哲學
- React Redux
- 其它
- 排錯
- 詞匯表
- API 文檔
- createStore
- Store
- combineReducers
- applyMiddleware
- bindActionCreators
- compose
- react-redux 文檔
- API
- 排錯