2017-03-17 102 views
0

所以,我檢查了終極版的代碼庫,終極版增強和applyMiddleware

要創建一個店,我們稱之爲由終極版曝光的createStore功能,

createStore(ourReducer,{}, applyMiddleware(someMiddleware)); 


export default function createStore(reducer, preloadedState, enhancer) { 
    if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') { 
    enhancer = preloadedState 
    preloadedState = undefined 
    } 

    if (typeof enhancer !== 'undefined') { 
    if (typeof enhancer !== 'function') { 
     throw new Error('Expected the enhancer to be a function.') 
    } 

    return enhancer(createStore)(reducer, preloadedState) 
    } ... 

在createStore以上功能,增強被稱爲在這一部分,這也是我在第一行通過applyMiddleware功能...

enhancer(createStore)(reducer, preloadedState) 

但是,當我檢查了applyMiddleware功能,有3個參數 (減速機,preloadedState,增強劑)...

export default function applyMiddleware(...middlewares) { 
    return (createStore) => (reducer, preloadedState, enhancer) => { 

...

它基本上總是不確定的吧?我只是好奇爲什麼它在那裏,或者我錯過了什麼。

enhancer(createStore)(reducer, preloadedState) 

回答

1

是的,這個出現(令人驚訝)頻繁。這是使用createStore的「舊式」方式的延續。有關討論和歷史記錄,請參閱Redux issue #2128