这是indexloc提供的服务,不要输入任何密码
Skip to content

Minor documentation improvements #27

@mcshaz

Description

@mcshaz

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

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions