有没有一种方法可以使用多个 redux-sagas 而无需在 rootSaga 中创建一个巨大的数组?

Is there a way to use multiple redux-sagas without making a huge array in the rootSaga?

目前,我的应用程序中有 20 多条路由。这些路由中的每一个都会有多个 API 调用,所以我打算使用 redux-saga 进行 AJAX 调用。

通过阅读文档,我似乎可以执行以下操作:

  1. 每条路线都有自己的 "root" saga,本身会产生多个 sagas。
  2. 此路由特定的 saga 将被导出到实际的主根 saga,后者又将传递给 createSagaMiddleware.run()

所以它看起来像这样:

export function* screen1Saga() {
    yield [ ... ]; // different sub-sagas for screen1 route
}

然后在主 saga 文件中,执行此操作:

import { screen1Saga } from './screen1/sagas';

export function* rootSaga() {
    yield [ screen1Saga(), ... ]; // array of route-specific sagas
}  

我相信这应该工作得很好。但我担心创建 20 多个特定于路线的 sagas 时它会是什么样子。在 root saga 中,它只是一个巨大的 saga 数组。

是否可以通过其他方式做到这一点?最好以这样一种方式将路由特定的 sagas 封装在其相应的文件夹中,而无需将其一直导出到应用程序结构的顶部?

只是想看看其他人是如何处理大量 sagas 的。

React-Boilerplate repo is a pretty good example of some ways to scale a React app. They use a utility file called asyncInjectors,它实际上只是通过在后台调用 sagaMiddleware.run(saga) 来委托添加 sagas 的工作。