@mpxjs/api-proxy 2.9.0-beta.0 → 2.9.0-beta.2

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.0-beta.0",
3
+ "version": "2.9.0-beta.2",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "promise"
32
32
  ],
33
33
  "author": "httpsxiao",
34
- "license": "ISC",
34
+ "license": "Apache-2.0",
35
35
  "bugs": {
36
36
  "url": "https://github.com/didi/mpx/issues"
37
37
  },
@@ -39,5 +39,5 @@
39
39
  "dependencies": {
40
40
  "axios": "^0.21.1"
41
41
  },
42
- "gitHead": "67b611aeae99f916d46ca8d5d9ed784ddf53f05c"
42
+ "gitHead": "2d61bab77c50eccb7470b9b9bd644e7bd6510467"
43
43
  }
package/src/index.js CHANGED
@@ -9,8 +9,7 @@ export default function install (target, options = {}) {
9
9
  platform = {},
10
10
  exclude = ['shareImageMessage'], // 强制不进行代理的api,临时fix微信分享朋友圈白屏
11
11
  custom = {}, // 自定义转化规则
12
- fallbackMap = {}, // 对于不支持的API,允许配置一个映射表,接管不存在的API
13
- optimize = false // 内部一些实验优化的开关,外部用户慎用
12
+ fallbackMap = {} // 对于不支持的API,允许配置一个映射表,接管不存在的API
14
13
  } = options
15
14
 
16
15
  let { from = '', to = '' } = platform
@@ -40,8 +39,7 @@ export default function install (target, options = {}) {
40
39
  exclude,
41
40
  from,
42
41
  to,
43
- custom,
44
- optimize
42
+ custom
45
43
  })
46
44
 
47
45
  const promisedApi = usePromise ? promisify(transedApi, whiteList, blackList) : {}
@@ -6,10 +6,7 @@ const TIPS_NAME = '支付宝环境 mpx'
6
6
  // canvas api 用
7
7
  const CANVAS_MAP = {}
8
8
 
9
- // optimize case avoid call api multi times with getSystemInfoSync
10
- let systemInfo
11
-
12
- const getWxToAliApi = ({ optimize = false }) => {
9
+ const getWxToAliApi = () => {
13
10
  return {
14
11
  /**
15
12
  * 基础
@@ -34,10 +31,6 @@ const getWxToAliApi = ({ optimize = false }) => {
34
31
  },
35
32
 
36
33
  getSystemInfoSync () {
37
- if (optimize) {
38
- if (systemInfo) return systemInfo
39
- }
40
-
41
34
  const res = ALI_OBJ.getSystemInfoSync() || {}
42
35
 
43
36
  res.system = `${res.platform} ${res.system}`
@@ -48,8 +41,6 @@ const getWxToAliApi = ({ optimize = false }) => {
48
41
  res.windowHeight = Math.floor(res.screenHeight * res.windowWidth / res.screenWidth) - 50
49
42
  }
50
43
 
51
- if (optimize) systemInfo = res
52
-
53
44
  return res
54
45
  },
55
46
 
@@ -14,7 +14,7 @@ function transformApi (options) {
14
14
  const from = options.from
15
15
  const to = options.to
16
16
  const fromTo = joinName(from, to)
17
- const wxToAliApi = getWxToAliApi({ optimize: options.optimize })
17
+ const wxToAliApi = getWxToAliApi()
18
18
  const wxToQqApi = getWxToQqApi()
19
19
  const wxToTtApi = getWxToTtApi()
20
20
  const platformMap = {
@@ -19,13 +19,13 @@ class EventChannel {
19
19
  }
20
20
  }
21
21
 
22
- off (eventName, EventCallback) {
23
- if (EventCallback) {
22
+ off (eventName, listener) {
23
+ if (listener) {
24
24
  const cbs = this.listener[eventName]
25
25
  const copyCbs = []
26
26
  if (cbs) {
27
27
  cbs.forEach((item) => {
28
- if (item.fn !== EventCallback) {
28
+ if (item.fn !== listener) {
29
29
  copyCbs.push(item)
30
30
  }
31
31
  })
@@ -36,26 +36,25 @@ class EventChannel {
36
36
  }
37
37
  }
38
38
 
39
- on (eventName, EventCallback) {
40
- (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type: 'on' })
39
+ on (eventName, listener) {
40
+ this._addListener(eventName, listener, 'on')
41
41
  }
42
42
 
43
- once (eventName, EventCallback) {
44
- (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type: 'once' })
43
+ once (eventName, listener) {
44
+ this._addListener(eventName, listener, 'once')
45
45
  }
46
46
 
47
- _addListener (eventName, EventCallback, type) {
48
- (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: EventCallback, type })
47
+ _addListener (eventName, listener, type) {
48
+ (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: listener, type })
49
49
  }
50
50
 
51
51
  _addListeners (events) {
52
- if (Object.prototype.toString.call(events) === '[object Object]') {
53
- Object.keys(events).forEach((eventName) => {
54
- (this.listener[eventName] || (this.listener[eventName] = [])).push({ fn: events[eventName], type: 'on' })
55
- })
56
- }
52
+ Object.keys(events).forEach((eventName) => {
53
+ this.on(eventName, events[eventName])
54
+ })
57
55
  }
58
56
  }
57
+
59
58
  export {
60
59
  EventChannel
61
60
  }