Redux 语法中的链式箭头函数
Chained Arrow Function in Redux Syntax
嗨,我正在研究 Redux,目前我只是对 Redux-Cheat-Sheet Redux Cheat Sheet from Egghead:
中给出的 redux 语法感到困惑
const actionLogger = ({dispatch, getState}) =>
(next) => (action) =>
{ console.log(action); return next(action) }
所以我的问题是:这个 "chained" 箭头函数的行为是怎样的?
你可以写成:
const actionLogger = function({dispatch, getState} /* this is store object */) {
return function(next) {
return function(action) {
console.log(action);
return next(action);
};
};
};
所以基本上链式箭头函数代表嵌套函数。可能有点混乱。
如果要使用箭头函数:
const actionLogger = () => (dispatch, getState) => {
console.log(getState())
......
};
嗨,我正在研究 Redux,目前我只是对 Redux-Cheat-Sheet Redux Cheat Sheet from Egghead:
中给出的 redux 语法感到困惑const actionLogger = ({dispatch, getState}) =>
(next) => (action) =>
{ console.log(action); return next(action) }
所以我的问题是:这个 "chained" 箭头函数的行为是怎样的?
你可以写成:
const actionLogger = function({dispatch, getState} /* this is store object */) {
return function(next) {
return function(action) {
console.log(action);
return next(action);
};
};
};
所以基本上链式箭头函数代表嵌套函数。可能有点混乱。
如果要使用箭头函数:
const actionLogger = () => (dispatch, getState) => {
console.log(getState())
......
};