redux-saga如何对生成的(数组)生成器进行递归?

时间:2017-05-02 19:30:29

标签: javascript generator redux-saga

我看过使用redux-saga的根传奇看起来像:

export default function* root() {
  yield [
    watch_sagaOne(),
    watch_sagaTwo(),
  ];
}

每个观察者都是如此。

const watch_sagaOne = function* () {
   yield takeEvery('action_key', saga_handler)
}

请注意,与文档相反,此处不使用all效果。

代码正在运行,好像已执行takeEvery()调用一样,每次发出操作键时都会调用saga_handlers。

总之我不明白怎么做。我的理解很简单,用于执行根传奇的sagaMiddleware.run(root)函数只是迭代,直到root()生成器完成。这将导致以下顺序:

sagaMiddleware.run(root)
// root is called to generate the rootGenerator generator
// rootGenerator.next() is called by redux-saga
// both watch_sagaOne and watchSagaTwo are executed to produce generators
// This yields an array of [ watch_sagaOneGenerator, watch_sagaTwoGenerator ]
// rootGenerator.next() is called by redux-saga, and finishes

然而,似乎redux-saga也会逐步进入生成的数组并执行两个生成器......这是真的吗?

0 个答案:

没有答案