You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
var each = require('./each'); |
|
var arrToMap = require('./arrToMap'); |
|
var startWith = require('./startWith'); |
|
var endWith = require('./endWith'); |
|
var extend = require('./extend'); |
|
|
|
var noPromiseMethods = arrToMap([ |
|
'stopRecord', |
|
'getRecorderManager', |
|
'pauseVoice', |
|
'stopVoice', |
|
'pauseBackgroundAudio', |
|
'stopBackgroundAudio', |
|
'getBackgroundAudioManager', |
|
'createAudioContext', |
|
'createInnerAudioContext', |
|
'createVideoContext', |
|
'createCameraContext', |
|
'createMapContext', |
|
'canIUse', |
|
'startAccelerometer', |
|
'stopAccelerometer', |
|
'startCompass', |
|
'stopCompass', |
|
'onBLECharacteristicValueChange', |
|
'onBLEConnectionStateChange', |
|
'hideToast', |
|
'hideLoading', |
|
'showNavigationBarLoading', |
|
'hideNavigationBarLoading', |
|
'navigateBack', |
|
'createAnimation', |
|
'pageScrollTo', |
|
'createSelectorQuery', |
|
'createCanvasContext', |
|
'createContext', |
|
'drawCanvas', |
|
'hideKeyboard', |
|
'stopPullDownRefresh', |
|
'arrayBufferToBase64', |
|
'base64ToArrayBuffer' |
|
]); |
|
function needToPromisify(name) { |
|
return ( |
|
!noPromiseMethods[name] && |
|
!startWith(name, 'on') && |
|
!endWith(name, 'Sync') |
|
); |
|
} |
|
each(wx, function(fn, name) { |
|
if (!needToPromisify(name)) return; |
|
exports[name] = function(obj) { |
|
return new Promise(function(resolve, reject) { |
|
fn.call( |
|
wx, |
|
extend(obj, { |
|
success: function(res) { |
|
resolve(res); |
|
}, |
|
fail: function(res) { |
|
reject(res); |
|
} |
|
}) |
|
); |
|
}); |
|
}; |
|
}); |
|
|
|
module.exports = exports;
|
|
|