在 saga 中访问 store.dispatch 以与 React router redux 一起使用

Access to store.dispatch in a saga for use with react router redux

我目前正在重构一个 react + redux + saga + react-router 3 应用程序,以使用新的 react-router 4 由于重大更改。在我使用 browserHistory 根据 saga 的结果定向到适当的路径之前。由于 react-router 4 的变化,我不能再使用 browserHistory。

现在我已经合并了 react-router-redux 来基本上完成 browserHistory 所做的事情。问题是 react-router-redux 只能在 store.dispatch 内工作,例如store.dispatch(推('/'))。我似乎无法找到一种方法来访问我的传奇中的商店或它的调度功能。关于如何在 saga 中访问 store.dispatch 有什么想法吗?我知道您可以在 root saga 中传递参数,但我不知道如何在我的实际 saga 中检索它们。

使用 redux-saga 的 put 效果,它将 redux 操作分派到商店 - docs.

import { call, put } from 'redux-saga/effects'
// ...

function* fetchProducts() {
  const products = yield call(Api.fetch, '/products')
  // create and yield a dispatch Effect
  yield put({ type: 'PRODUCTS_RECEIVED', products })
}