【问题标题】:Saga Event channels not emitting a callbackSaga 事件通道未发出回调
【发布时间】:2019-02-21 06:11:52
【问题描述】:

正在学习 Saga 事件通道以侦听自定义事件,但无法解决问题。

问题: startlistner() 函数在调用时不会从根函数调用

const channel = yield call(startlistner);

完整代码

import { eventChannel } from "redux-saga";
import { take, fork, call } from "@redux-saga/core/effects";

export default function handleclick() {
root().next();
}

function* root() {
const channel = yield call(startlistner);
while (true) {
const { data } = yield take(channel);
console.log("while");
 }
}

function startlistner() {
console.log("da");
const channel = eventChannel(emmiter => {
emmiter({ data: null });
return () => {};
});
}

感谢您提供的任何帮助。

【问题讨论】:

    标签: reactjs typescript react-redux redux-saga


    【解决方案1】:

    Saga 事件通道不发出回调

    在您的startlistner() 中,您没有返回事件频道。

    function startlistner() {
      const channel = eventChannel(emmiter => {
        emmiter({ data: null }); // for emitting action
        return () => {};         // for unsubscribe
      });
    
      return channel;            // return event channel to caller.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-18
      • 2018-03-17
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多