Gcaufy 4f07b2cfa5 feat: added ci release support | 4 éve | |
---|---|---|
.. | ||
dist | 4 éve | |
test | 4 éve | |
CHANGELOG.md | 4 éve | |
README.md | 4 éve | |
index.js | 4 éve | |
install.js | 4 éve | |
package.json | 4 éve |
Promisfy all weapp APIs.
npm install @wepy/use-promisify --save
import wepy from '@wepy/core';
import promisify from '@wepy/use-promisify';
wepy.use(promisify);
wepy.wx.getStorage('mykey').then(res => console.log(res));
wepy.use(promisify, ['getStorage', 'getSystemInfo']);
// passing object
// wepy.use(promisify, { someNewAPI: false, getStorage: true });
wepy.wx.getStorage({
key: 'mykey',
succuess (res) { console.log(res) }
})
Support to use wepy.promisify
to promisify a callback function.
/**
* Promisify a callback function
* @param {Function} fn callback function
* @param {Object} caller caller
* @param {String} type weapp-style|error-first, default to weapp-style
* @return {Function} promisified function
*/
wepy.promisify(fn, caller, type);
Supports all function which is weapp-style:
func({
success () {},
fail () {}
})
wepy.promisify(func)({key: 'mykey'}).then(console.log).catch(console.error);
Supports all error-first
functions, like:
func(arg1, args2, function (err, data) {});
wepy.promisify(func, null, 'error-first')(arg1, arg2).then(console.log).catch(console.error);
weapp-style
function always need a Object params, and this plugin will simplify the parameters. e.g.
wepy.use(promisify);
// wepy.wx.getStorage({ key: 'mykey' });
wepy.wx.getStorage('mykey');
// wepy.wx.request({ url: myurl });
wepy.wx.request(myurl);
// wepy.wx.openLocation({ latitude: 0, longitude: 0 });
wepy.wx.openLocation(0, 0);
Here we can see all the Simplify List