我正在构建我的异步中间件,我想从中分派几个操作。下面是目前的情况:
const [ requestType, successType, failureType ] = types;
next({type: requestType});
return call().then(
result => {
return next({
result,
type: successType
})
},
error => {
// I want to dispath the `sendNotification()` action here
// to add item to notifications center
// should I use `next` or `store.dispath`?
//this way?
store.dispath(failedNotification);
//or this way?
next(failedNotification);
return next({
type: failureType,
error: error.message || 'Something bad happened',
errorType: error.errorType
})
}
)
我的问题在上面代码中的这些注释中:
// I want to dispath the `sendNotification()` action here
// to add item to notifications center
// should I use `next` or `store.dispath`?
我之所以这么问是因为根据我的理解
applyMiddleware
实施详细信息来自
here
,
next()
将通过剩余的中间产品链传递动作
store.dispatch
将通过整个中间产品链,包括当前的中间产品。