Skip to content

Instantly share code, notes, and snippets.

@borie88
Created March 10, 2019 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borie88/8028d94fdbecfa05c3d4119f54fbe88e to your computer and use it in GitHub Desktop.
Save borie88/8028d94fdbecfa05c3d4119f54fbe88e to your computer and use it in GitHub Desktop.
Wrap WeChat Mini Program APIs with a Promise
const methods = [
'getStorage',
'setStorage',
'getSystemInfo'
]
const wxp = {}
methods.forEach((method) => {
wxp[method] = (args = {}) =>
new Promise((resolve, reject) => {
args.success = (res) => resolve(res)
args.fail = (err) => reject(err)
wx[method](args)
})
})
module.exports = wxp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment