babel-plugin-promise-add-catch

1.1.1 • Public • Published

babel-plugin-promise-add-catch

GitHub issues GitHub forks GitHub stars GitHub license

Install

npm i babel-plugin-promise-add-catch -D

Usage

Via babel.config.js or babel-loader.

{
  "plugins": [["promise-add-catch", options]]
}

options

options is object.

{
  "promiseNames": ['$confirm', 'confirm', '$prompt', 'getUserInfo'],
  "catchCallback" 'console.log(err)'
}
  • promiseNames:array: Choose to add catch for the specified Promise; if it is empty, don't add catch for any Promise; if you don't set this option, add catch for all Promise;

  • catchCallback:string: The function body of catch callback, the parameter is err; if not set, the callback of catch defaults to err => err;

Example

Converts

this.$confirm().then()

MessageBox.confirm().then()

this['$prompt'].then()

getUserInfo().then()

getUserInfo().then().catch()

ctx.$confirm("是否确定删除?", "提示", {
  type: "warning"
}).then(() => {
  getUserInfo().then(() => {
    getPermission().then()
  })
})

To

this.$confirm().then().catch(err => { console.log(err) })

MessageBox.confirm().then().catch(err => { console.log(err) })

this['$prompt'].then().catch(err => { console.log(err) })

getUserInfo().then().catch(err => { console.log(err) })

getUserInfo().then().catch()

ctx.$confirm("是否确定删除?", "提示", {
  type: "warning"
}).then(() => {
  getUserInfo().then(() => {
    getPermission().then().catch(err => { console.log(err) })
  }).catch(err => { console.log(err) })
}).catch(err => { console.log(err) })

Development

npm run test

Build

npm run build

Readme

Keywords

Package Sidebar

Install

npm i babel-plugin-promise-add-catch

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

6.03 kB

Total Files

3

Last publish

Collaborators

  • hulkshen