oak-frontend-base/lib/utils/promisify.js

25 lines
735 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.promisify = promisify;
/**
* 将小程序的API封装成支持Promise的API, 小程序部分api不支持promise
* @params fn {Function} 小程序原始API如wx.login
*/
function promisify(fn) {
return function (obj) {
return new Promise((resolve, reject) => {
obj.success = function (res) {
resolve(res);
};
obj.fail = function (res) {
reject(res);
};
obj.cancel = function () {
// 微信jsSdk api有cancel回调
reject({ errMsg: 'request:cancel' });
};
fn(obj);
});
};
}