首页 > 解决方案 > 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();

我究竟做错了什么?

标签: reactjsreduxreact-reduxredux-saga

解决方案


// 存储/sagas/rootSaga.js

从 './rootWatchers' 导入 * 作为观察者;

const sagasList = [ ...watchers ];

应该是import watchers from './rootWatchers',因为你正在使用export default


推荐阅读