ノード6.2.1で次のコードを実行しようとしました。それは1,2,を記録し、次にスタックします。なぜ私はそれが行収量take( 'TEST')に実行を継続しないのか、undestandできません...別の佐賀が終了し、2を記録すると思われるが、制御はrootSagaに返されない。誰も私を助けることができますか?Redux-sagaがyieldコールでスタックされています
const {runSaga, delay} = require('redux-saga');
const {take, put, call} = require('redux-saga/effects');
function* anotherSaga() {
yield call(delay, 1000);
console.log(2);
}
function* rootSaga() {
while(true) {
console.log(1);
yield call(anotherSaga);
console.log(3);
const action = yield take('TEST');
console.log(4);
yield put(action);
}
}
runSaga(
rootSaga(),
{
subscribe(callback) {
return setInterval(() => (callback({type: 'TEST'})), 1000);
},
dispatch(action) {
console.log(action);
},
getState() {}
}
);
更新:しかしrunSagaのないコードが予想ログとして働く1,2,3,4-
const {createStore, applyMiddleware} = require('redux');
const createSagaMiddleware = require('redux-saga').default;
const {delay} = require('redux-saga');
const {take, put, call} = require('redux-saga/effects');
function* anotherSaga() {
yield call(delay, 2000);
console.log(2);
}
function* rootSaga() {
while(true) {
console.log(1);
yield call(anotherSaga);
console.log(3);
const action = yield take('TEST');
console.log(4);
yield put(action);
console.log('---')
}
}
const rootReducer = (state, action) => {
if (state === undefined) {
return {};
}
return state;
}
const sagaMiddleware = createSagaMiddleware();
const store = createStore(rootReducer, {}, applyMiddleware(sagaMiddleware));
sagaMiddleware.run(rootSaga);
setInterval(() => (store.dispatch({type: 'TEST'})), 1000);
runSagaなしでこのコードを試しましたか? – kuy
@kuy私は試しましたが、期待どおりに動作します。メイントピックのコードを見てください。 –