Created
March 10, 2019 15:26
-
-
Save borie88/8028d94fdbecfa05c3d4119f54fbe88e to your computer and use it in GitHub Desktop.
Wrap WeChat Mini Program APIs with a Promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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