@mpxjs/api-proxy 2.9.20 → 2.9.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/api-proxy",
3
- "version": "2.9.20",
3
+ "version": "2.9.22",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -39,5 +39,5 @@
39
39
  "dependencies": {
40
40
  "axios": "^1.6.7"
41
41
  },
42
- "gitHead": "2813da00b63ec85a3bcd4355979c5adb56c853fd"
42
+ "gitHead": "0ef19708a763b6e7a9338591618197d8d33adbfd"
43
43
  }
@@ -1,4 +1,4 @@
1
- import { getEnvObj, noop } from './utils'
1
+ import { getEnvObj } from './utils'
2
2
 
3
3
  const envObj = getEnvObj()
4
4
 
@@ -68,29 +68,20 @@ function promisify (listObj, whiteList, customBlackList) {
68
68
  }
69
69
 
70
70
  result[key] = function (...args) {
71
- if (promisifyFilter(key)) {
72
- if (!args[0]) {
73
- args.unshift({ success: noop, fail: noop })
74
- }
75
- const obj = args[0]
71
+ const obj = args[0] || {}
72
+ // 不需要转换 or 用户已定义回调,则不处理
73
+ if (!promisifyFilter(key) || obj.success || obj.fail) {
74
+ return listObj[key].apply(envObj, args)
75
+ } else { // 其他情况进行转换
76
+ if (!args[0]) args.unshift(obj)
76
77
  let returned
77
78
  const promise = new Promise((resolve, reject) => {
78
- const originSuccess = obj.success
79
- const originFail = obj.fail
80
- obj.success = function (res) {
81
- originSuccess && originSuccess.call(this, res)
82
- resolve(res)
83
- }
84
- obj.fail = function (e) {
85
- originFail && originFail.call(this, e)
86
- reject(e)
87
- }
79
+ obj.success = resolve
80
+ obj.fail = reject
88
81
  returned = listObj[key].apply(envObj, args)
89
82
  })
90
83
  promise.__returned = returned
91
84
  return promise
92
- } else {
93
- return listObj[key].apply(envObj, args)
94
85
  }
95
86
  }
96
87
  })