Javascript Redux action没有';我不想和这件事扯上关系

Javascript Redux action没有';我不想和这件事扯上关系,javascript,reactjs,react-native,redux-saga,Javascript,Reactjs,React Native,Redux Saga,在我的React应用程序中,我使用saga中间件这是我的根传奇。 import { all } from 'redux-saga/effects'; import alertSaga from 'redux/alert/alert.saga'; export default function* rootSaga() { console.log('ROOT SAGA') yield all([ alertSaga(), ]); } import { applyMiddle

在我的React应用程序中,我使用saga中间件这是我的根传奇。

import { all } from 'redux-saga/effects';

import alertSaga from 'redux/alert/alert.saga';

export default function* rootSaga() {
  console.log('ROOT SAGA')
  yield all([
    alertSaga(),
  ]);
}
import { applyMiddleware, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import { persistStore } from 'redux-persist';
import createSagaMiddleware from 'redux-saga';

import rootReducer from './root-reducer';
import rootSaga from './root-saga';

const INITIAL_STATE = {};

const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware];

const store = createStore(
  rootReducer,
  INITIAL_STATE,
  composeWithDevTools(applyMiddleware(...middleware)),
);

sagaMiddleware.run(rootSaga);

const persistor = persistStore(store);

export { store, persistor };
import { put, takeEvery } from 'redux-saga/effects';

import { IAction } from 'constants/types.constant';
import { removeAlert, setAlert } from 'redux/alert/alert.actions';
import { SET_ALERT } from 'redux/alert/alert.types';

export function* displayAlert({ type, payload }: IAction) {
  console.log(type);
  console.log(payload);
  // yield put(setAlert({ type, payload }));

  try {
    yield put({ type: SET_ALERT, payload });
  } catch (error) {

  }

  // setTimeout(() => yield put(removeAlert(payload.id), 3000));
}

function* alertSaga() {
  console.log('HELLO');
  yield takeEvery(SET_ALERT, displayAlert);
}

export default alertSaga;
import { REMOVE_ALERT, SET_ALERT } from './alert.types';

export const setAlert = (payload: Object) => ({ type: SET_ALERT, payload });

export const removeAlert = (payload: number) => ({ type: REMOVE_ALERT, payload });
这就是商店。

import { all } from 'redux-saga/effects';

import alertSaga from 'redux/alert/alert.saga';

export default function* rootSaga() {
  console.log('ROOT SAGA')
  yield all([
    alertSaga(),
  ]);
}
import { applyMiddleware, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import { persistStore } from 'redux-persist';
import createSagaMiddleware from 'redux-saga';

import rootReducer from './root-reducer';
import rootSaga from './root-saga';

const INITIAL_STATE = {};

const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware];

const store = createStore(
  rootReducer,
  INITIAL_STATE,
  composeWithDevTools(applyMiddleware(...middleware)),
);

sagaMiddleware.run(rootSaga);

const persistor = persistStore(store);

export { store, persistor };
import { put, takeEvery } from 'redux-saga/effects';

import { IAction } from 'constants/types.constant';
import { removeAlert, setAlert } from 'redux/alert/alert.actions';
import { SET_ALERT } from 'redux/alert/alert.types';

export function* displayAlert({ type, payload }: IAction) {
  console.log(type);
  console.log(payload);
  // yield put(setAlert({ type, payload }));

  try {
    yield put({ type: SET_ALERT, payload });
  } catch (error) {

  }

  // setTimeout(() => yield put(removeAlert(payload.id), 3000));
}

function* alertSaga() {
  console.log('HELLO');
  yield takeEvery(SET_ALERT, displayAlert);
}

export default alertSaga;
import { REMOVE_ALERT, SET_ALERT } from './alert.types';

export const setAlert = (payload: Object) => ({ type: SET_ALERT, payload });

export const removeAlert = (payload: number) => ({ type: REMOVE_ALERT, payload });
这是我的故事。

import { all } from 'redux-saga/effects';

import alertSaga from 'redux/alert/alert.saga';

export default function* rootSaga() {
  console.log('ROOT SAGA')
  yield all([
    alertSaga(),
  ]);
}
import { applyMiddleware, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import { persistStore } from 'redux-persist';
import createSagaMiddleware from 'redux-saga';

import rootReducer from './root-reducer';
import rootSaga from './root-saga';

const INITIAL_STATE = {};

const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware];

const store = createStore(
  rootReducer,
  INITIAL_STATE,
  composeWithDevTools(applyMiddleware(...middleware)),
);

sagaMiddleware.run(rootSaga);

const persistor = persistStore(store);

export { store, persistor };
import { put, takeEvery } from 'redux-saga/effects';

import { IAction } from 'constants/types.constant';
import { removeAlert, setAlert } from 'redux/alert/alert.actions';
import { SET_ALERT } from 'redux/alert/alert.types';

export function* displayAlert({ type, payload }: IAction) {
  console.log(type);
  console.log(payload);
  // yield put(setAlert({ type, payload }));

  try {
    yield put({ type: SET_ALERT, payload });
  } catch (error) {

  }

  // setTimeout(() => yield put(removeAlert(payload.id), 3000));
}

function* alertSaga() {
  console.log('HELLO');
  yield takeEvery(SET_ALERT, displayAlert);
}

export default alertSaga;
import { REMOVE_ALERT, SET_ALERT } from './alert.types';

export const setAlert = (payload: Object) => ({ type: SET_ALERT, payload });

export const removeAlert = (payload: number) => ({ type: REMOVE_ALERT, payload });
最后,这是我的警戒行动。

import { all } from 'redux-saga/effects';

import alertSaga from 'redux/alert/alert.saga';

export default function* rootSaga() {
  console.log('ROOT SAGA')
  yield all([
    alertSaga(),
  ]);
}
import { applyMiddleware, createStore } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import { persistStore } from 'redux-persist';
import createSagaMiddleware from 'redux-saga';

import rootReducer from './root-reducer';
import rootSaga from './root-saga';

const INITIAL_STATE = {};

const sagaMiddleware = createSagaMiddleware();
const middleware = [sagaMiddleware];

const store = createStore(
  rootReducer,
  INITIAL_STATE,
  composeWithDevTools(applyMiddleware(...middleware)),
);

sagaMiddleware.run(rootSaga);

const persistor = persistStore(store);

export { store, persistor };
import { put, takeEvery } from 'redux-saga/effects';

import { IAction } from 'constants/types.constant';
import { removeAlert, setAlert } from 'redux/alert/alert.actions';
import { SET_ALERT } from 'redux/alert/alert.types';

export function* displayAlert({ type, payload }: IAction) {
  console.log(type);
  console.log(payload);
  // yield put(setAlert({ type, payload }));

  try {
    yield put({ type: SET_ALERT, payload });
  } catch (error) {

  }

  // setTimeout(() => yield put(removeAlert(payload.id), 3000));
}

function* alertSaga() {
  console.log('HELLO');
  yield takeEvery(SET_ALERT, displayAlert);
}

export default alertSaga;
import { REMOVE_ALERT, SET_ALERT } from './alert.types';

export const setAlert = (payload: Object) => ({ type: SET_ALERT, payload });

export const removeAlert = (payload: number) => ({ type: REMOVE_ALERT, payload });

当setAlert被调度时,它不会影响警报事件。我做错了什么?

如果您只想导出一部传奇,请尝试下面的内容

export default function* alertSaga() {
  console.log('HELLO');
  yield takeEvery(SET_ALERT, displayAlert);
}
或者,如果您要导出多个传奇

export default function* yourSagas() {
  yield all([
    alertSaga(),
    otherSaga(),
  ]);
}