那么这些胖箭在下面的代码中做了什么?我能理解他们是不是两个人!
export default function clientMiddleware(client) {
return ({dispatch, getState}) => {
// ******** starts here **********
return next => action => {
// ******** ends here **********
if (typeof action === 'function') {
return action(dispatch, getState);
}
const { promise, types, ...rest } = action; // eslint-disable-line no-redeclare
if (!promise) {
return next(action);
}
const [REQUEST, SUCCESS, FAILURE] = types;
next({...rest, type: REQUEST});
const actionPromise = promise(client);
actionPromise.then(
(result) => next({...rest, result, type: SUCCESS}),
(error) => next({...rest, error, type: FAILURE})
).catch((error)=> {
console.error('MIDDLEWARE ERROR:', error);
next({...rest, error, type: FAILURE});
});
return actionPromise;
};
};
}
这段代码的等价物是什么?
value => value2 => {
// some code
}
答案 0 :(得分:3)
这基本上是一个返回箭头功能的箭头功能。你可以写得更清楚:
(value) => {
return (value2) => {
// some code
};
}