-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation
Description
First thank you and well done for making such for a great library
The docs are great, but a few small thoughts on improvements:
Using with typescript
If you are passing a Task down as a property to a child component, you can use the typing
const t = props.modelValue as ReturnType<typeof useTask>
Error handling
if you need to perform error handling within the useTask yielded function, define it on the signal argument first. For example if you were logging all calls to the server.
const componentLog = log.create("MyComponent")
const task = useTask(function*(signal, ){
signal.pr.then(() => componentLog.info('successfully posted'),
err=> {
componentLog.warn('failed post', err)
return Promise.reject(err)
})
yield axios.post(`api/...`)
Cancelation
A bit more info would be great around - what happens to the try/catch block if cancel or cancelAll has been called vs the server returning an error. using the example above
const componentLog = log.create("MyComponent")
const task = useTask(function*(signal, ){
signal.pr.then(() => componentLog.info('successfully posted'),
err=> {
if (err === 'cancel') {
componentLog.warn('request cancelled by user')
} else {
componentLog.error('failed post', err)
}
return Promise.reject(err)
})
Thanks again
Metadata
Metadata
Assignees
Labels
documentationImprovements or additions to documentationImprovements or additions to documentation