2

redux-saga 中 channel 的原理是怎样的?

 2 years ago
source link: https://www.v2ex.com/t/822092
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  程序员

redux-saga 中 channel 的原理是怎样的?

  FaiChou · FaiChou · 5 分钟前 · 3 次点击

摊牌了, 源码没看懂. 有个地方想请教, 例子:

function* watchAndDo() {
  const channel = yield actionChannel('TEST');
  while (true) {
    const payload = yield take(channel);
    yield call(Api, payload);
  }
}

这个例子中, 假如一起来了 10 个 TEST, 则会一个一个执行. 那么这里 channel 是如何做到等待循环里的 block 结束再派发下一个动作的?

目前了解到: 创建 channel 后, dispatch 的消息会加入到 buffer 中, buffer 是一个数组.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK