Я пытаюсь получить саунд-редукцию, работающую с прослушивателем 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
вызывается getTransactions
, поток открывается и прослушиватель onMessage вызывается, поскольку данные принимаются с сервера, но мне не удастся отправить это действие при вызове yield put(transactions(txs))
в генераторе foo
.
Может ли кто-нибудь сказать мне, что я делаю неправильно?