wx-miniapp-promisify

1.0.0 • Public • Published

Wechat Miniapp Promisify

GitHub license Coverage Status TravisCI

Read this in other languages: English, 简体中文

wx-miniapp-promisify is a simple wrapper to return the most commonly used wx async functions as Promises. This library should only be used in a WeChat miniapp.

Table of Contents

How to install via NPM in WeChat miniapp

  1. Go to your wechat app folder and run npm install wx-miniapp-promisify.
  2. In your WeChat IDE, ensure the following,
    1. In "Settings > Project Settings", ensure that "Transpile ES6 to ES5" and "Use NPM module" is checked.
    2. Run npm build in "Tools > Build npm".

How to use wx-miniapp-promisify

  1. Using import or require statements to include the library into your code.
// Example with "import" syntax in page/index.js

import wxPromise from 'wx-miniapp-promisify';


// Example with "require" syntax in page/index.js

let wxPromise = require('wx-miniapp-promisify');
  1. wx-miniapp-promisify functions are a replica of wx async functions.
// Example code for a "normal wx.request"

let normalResponse = wx.request({
    url: 'test.php', // imaginary url endpoint
    data: {
        x: '',
        y: ''
    },
    header: {
        'content-type': 'application/json'
    },
    success (res) {
        console.log(res.data)
    }
});

// Example using "wx-miniapp-promisify"

let promiseResponse = wxPromise.request({
    url: 'test.php', // imaginary url endpoint
    data: {
        x: '',
        y: ''
    },
    header: {
        'content-type': 'application/json'
    },
    success (res) {
        console.log(res.data)
    }
});

Helper Methods

Method Name Parameters Type Return Value Example
isPromisable methodName string boolean wxPromise.isPromisable('newWxMethod')

Supported Methods

Package Sidebar

Install

npm i wx-miniapp-promisify

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

98.1 kB

Total Files

7

Last publish

Collaborators

  • gjiehs