Skip to content

Commit

Permalink
feat: add type defined
Browse files Browse the repository at this point in the history
  • Loading branch information
vv13 committed Sep 13, 2020
1 parent 6ae3996 commit d190ec1
Show file tree
Hide file tree
Showing 3 changed files with 18,248 additions and 7 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@
```

使用Proxy + ES Promise实现,核心代码只有10行
使用Proxy + ES Promise实现,核心代码只有10行,含有 TypeScript 类型定义。

## 安装
```
$ npm i wx-api-promisify
```

## 示例
若您的工程支持,推荐使用async/await。以下为获取用户信息->下载文件->保存到相册的Promise示例:
若您的工程支持,推荐使用async/await。以下为获取用户信息->下载头像->保存到相册的Promise示例:
```
import wxPromise from 'wx-api-promisify'
Page({
...
getUserInfo() {
wxPromise.getUserInfo()
.then(({ userInfo: { avatarUrl } }) => wxPromise.downloadFile({ url: avatarUrl }))
.then(({ tempFilePath }) => wxPromise.saveImageToPhotosAlbum({ filePath: tempFilePath })
const { userInfo: { avatarUrl } } = await wxPromise.getUserInfo()
const { tempFilePath } = await wxPromise.downloadFile({ url: avatarUrl }))
await wxPromise.saveImageToPhotosAlbum({ filePath: tempFilePath })
},
})
```
Loading

0 comments on commit d190ec1

Please sign in to comment.