ノード 6.2.1 で次のコードを実行しようとしました。1、2 をログに記録し、スタックします。yield take('TEST') の行まで実行を継続しない理由がわかりません... anotherSaga が終了して 2 をログに記録するようですが、制御が rootSaga に返されません。誰でも私を助けてもらえますか?
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 のないコードは期待どおりに機能します
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);