javascript - Redu-Saga 的 put 方法没有启动对应的 Reducer
问题描述
这是我的传奇(索引和特定传奇):传奇索引:
import { all } from 'redux-saga/effects';
import search from './search';
export default function* rootSaga() {
yield all([search]);
}
具体传奇:
import { put, call, takeLatest } from 'redux-saga/effects';
import {
SEARCH_MOVIE_START,
SEARCH_MOVIE_COMPLETE,
SEARCH_MOVIE_ERROR,
} from '../../consts/actionTypes';
import { apiCall } from '../api';
export function* searchMovie({ playload }) {
try {
console.log('Accion inical');
const results = yield call(
apiCall,
`&s=${playload.movieName}`,
null,
null,
'GET'
);
yield put({ type: SEARCH_MOVIE_COMPLETE, results });
} catch (error) {
yield put({ type: SEARCH_MOVIE_ERROR, error });
}
}
export default function* search() {
yield takeLatest(SEARCH_MOVIE_START, searchMovie);
}
正如你所看到的,在这个传奇中是一个 console.log() 和一个 put() 方法,但是 console.log() 和 put() 都不起作用,我的意思是在浏览器控制台中没有出现任何消息器。我也使用 Redux DevTools 并且在操作部分只出现 SERACH_MOVIE_START,但没有出现 SEARCH_MOVIE_COMPLETE 或 SEARCH_MOVIE_ERROR(如果我在我的 api 中调用失败)
我的减速器(索引和特定减速器): 我的索引:
import { combineReducers } from 'redux';
import search from './search';
const rootReducer = combineReducers({
search,
});
export default rootReducer;
我的专用减速机
import {
SEARCH_MOVIE_COMPLETE,
SEARCH_MOVIE_ERROR,
SEARCH_MOVIE_START,
} from '../../consts/actionTypes';
const initialState = {};
export default function (state = initialState, action) {
switch (action.type) {
case SEARCH_MOVIE_START:
return { ...state };
case SEARCH_MOVIE_ERROR:
console.log(action);
return { ...state };
case SEARCH_MOVIE_COMPLETE:
console.log(action);
return { si: 'no lo creo', ...state };
default:
return { ...state };
}
}
并存储:
import { createStore, applyMiddleware } from 'redux';
import createSagaMiddleware from 'redux-saga';
import { composeWithDevTools } from 'redux-devtools-extension';
import rootReducer from '../reducers';
import rootSaga from '../sagas';
const configureStore = () => {
const sagaMiddleware = createSagaMiddleware();
return {
...createStore(
rootReducer,
composeWithDevTools(applyMiddleware(sagaMiddleware))
),
runSaga: sagaMiddleware.run(rootSaga),
};
};
export default configureStore;
解决方案
推荐阅读
- java - IllegalStateException:无法初始化插件:接口 org.mockito.plugins.MockMaker
- angular - PrimeNG 菜单栏启动指令未在单元测试中显示
- r - 如何在 ggplot2 中填写自定义极坐标形状?
- python - 如何在 python 中与 twilio 入站消息(来自用户)进行交互?
- android - osmdroid - 标记的自定义视图
- java - MultipleBagFetchException - 如果我们只有一个集合怎么办
- python - 为什么剪枝中的参数会在 tensorflow 的 tfmot 中增加
- .net - 如何在 Visual Studio 2019 上解锁 NLog.config
- c++ - C++17 新功能:错误 C4996:'getenv':此函数或变量可能不安全。考虑改用 _dupenv_s
- javascript - 除非先进入根域,否则 React Router 无法呈现确切的路径