如何订阅 redux-saga 到 action?
How to subscribe redux-saga to action?
我对 redux-sage 有疑问。无法设法订阅操作。
我为商店
设置了这个
import { createStore, applyMiddleware, compose } from "redux"
import createSagaMiddleware from "redux-saga"
import rootSaga from "../config/rootSaga"
import rootReducer from "../config/rootReducer"
const effects = []
let composeEnhancers = compose
if (process.env.NODE_ENV === "development") {
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ // eslint-disable-line no-underscore-dangle
}
const sagaMiddleware = createSagaMiddleware()
effects.push(sagaMiddleware)
const store = createStore(rootReducer, {}, composeEnhancers(applyMiddleware(...effects)))
sagaMiddleware.run(rootSaga)
export default store
saga 中间件似乎不起作用。
我从我的 rootSaga 中看到 console.log 但是当 redux 动作发生时,saga 不起作用
export default function* searchRootSaga() {
console.log("searchRootSaga") // I see this on start
yield all([fork(throttle, 100, SEARCH.GET.REQUEST, getSearchThis)])
}
export function* getSearchThis(action) {
console.log("getSearchThis") // I dont see this
try {
// const response = yield call(API.getSearch, query)
const response = dummy_data
yield put(getSearchSuccess(response))
} catch (e) {
yield put(getSearchFailure("Server Err"))
}
}
React 开发工具显示 SEARCH.GET.REQUEST 操作,但 saga 不工作。
我做错了什么?
我觉得throttle本身就是一个非阻塞效果。所以你不需要分叉它。尝试:
yield throttle(100, SEARCH.GET.REQUEST, getSearchThis)
我对 redux-sage 有疑问。无法设法订阅操作。 我为商店
设置了这个import { createStore, applyMiddleware, compose } from "redux"
import createSagaMiddleware from "redux-saga"
import rootSaga from "../config/rootSaga"
import rootReducer from "../config/rootReducer"
const effects = []
let composeEnhancers = compose
if (process.env.NODE_ENV === "development") {
composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ // eslint-disable-line no-underscore-dangle
}
const sagaMiddleware = createSagaMiddleware()
effects.push(sagaMiddleware)
const store = createStore(rootReducer, {}, composeEnhancers(applyMiddleware(...effects)))
sagaMiddleware.run(rootSaga)
export default store
saga 中间件似乎不起作用。 我从我的 rootSaga 中看到 console.log 但是当 redux 动作发生时,saga 不起作用
export default function* searchRootSaga() {
console.log("searchRootSaga") // I see this on start
yield all([fork(throttle, 100, SEARCH.GET.REQUEST, getSearchThis)])
}
export function* getSearchThis(action) {
console.log("getSearchThis") // I dont see this
try {
// const response = yield call(API.getSearch, query)
const response = dummy_data
yield put(getSearchSuccess(response))
} catch (e) {
yield put(getSearchFailure("Server Err"))
}
}
React 开发工具显示 SEARCH.GET.REQUEST 操作,但 saga 不工作。 我做错了什么?
我觉得throttle本身就是一个非阻塞效果。所以你不需要分叉它。尝试:
yield throttle(100, SEARCH.GET.REQUEST, getSearchThis)