本文整理匯總了TypeScript中redux-saga.call函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript call函數的具體用法?TypeScript call怎麽用?TypeScript call使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了call函數的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: bgSync
function* bgSync() {
try {
while(true) {
yield put({type: 'REQUEST_START'})
const result = yield call(someApi)
yield put({type: 'REQUEST_SUCCESS', result})
yield call(delay, 5000)
}
} catch(error) {
if(error instanceof SagaCancellationException)
yield put({type: 'REQUEST_FAILURE', message: 'Sync cancelled!'})
}
}
示例2: fetchPostsWithTimeout
const fetchPostsWithTimeout:Saga = function* fetchPostsWithTimeout() {
while( yield take('FETCH_POSTS') ) {
// starts a race between 2 effects
const {posts, timeout} = yield race({
posts : call(fetchApi, '/posts'),
timeout : call(delay, 1000)
})
if(posts)
put( {type: 'RECEIVE_POSTS', posts} )
else
put( {type: 'TIMEOUT_ERROR'} )
}
}
示例3: fetchProducts
function* fetchProducts() {
yield put( {type: 'REQUEST_PRODUCTS'} )
const products = yield call(fetchApi, '/products')
yield put( {type: 'RECEIVE_PRODUCTS', products } )
}
示例4: fetchPosts
function* fetchPosts() {
yield put( {type: 'REQUEST_POSTS'} )
const posts = yield call(fetchApi, '/posts')
yield put( {type: 'RECEIVE_POSTS', posts} )
}
示例5: watchFetch
function* watchFetch() {
while ( yield take('FETCH_PRODUCTS') ) {
yield call(fetchProducts) // waits for the fetchProducts task to
// terminate
}
}