本文整理匯總了TypeScript中redux-saga.take函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript take函數的具體用法?TypeScript take怎麽用?TypeScript take使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了take函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: main
function* main() {
while( yield take('START_BACKGROUND_SYNC') ) {
// starts the task in the background
const bgSyncTask = yield fork(bgSync)
// wait for the user stop action
yield take('STOP_BACKGROUND_SYNC')
// user clicked stop. cancel the background task
// this will throw a SagaCancellationException into the forked bgSync
// task
yield cancel(bgSyncTask)
}
}
示例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: incrementAsync
const incrementAsync:Saga = function* incrementAsync() {
while(true) {
// wait for each INCREMENT_ASYNC action
const nextAction = yield take('INCREMENT_ASYNC')
// delay is a sample function
// return a Promise that resolves after (ms) milliseconds
yield delay(1000)
// dispatch INCREMENT_COUNTER
yield put( {type: 'INCREMENT_COUNTER'} )
}
}
示例4: watchFetch
function* watchFetch() {
while ( yield take('FETCH_POSTS') ) {
yield fork(fetchPosts) // non blocking call
}
}