reactjs - React Redux Saga - 使用 multi-saga
问题描述
我正在尝试实现乘法传奇,但由于某种原因它对我停止工作,我不知道为什么。
这是我的完整代码:
// 存储/sagas/sagas/auth.js
import { delay } from 'redux-saga';
import { put, call } from 'redux-saga/effects';
// When the client enter input on email / password textboxes on auth form.
export function* sagaFunction1(action) {
yield call(actions.SomeAction1, { 'testSeting' );
}
// 存储/sagas/watchers/auth.js
import { takeEvery, all } from 'redux-saga/effects';
import * as actionTypes from '../../actions/actionTypes';
import * as sagas from '../sagas/auth';
export function* watchAuthSaga() {
yield all([
takeEvery(actionTypes.SAGA_FUNCTION1, sagas.sagaFunction1)
}
// 存储/sagas/rootSaga.js
import { all, fork } from 'redux-saga/effects';
import * as watchers from './rootWatchers';
const sagasList = [
...watchers
];
export default function* rootSaga() {
yield all(sagasList.map(saga => fork(saga)));
}
// 存储/sagas/rootWatchers.js
import { watchAuthSaga } from './watchers/auth';
export default [watchAuthSaga];
// index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import './index.less';
import { BrowserRouter } from 'react-router-dom';
import { createStore, applyMiddleware, combineReducers, compose } from 'redux';
import { Provider } from 'react-redux';
import createSagaMiddleware from 'redux-saga';
import * as reducers from './store/reducers/reducers';
import rootSaga from './store/sagas/rootSaga';
import { getEnhancers } from './utils/coreUtils';
import App from './containers/App/App';
import registerServiceWorker from './registerServiceWorker';
// For redux development tools
const composeEnhancers = getEnhancers(compose);
const rootReducer = combineReducers({
auth: reducers.authReducer
});
const sagaMiddleware = createSagaMiddleware();
const store = createStore(rootReducer, composeEnhancers(applyMiddleware(sagaMiddleware)));
sagaMiddleware.run(rootSaga);
const app = (
<Provider store={store}>
<BrowserRouter>
<App />
</BrowserRouter>
</Provider>
);
ReactDOM.render(app, document.getElementById('root'));
registerServiceWorker();
我究竟做错了什么?
解决方案
// 存储/sagas/rootSaga.js
从 './rootWatchers' 导入 * 作为观察者;
const sagasList = [ ...watchers ];
应该是import watchers from './rootWatchers'
,因为你正在使用export default
推荐阅读
- c++ - 在我的 c++ builder 应用程序中包含 xmmintrin.h 的问题
- cakephp - cakephp4 中的 SweetAlert2 实现
- css - 无法识别用于在 rvest 中抓取的 html 节点
- typescript - Firebase 云交易并不总是完成
- python-3.x - 从 ox.projection.project_gdf(city,yerevan.crs) 获取 b'在初始化列表中没有参数'
- python - 如何使 python 包可从终端使用
- c# - Razor Pages Asp.Net-Core 安装 FullCalendar
- r - 在 LeafLet R 中自定义光栅标签
- python - “@”运算符和 np.matmul() 之间的区别
- electron - 电子生成器:资源繁忙或锁定。创建安装程序失败