const createMiddleware = (extraArgument) => ({dispatch, getState}) => (next) =>(action) => {//some code};
const createMiddleware = (extraArgument) => {
return ({dispatch, getState}) => {
return (next) => {
return (action) => {//some code};
}
}
}
{dispatch, getState} 是解構賦值 (Destructuring)
上層呼叫方 applyMiddleware.js 傳參數 middlewareAPI。
return middleware(middlewareAPI);
middlewareAPI 當中有兩個物件 dispatch, getState,
下層被呼叫用 {dispatch, getState} 可以取得。
ref .1 https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
沒有留言:
張貼留言