Reactjs Saga watcher未接收或处理已调度的操作
我有一个守望者传奇,它不断地倾听某种类型的行动。这是从saga.run()启动的。当它收到某种类型的动作时,它应该调用另一个执行异步动作的传奇。然而,第二个传奇中的断点永远不会被调用 因此,要么是源代码没有正确地分派操作,要么是watcher saga配置错误 守望者传奇代码Reactjs Saga watcher未接收或处理已调度的操作,reactjs,typescript,redux,redux-saga,Reactjs,Typescript,Redux,Redux Saga,我有一个守望者传奇,它不断地倾听某种类型的行动。这是从saga.run()启动的。当它收到某种类型的动作时,它应该调用另一个执行异步动作的传奇。然而,第二个传奇中的断点永远不会被调用 因此,要么是源代码没有正确地分派操作,要么是watcher saga配置错误 守望者传奇代码 import { all, fork, takeLatest } from 'redux-saga/effects' import {fetchItems} from './itemsSaga'; function* w
import { all, fork, takeLatest } from 'redux-saga/effects'
import {fetchItems} from './itemsSaga';
function* watchLoadItemsRequest() {
while(true) {
yield takeLatest('FETCH_ITEMS_REQUEST', fetchItems);
}
}
export default function* root() {
yield all ([
fork(watchLoadItemsRequest)
])
}
我的itemsSaga(没有被调用)
我的商店创建代码
import { applyMiddleware, createStore } from 'redux';
import createSagaMiddleware from 'redux-saga';
import reducers from '../reducers';
import watchersSaga from '../sagas/watchersSaga';
export default function getStore() {
const sagaMiddleware = createSagaMiddleware();
const store = createStore(
reducers, applyMiddleware(sagaMiddleware)
);
sagaMiddleware.run(watchersSaga);
return store;
}
最后是应该发送FETCH\u ITEMS\u请求操作的控件
import * as React from 'react';
import { connect, Dispatch } from 'react-redux';
import ItemEntity from './api/itemEntity';
import './App.css';
import IStoreState from './interfaces/IStoreState';
interface IContentProps {
groupingType : string,
items: ItemEntity[],
loadItems : () => void
}
class MyContent extends React.Component<IContentProps,{}> {
constructor(props: any) {
super(props);
}
public componentDidMount() {
this.props.loadItems();
}
public render() {
return (
<div className="Center-content">
<div className="Center-content White">
<br/><br/>Grouped by {this.props.groupingType}<br/><br/>{this.props.items.length} items loaded
</div>
</div>
);
}
}
function mapStateToProps(state: IStoreState) {
return {
groupingType: state.navigation.groupingType,
trades: state.item.items
};
}
const mapDispatchToProps = (dispatch: Dispatch) => {
return {
loadItems: () => dispatch({type:'FETCH_ITEMS_REQUEST'})
}
}
export default connect(mapStateToProps, mapDispatchToProps)(PnlContent);
这似乎不是对收到的FETCH\u ITEMS\u请求消息的响应,也不是为任何有类似问题的人调用fetchItems,最后我将我的watchers Saga改为
function* watchLoadTradesRequest() {
yield takeEvery('FETCH_TRADES_REQUEST', fetchTrades);
}
// Register all your watchers
export default function* watchersRootSaga() {
yield all ([
watchLoadTradesRequest()
])
}
while(true) {
yield takeLatest('FETCH_ITEMS_REQUEST', fetchItems);
}
function* watchLoadTradesRequest() {
yield takeEvery('FETCH_TRADES_REQUEST', fetchTrades);
}
// Register all your watchers
export default function* watchersRootSaga() {
yield all ([
watchLoadTradesRequest()
])
}