1.0.7 • Published 3 years ago

miniprogram-api-promise-forallapi v1.0.7

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

miniprogram-api-promise-forallapi

npm.io npm.io

Extend WeChat miniprogram's all apis to surport promise.

Installation

npm install --save miniprogram-api-promise-forallapi

Getting started

Call the method promisifyAll at the program entry (app.js), It only needs to be called once. The package on the wechat official website does not convert all APIs to promise, but it can be used here

💨example:

import { promisifyAll, promisify } from 'miniprogram-api-promise-forallapi';

const wxp = {}
// promisify all wx's api
promisifyAll(wx, wxp)
console.log(wxp.getSystemInfoSync())
wxp.getSystemInfo().then(console.log)
wxp.showModal().then(wxp.openSetting())

// compatible usage
wxp.getSystemInfo({success(res) {console.log(res)}})

// promisify single api
promisify(wx.getSystemInfo)().then(console.log)

// even if wx.getAccountInfoSync is not a promise interface,but we can still use it like this。
wxp.getAccountInfoSync().then(console.log)

// We can also use it like this
promisify('not a functoin').then(console.log)
1.0.7

3 years ago

1.0.6

3 years ago

1.0.4

3 years ago

1.0.0

3 years ago