@mpxjs/api-proxy 2.10.3-beta.1 → 2.10.3-beta.3

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.10.3-beta.1",
3
+ "version": "2.10.3-beta.3",
4
4
  "description": "convert miniprogram API at each end",
5
5
  "module": "src/index.js",
6
6
  "types": "@types/index.d.ts",
@@ -44,7 +44,8 @@ const blackList = [
44
44
  'getExptInfoSync',
45
45
  'reserveChannelsLive',
46
46
  'getNFCAdapter',
47
- 'isVKSupport'
47
+ 'isVKSupport',
48
+ 'getState'
48
49
  ]
49
50
 
50
51
  function getMapFromList (list) {
@@ -34,7 +34,7 @@ function resolvePath (relative, base) {
34
34
  return stack.join('/')
35
35
  }
36
36
  let timerId = null
37
- function isLock (navigationHelper, type, options) {
37
+ function isLock (navigationHelper = {}, type, options) {
38
38
  if (navigationHelper.lastSuccessCallback && navigationHelper.lastFailCallback) {
39
39
  const res = { errMsg: `${type}:fail the previous routing event didn't complete` }
40
40
  failHandle(res, options.fail, options.complete)
@@ -156,10 +156,53 @@ function switchTab () {
156
156
 
157
157
  }
158
158
 
159
+ function reset (options = {}) {
160
+ const routes = options.routes || []
161
+ if (!routes.length) {
162
+ const res = { errMsg: 'reset:fail routes cannot be an empty array' }
163
+ failHandle(res, options.fail, options.complete)
164
+ return
165
+ }
166
+ const resetOption = Object.keys(options).reduce((resOpt, key) => {
167
+ if (key !== 'fail' && key !== 'complete' && key !== 'success') {
168
+ resOpt[key] = options[key]
169
+ }
170
+ return resOpt
171
+ }, {})
172
+ const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
173
+ const navigationHelper = global.__navigationHelper
174
+ if (isLock(navigationHelper, 'reset', options)) {
175
+ return
176
+ }
177
+ if (navigation && navigationHelper) {
178
+ navigation.reset(Object.assign(resetOption, {
179
+ index: routes.length - 1
180
+ }))
181
+ navigationHelper.lastSuccessCallback = () => {
182
+ const res = { errMsg: 'reset:ok' }
183
+ successHandle(res, options.success, options.complete)
184
+ }
185
+ navigationHelper.lastFailCallback = (msg) => {
186
+ const res = { errMsg: `reset:fail ${msg}` }
187
+ failHandle(res, options.fail, options.complete)
188
+ }
189
+ }
190
+ }
191
+
192
+ function getState () {
193
+ const navigation = Object.values(global.__mpxPagesMap || {})[0]?.[1]
194
+ if (navigation) {
195
+ return navigation.getState()
196
+ }
197
+ return {}
198
+ }
199
+
159
200
  export {
160
201
  redirectTo,
161
202
  navigateTo,
162
203
  navigateBack,
163
204
  reLaunch,
164
- switchTab
205
+ switchTab,
206
+ reset,
207
+ getState
165
208
  }
@@ -10,10 +10,16 @@ const reLaunch = ENV_OBJ.reLaunch || envError('reLaunch')
10
10
 
11
11
  const switchTab = ENV_OBJ.switchTab || envError('switchTab')
12
12
 
13
+ const reset = envError('reset')
14
+
15
+ const getState = envError('getState')
16
+
13
17
  export {
14
18
  redirectTo,
15
19
  navigateTo,
16
20
  navigateBack,
17
21
  reLaunch,
18
- switchTab
22
+ switchTab,
23
+ reset,
24
+ getState
19
25
  }
@@ -1,4 +1,4 @@
1
- import { successHandle, failHandle, isTabBarPage, throwSSRWarning, isBrowser } from '../../../common/js'
1
+ import { successHandle, failHandle, isTabBarPage, throwSSRWarning, isBrowser, envError } from '../../../common/js'
2
2
  import { EventChannel } from '../event-channel'
3
3
 
4
4
  let routeCount = 0
@@ -183,10 +183,16 @@ function switchTab (options = {}) {
183
183
  }
184
184
  }
185
185
 
186
+ const reset = envError('reset')
187
+
188
+ const getState = envError('getState')
189
+
186
190
  export {
187
191
  redirectTo,
188
192
  navigateTo,
189
193
  navigateBack,
190
194
  reLaunch,
191
- switchTab
195
+ switchTab,
196
+ reset,
197
+ getState
192
198
  }