onmessage
redux-saga をリスナーと連携させようとしています。私が持っているものが機能しない理由がわかりません。
私は次の設定をしています。
// 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
誰が私が間違っているのか教えてもらえますか?