几个api
- call和apply 执行异步请求操作 类似call的调用方法
yield call(Api.fetch, arg1, arg2...)
yield apply(this, Api.fetch, args)
- put 执行action
yield put(action) //功能dispatch
- take 订阅指定的action
yield take(action)
action的类型
1. *
2. 字符串 匹配具体action
3. 数组
4. 函数
3.1 takeEvery 订阅一个action 绑定对应的回调函数
import { takeEvery } from `redux-saga`
function* fetchUser(action) {
...
}
function* watchFetchUser() {
yield* takeEvery('USER_REQUESTED', fetchUser)
}
- select 功能从store中取值, 是getState的包装
const count = select(state=>state.count)
//or
const count = getState().count
网友评论