【问题标题】:How can I know when a redux-saga function has completed in the calling code我如何知道调用代码中的 redux-saga 函数何时完成
【发布时间】:2016-12-14 09:53:55
【问题描述】:

React、redux、redux-saga

我向商店发送一个操作,例如 CREATE_REQUESTED。 Redux-saga 运行,并对服务器进行异步调用。 传奇完成后,即下一个 CREATE_REQUESTED 的块我想从启动第一个 CREATE_REQUESTED 的容器/组件中执行其他代码。

// pseudo code
class Cmp extends React.component {
   onCreateClick(id) {
     const record = {id, name: 'alabala'}
     // I am missing the .then() part
     this.props.dispatch({type: 'CREATE_REQUESTED', record}).then(created => {
        console.log(created)
     }
   }
}

有没有办法做到这一点?如何? 如果没有,我应该如何设计这个任务?

【问题讨论】:

    标签: redux redux-saga


    【解决方案1】:

    一种方法可能是将(解决、拒绝)选项与操作一起传递,并让 saga 在成功/失败时调用它们。似乎还可以。

    https://github.com/yelouafi/redux-saga/issues/161

    【讨论】:

      最近更新 更多