You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/api-proxy/src/common/js/promisify.js
+12-26Lines changed: 12 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,14 @@
1
-
import{ENV_OBJ}from'./utils'
1
+
import{ENV_OBJ,warn}from'./utils'
2
2
3
3
// 特别指定的不进行Promise封装的方法
4
4
constblackList=[
5
-
'clearStorage',
6
-
'hideToast',
7
-
'hideLoading',
8
5
'drawCanvas',
9
6
'canIUse',
10
-
'stopRecord',
11
-
'pauseVoice',
12
-
'stopVoice',
13
-
'pauseBackgroundAudio',
14
-
'stopBackgroundAudio',
15
-
'showNavigationBarLoading',
16
-
'hideNavigationBarLoading',
17
7
'getPerformance',
18
-
'hideKeyboard',
19
-
'stopPullDownRefresh',
20
-
'pageScrollTo',
21
8
'reportAnalytics',
22
9
'getMenuButtonBoundingClientRect',
23
10
'reportMonitor',
24
11
'reportEvent',
25
-
'connectSocket',
26
12
'base64ToArrayBuffer',
27
13
'arrayBufferToBase64',
28
14
'getDeviceInfo',
@@ -33,16 +19,12 @@ const blackList = [
33
19
'postMessageToReferrerPage',
34
20
'postMessageToReferrerMiniProgram',
35
21
'reportPerformance',
36
-
'getPerformance',
37
-
'preDownloadSubpackage',
38
22
'router',
39
23
'nextTick',
40
24
'checkIsPictureInPictureActive',
41
25
'worklet',
42
26
'revokeBufferURL',
43
-
'reportEvent',
44
27
'getExptInfoSync',
45
-
'reserveChannelsLive',
46
28
'getNFCAdapter',
47
29
'isVKSupport'
48
30
]
@@ -79,18 +61,22 @@ function promisify (listObj, whiteList, customBlackList) {
79
61
if(typeoflistObj[key]!=='function'){
80
62
return
81
63
}
82
-
83
-
result[key]=function(...args){
84
-
constobj=args[0]||{}
85
-
// 不需要转换 or 用户已定义回调,则不处理
86
-
if(!promisifyFilter(key)){
87
-
returnlistObj[key].apply(ENV_OBJ,args)
88
-
}else{// 其他情况进行转换
64
+
if(!promisifyFilter(key)){
65
+
result[key]=listObj[key].bind(ENV_OBJ)
66
+
}else{
67
+
result[key]=function(...args){
68
+
constobj=args[0]||{}
69
+
if(obj.usePromise===false){
70
+
returnlistObj[key].apply(ENV_OBJ,args)
71
+
}
89
72
if(!args[0])args.unshift(obj)
90
73
letreturned
91
74
constpromise=newPromise((resolve,reject)=>{
92
75
constoriginSuccess=obj.success
93
76
constoriginFail=obj.fail
77
+
if(originSuccess||originFail){
78
+
warn(`The [${key}] method has been promisified, please use .then or .catch to handle the result, if you need to handle the result with options.success/fail, please set options.usePromise to false to close the promisify in this call temporarily. `)
0 commit comments