我正在尝试让 redux-saga 与onmessage
侦听器一起工作。我不知道为什么我所拥有的不起作用。
我有以下设置。
// sagas.js
import { take, put } from 'redux-saga';
import {transactions} from "./actions";
function* foo (txs) {
console.log("yielding"); // appears in console
yield put(transactions(txs)); // action *is not* dispatched
console.log("yielded"); //appears in console
}
const onMessage = (event) => {
const txs = JSON.parse(event.data);
const iter = foo(txs);
iter.next(); // do I really need to do this?
};
function* getTransactions() {
while(yield take('APP_LOADED')) {
const stream = new EventSource(eventSourceUrl);
stream.onopen = onOpen;
stream.onmessage = onMessage;
stream.onerror = onError;
// this is just testing that `yield put` works
yield put(transactions([{baz : 42}])); //this action *is* dispatched
}
};
当调用APP_LOADED
调度动作时,打开流并调用 onMessage 侦听器,因为从服务器接收到数据,但是在调用生成器getTransactions
时调度动作没有任何运气。yield put(transactions(txs))
foo
谁能告诉我我做错了什么?