weapp-promisify-api
v1.0.1
Published
promisify all apis of wx
Downloads
2
Readme
weapp-promisify
usage
- Before:
wx.setStorage({
key: "key",
data: "value",
success: function() {
console.log('>>>save success.')
},
fail: function() {
console.log('>>>save fail.')
},
})
- After:
const Promisify = require('weapp-promisify')
const weapp = new Promisify(wx)
weapp.setStorage({
key: "key",
data: "value",
})
.then(() => {
console.log('>>>save success.')
})
.catch(() => {
console.log('>>>save error.')
})
//>>>save success.
option
- interceptor
const Promisify = require('weapp-promisify')
const weapp = new Promisify(wx)
weapp.use(function(opt) {
if (opt.key === 'key') {
return false
}
return true
})
weapp.setStorage({
key: "key",
data: "value",
})
.then(() => {
console.log('>>>save success.')
})
.catch((e) => {
console.log('>>>save error.', e)
})
//>>>save error. weapp-promisify interceptor return false