BubbleSci 12518df3cc docs: revise English translation | 4 yıl önce | |
---|---|---|
.. | ||
dist | 4 yıl önce | |
test | 4 yıl önce | |
CHANGELOG.md | 4 yıl önce | |
README.md | 4 yıl önce | |
README_EN.md | 4 yıl önce | |
index.js | 4 yıl önce | |
install.js | 4 yıl önce | |
package.json | 4 yıl önce |
English | 简体中文
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);
支持 weapp-style的所有功能:
func({
success () {},
fail () {}
})
wepy.promisify(func)({key: 'mykey'}).then(console.log).catch(console.error);
支持所有 error-first
功能,例如:
func(arg1, args2, function (err, data) {});
wepy.promisify(func, null, 'error-first')(arg1, arg2).then(console.log).catch(console.error);
weapp-style
函数始终需要一个Object参数,并且此插件将简化参数。例如:
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);
在这里我们可以看到所有的简化列表 Simplify List