Q_Q 没学完啦
import { createStore, applyMiddleware } from 'redux'
import createSagaMiddleware from 'redux-saga'
import reducer from './reducers'
import mySaga from './sagas'
// create the saga middleware
const sagaMiddleware = createSagaMiddleware()
// mount it on the Store
const store = createStore(
reducer,
applyMiddleware(sagaMiddleware)
)
// then run the saga
sagaMiddleware.run(mySaga)
// render the application
import { call, put, takeEvery, takeLatest } from 'redux-saga/effects'
import Api from '...'
// 工作的 Saga:当 action 是 USER_FETCH_REQUESTED 时被触发
function* fetchUser(action) {
try {
const user = yield call(Api.fetchUser, action.payload.userId);
yield put({type: "USER_FETCH_SUCCEEDED", user: user});
} catch (e) {
yield put({type: "USER_FETCH_FAILED", message: e.message});
}
}
/*
在每次 dispatch `USER_FETCH_REQUESTED` action 时,启动 fetchUser。
允许同时取得使用者。
*/
function* mySaga() {
yield takeEvery("USER_FETCH_REQUESTED", fetchUser);
}
/*
另外你也可以使用 takeLatest。
但不允许同时取得使用者。当一个 fetch 已经在 pending 时,如果取得 dispatch「USER_FETCH_REQUESTED」,
正在等待的 fetch 会被取消,只执行最新的发出的 USER_FETCH_REQUESTED。
*/
function* mySaga() {
yield takeLatest("USER_FETCH_REQUESTED", fetchUser);
}
export default mySaga;
https://neighborhood999.github.io/redux-saga/
<<: [Day25] Scrum失败经验谈 – 与需求单位之间的断层
本篇已同步发表至个人部落格 https://coolmandiary.blogspot.com/20...
前言 今天是我挑战的第一天,这次挑战其实是一个偶然状况下,资深的前辈看到我正好开着铁人挑战赛的报名页...
在安装软件时有安装成功,但启动时失败,有人有遇过这种情形吗? ...
Sub 在投影片内文字选取位置插入等大图片_以字图取代文字() '20210320 Dim sld ...
逻辑运算子 MDN : https://developer.mozilla.org/zh-TW/do...