redux-thunk 中间件 multiple => Syntex
redux-thunk middleware multiple => Syntex
我试图了解 thunk 在 shell 下的工作原理,但很难理解从 here
引用的这段代码
function createThunkMiddleware(extraArgument) {
return ({ dispatch, getState }) => next => action => {
// This gets called for every action you dispatch.
// If it's a function, call it.
if (typeof action === 'function') {
return action(dispatch, getState, extraArgument);
}
// Otherwise, just continue processing this action as usual
return next(action);
};
}
const thunk = createThunkMiddleware();
thunk.withExtraArgument = createThunkMiddleware;
export default thunk;
它说这基本上是 thunk 的代码。令我困惑的是 multiple => 语法。我知道 => 是箭头函数的一部分。
我目前的理解是 createThunkMiddleware
returns 一个函数,我们称它为 A, returns 另一个函数 B, returns 另一个函数 C。以及 A,B 的签名和 C 如下所示:
function A ({dispatch, getState}) {
return B(next)
}
function B (next) {
return C(action)
}
function C (action) {
....
}
但这对我来说没有意义。因为,A如何将next
传递给B,B也是如此。
redux-thunk只是一个普通的redux中间件。中间件系统中存在某种类型的控制流。请检查here,你就会知道这是怎么回事了。
我试图了解 thunk 在 shell 下的工作原理,但很难理解从 here
引用的这段代码function createThunkMiddleware(extraArgument) {
return ({ dispatch, getState }) => next => action => {
// This gets called for every action you dispatch.
// If it's a function, call it.
if (typeof action === 'function') {
return action(dispatch, getState, extraArgument);
}
// Otherwise, just continue processing this action as usual
return next(action);
};
}
const thunk = createThunkMiddleware();
thunk.withExtraArgument = createThunkMiddleware;
export default thunk;
它说这基本上是 thunk 的代码。令我困惑的是 multiple => 语法。我知道 => 是箭头函数的一部分。
我目前的理解是 createThunkMiddleware
returns 一个函数,我们称它为 A, returns 另一个函数 B, returns 另一个函数 C。以及 A,B 的签名和 C 如下所示:
function A ({dispatch, getState}) {
return B(next)
}
function B (next) {
return C(action)
}
function C (action) {
....
}
但这对我来说没有意义。因为,A如何将next
传递给B,B也是如此。
redux-thunk只是一个普通的redux中间件。中间件系统中存在某种类型的控制流。请检查here,你就会知道这是怎么回事了。