1.0.1 • Published 3 years ago

miniprogram-api-promise-error-first v1.0.1

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

miniprogram-api-promise-error-first

npm.io

Extend WeChat miniprogram's api to surport promise.

Installation

npm install --save miniprogram-api-promise-error-first

Getting started

Call the method promisifyAll at the program entry (app.js), It only needs to be called once.

💨example:

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

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

(async () => {
    const [err, systemInfo] = await wxp.getSystemInfo()
    if (err) {
        console.error(err)
        return
    }
    console.log(systemInfo)
});


(async () => {
    const [err] = await wxp.showModal()
    if (err) {
        console.error(err)
        return
    }
    
    wxp.openSetting()
});

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

(async () => {
    // promisify single api
    const [err, res] = await promisify(wx.getSystemInfo)()
});