私はサガからサンクを派遣しようとすべきではないことを知っています。それはリフィックス・サガがやろうとしていることに反するものです。しかし、私はかなり大きなアプリで作業しており、コードの大部分はサンクで作られています。私たちはビット単位で移行しており、サガの中からサンクをディスパッチする必要があります。サンクは他の部分(約束を返すサンク)で使用されているので変更できません。そのため、多くのことが壊れてしまいます。サガからサンクを発送するには?
configureStore:
const store = createStore(
rootReducer,
initialState,
compose(applyMiddleware(thunk, sagaMiddleware))
);
サーガ
// Saga (is called from a takeEvery)
function* watchWarehouseChange(action) {
const companyId = yield select(Auth.id);
// We use cookies here instead of localStorage so that we persist
// it even when the user logs out. (localStorage clears on logout)
yield call(Cookies.set, `warehouse${companyId}`, action.warehouse);
// I want to dispatch a thunk here
yield put.resolve(syncItems);
// put(syncItems) doesn't work either
}
サンク:
export function syncItems() {
console.log('first!');
return dispatch => {
console.log('second!');
return dispatch(fetchFromBackend()).then(
items => itemsDB.emptyAndFill(items)
)
}
}
syncItems()
が実行されるたびに、唯一first!
ログ。 second!
は起こりません。
PS:エラーや警告は表示されません。
ありがとう@markerikson、あなたは絶対に正しいです!思ったよりも簡単だった – Mathius17