简体   繁体   中英

React Redux Saga - Working with multi-saga

I'm trying to implement multiply saga, but for some reason it's stopped working to me, and i don't know why.

Here is my full code:

// store/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' );
}

// store/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)
}

// store/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)));
}

// store/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();

What am i doing wrong?

// store/sagas/rootSaga.js

import * as watchers from './rootWatchers';

const sagasList = [ ...watchers ];

Should be import watchers from './rootWatchers' , because you are using export default

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM