@mpxjs/core 2.8.5 → 2.8.7

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/@types/index.d.ts CHANGED
@@ -7,8 +7,10 @@
7
7
  /// <reference path="./global.d.ts" />
8
8
  /// <reference path="./node.d.ts" />
9
9
 
10
+ // @ts-ignore
10
11
  import type { GetComputedType } from '@mpxjs/store'
11
12
 
13
+ // @ts-ignore
12
14
  export * from '@mpxjs/store'
13
15
 
14
16
  // utils
@@ -571,27 +573,29 @@ export function onBeforeUnmount (callback: () => void): void
571
573
 
572
574
  export function onUnmounted (callback: () => void): void
573
575
 
574
- export function onLoad<T extends object> (callback: (query: T) => void): void
576
+ export function onLoad<T extends Record<string, string | undefined>> (callback: (query: T) => void): void
577
+ // wechat dose not have generics
578
+ // export function onLoad (callback: WechatMiniprogram.Page.ILifetime['onLoad']): void
575
579
 
576
- export function onShow (callback: () => void): void
580
+ export function onShow (callback: WechatMiniprogram.Page.ILifetime['onShow']): void
577
581
 
578
- export function onHide (callback: () => void): void
582
+ export function onHide (callback: WechatMiniprogram.Page.ILifetime['onHide']): void
579
583
 
580
- export function onResize (callback: () => void): void
584
+ export function onResize (callback: WechatMiniprogram.Page.ILifetime['onResize']): void
581
585
 
582
- export function onPullDownRefresh (callback: () => void): void
586
+ export function onPullDownRefresh (callback: WechatMiniprogram.Page.ILifetime['onPullDownRefresh']): void
583
587
 
584
- export function onReachBottom (callback: () => void): void
588
+ export function onReachBottom (callback: WechatMiniprogram.Page.ILifetime['onReachBottom']): void
585
589
 
586
- export function onShareAppMessage (callback: () => void): void
590
+ export function onShareAppMessage (callback: WechatMiniprogram.Page.ILifetime['onShareAppMessage']): void
587
591
 
588
- export function onShareTimeline (callback: () => void): void
592
+ export function onShareTimeline (callback: WechatMiniprogram.Page.ILifetime['onShareTimeline']): void
589
593
 
590
- export function onAddToFavorites (callback: () => void): void
594
+ export function onAddToFavorites (callback: WechatMiniprogram.Page.ILifetime['onAddToFavorites']): void
591
595
 
592
- export function onPageScroll (callback: () => void): void
596
+ export function onPageScroll (callback: WechatMiniprogram.Page.ILifetime['onPageScroll']): void
593
597
 
594
- export function onTabItemTap (callback: () => void): void
598
+ export function onTabItemTap (callback: WechatMiniprogram.Page.ILifetime['onTabItemTap']): void
595
599
 
596
600
  export function onSaveExitState (callback: () => void): void
597
601
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.8.5",
3
+ "version": "2.8.7",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -47,5 +47,5 @@
47
47
  "url": "https://github.com/didi/mpx/issues"
48
48
  },
49
49
  "sideEffects": false,
50
- "gitHead": "c4cb7f7244d13a59535891acf02c347960c52343"
50
+ "gitHead": "d064d3caf12023c955f79cecdb92b90d479a6a05"
51
51
  }
@@ -1,5 +1,21 @@
1
+ import { error } from '@mpxjs/utils'
2
+
3
+ const BEHAVIORS_MAP = [
4
+ 'wx://form-field',
5
+ 'wx://form-field-group',
6
+ 'wx://form-field-button',
7
+ 'wx://component-export'
8
+ ]
9
+
1
10
  export default {
2
11
  convert (options) {
3
- // 暂时无需转换
12
+ if (options.behaviors) {
13
+ options.behaviors.forEach((behavior, idx) => {
14
+ if (BEHAVIORS_MAP.includes(behavior)) {
15
+ error(`Built-in behavior "${behavior}" is not supported in tt environment!`, global.currentResource)
16
+ options.behaviors.splice(idx, 1)
17
+ }
18
+ })
19
+ }
4
20
  }
5
21
  }
@@ -48,30 +48,31 @@ if (isBrowser) {
48
48
  }
49
49
 
50
50
  export default function pageStatusMixin (mixinType) {
51
+ const mixin = {}
52
+
51
53
  if (mixinType === 'page') {
52
- return {
54
+ Object.assign(mixin, {
53
55
  data: {
54
- mpxPageStatus: 'show'
56
+ mpxPageStatus: null
55
57
  },
56
58
  activated () {
57
59
  this.mpxPageStatus = 'show'
58
- this.__mpxProxy.callHook(ONSHOW)
59
60
  },
60
61
  deactivated () {
61
62
  this.mpxPageStatus = 'hide'
62
- this.__mpxProxy.callHook(ONHIDE)
63
63
  },
64
64
  created () {
65
65
  // onLoad应该在用户声明周期CREATED后再执行,故此处使用原生created声明周期来触发onLoad
66
66
  const query = (global.__mpxRouter && global.__mpxRouter.currentRoute && global.__mpxRouter.currentRoute.query) || {}
67
67
  this.__mpxProxy.callHook(ONLOAD, [query])
68
68
  }
69
- }
69
+ })
70
70
  }
71
- return {
71
+
72
+ Object.assign(mixin, {
72
73
  [CREATED] () {
73
- const pageInstance = getCurrentPageInstance()
74
- if (!pageInstance) {
74
+ const pageInstance = mixinType === 'page' ? this : getCurrentPageInstance()
75
+ if (pageInstance) {
75
76
  this.$watch(() => pageInstance.mpxPageStatus, status => {
76
77
  if (!status) return
77
78
  if (status === 'show') this.__mpxProxy.callHook(ONSHOW)
@@ -91,5 +92,7 @@ export default function pageStatusMixin (mixinType) {
91
92
  })
92
93
  }
93
94
  }
94
- }
95
+ })
96
+
97
+ return mixin
95
98
  }
@@ -7,7 +7,6 @@ const APIs = {
7
7
  mixin: injectMixins,
8
8
  observable: reactive,
9
9
  watch,
10
- // use,
11
10
  set,
12
11
  delete: del
13
12
  }
@@ -1,25 +1,23 @@
1
1
  import Vue from '../../vue'
2
2
  import { injectMixins } from '../../core/injectMixins'
3
3
 
4
- function initApi () {
5
- const vm = new Vue()
6
- const observable = Vue.observable.bind(Vue)
7
- const watch = vm.$watch.bind(vm)
8
- const set = Vue.set.bind(Vue)
9
- const del = Vue.delete.bind(Vue)
10
- APIs = {
11
- injectMixins,
12
- mixin: injectMixins,
13
- observable,
14
- watch,
15
- // use,
16
- set,
17
- delete: del
18
- }
19
- return APIs
4
+ const vm = new Vue()
5
+ const observable = Vue.observable.bind(Vue)
6
+ const watch = vm.$watch.bind(vm)
7
+ const set = Vue.set.bind(Vue)
8
+ const del = Vue.delete.bind(Vue)
9
+
10
+ const APIs = {
11
+ injectMixins,
12
+ mixin: injectMixins,
13
+ observable,
14
+ watch,
15
+ set,
16
+ delete: del
20
17
  }
21
- let APIs = initApi()
18
+
22
19
  const InstanceAPIs = {}
20
+
23
21
  export {
24
22
  APIs,
25
23
  InstanceAPIs