@mpxjs/core 2.8.15 → 2.8.19

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
@@ -69,10 +69,6 @@ interface WatchField {
69
69
  [key: string]: WatchHandler | WatchOptWithHandler
70
70
  }
71
71
 
72
- interface ObserversDefs {
73
- [expression: string]: (...fields: any[]) => any
74
- }
75
-
76
72
  type GetDataType<T> = T extends () => any ? ReturnType<T> : T
77
73
 
78
74
  type PropValueType<Def> = Def extends {
@@ -119,34 +115,19 @@ interface Context {
119
115
  createIntersectionObserver: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createIntersectionObserver']
120
116
  }
121
117
 
122
- interface ComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> extends Partial<WechatMiniprogram.Component.Lifetimes> {
118
+ interface ComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> extends Partial<WechatMiniprogram.Component.Lifetimes & WechatMiniprogram.Component.OtherOption>{
123
119
  data?: D
124
120
  properties?: P
125
121
  computed?: C
126
122
  methods?: M
127
123
  mixins?: Mi
128
124
  watch?: WatchField
129
- observers?: ObserversDefs
130
- options?: Partial<{
131
- addGlobalClass: boolean
132
- multipleSlots: boolean
133
- styleIsolation: string
134
- }>
135
-
136
125
  setup?: (props: GetPropsType<P & UnboxMixinsField<Mi, 'properties'>>, context: Context) => S
137
126
 
138
127
  pageShow?: () => void
139
128
 
140
129
  pageHide?: () => void
141
130
 
142
- externalClasses?: string[]
143
-
144
- lifetimes?: Partial<WechatMiniprogram.Component.Lifetimes>
145
-
146
- pageLifetimes?: Partial<WechatMiniprogram.Component.PageLifetimes>
147
-
148
- relations?: { [key: string]: WechatMiniprogram.Component.RelationOption }
149
-
150
131
  [index: string]: any
151
132
  }
152
133
 
@@ -621,6 +602,28 @@ export function useI18n<Options extends {
621
602
  options?: Options
622
603
  ): UseI18n
623
604
 
605
+ // `<script setup>`
606
+ type NotUndefined<T> = T extends undefined ? never : T
607
+
608
+ type InferDefaults<T> = {
609
+ [K in keyof T]?: InferDefault<T, NotUndefined<T[K]>>
610
+ }
611
+
612
+ type InferDefault<P, T> = T extends
613
+ | null
614
+ | number
615
+ | string
616
+ | boolean
617
+ | symbol
618
+ | Array<any>
619
+ | Object
620
+ ? T | ((props: P) => T)
621
+ : (props: P) => T
622
+
623
+ type PropsWithDefaults<Base, Defaults> = Base & {
624
+ [K in keyof Defaults]: K extends keyof Base ? NotUndefined<Base[K]> : never
625
+ }
626
+
624
627
  // inner lifecycle
625
628
  export const BEFORECREATE: string
626
629
  export const CREATED: string
@@ -640,4 +643,5 @@ declare global {
640
643
  const defineOptions: <D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], S extends AnyObject = {}, O extends AnyObject = {}> (opt: ThisTypedComponentOpt<D, P, C, M, Mi, S, O>) => void
641
644
  const defineExpose: <E extends AnyObject = AnyObject>(exposed?: E) => void
642
645
  const useContext: () => Context
646
+ const withDefaults: <Props, Defaults extends InferDefaults<Props>>(props: Props, defaults: Defaults) => PropsWithDefaults<Props, Defaults>
643
647
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.8.15",
3
+ "version": "2.8.19",
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": "292c54cd571b1cdc3ca7cf9ffa8ab13ed2da6158"
50
+ "gitHead": "fca1b61f52c2ed8b3926e7b8a3a150d27904911a"
51
51
  }
@@ -47,7 +47,7 @@ export default function mergeOptions (options = {}, type, needConvert) {
47
47
 
48
48
  export function getMixin (mixin = {}) {
49
49
  // 用于ts反向推导mixin类型
50
- return mixin.mixins ? extractMixins({}, mixin, true) : mixin
50
+ return mixin
51
51
  }
52
52
 
53
53
  function extractMixins (mergeOptions, options, needConvert) {
@@ -214,7 +214,7 @@ function mergeMixins (parent, child) {
214
214
  mergeHooks(parent, child, key)
215
215
  } else if (/^(data|dataFn)$/.test(key)) {
216
216
  mergeDataFn(parent, child, key)
217
- } else if (/^(computed|properties|props|methods|proto|options|relations)$/.test(key)) {
217
+ } else if (/^(computed|properties|props|methods|proto|options|relations|initData)$/.test(key)) {
218
218
  mergeShallowObj(parent, child, key)
219
219
  } else if (/^(watch|observers|pageLifetimes|events)$/.test(key)) {
220
220
  mergeToArray(parent, child, key)
@@ -318,9 +318,6 @@ function composeHooks (target, includes) {
318
318
  const data = hooksArr[i].apply(this, args)
319
319
  data !== undefined && (result = data)
320
320
  }
321
- if (result === '__abort__') {
322
- break
323
- }
324
321
  }
325
322
  return result
326
323
  })
@@ -24,7 +24,8 @@ export default function transferOptions (options, type, needConvert = true) {
24
24
  }
25
25
  if (currentInject && currentInject.pageEvents) {
26
26
  options.mixins = options.mixins || []
27
- options.mixins.unshift(currentInject.pageEvents)
27
+ // 驱动层视作用户本地逻辑,作为最后的mixin来执行
28
+ options.mixins.push(currentInject.pageEvents)
28
29
  }
29
30
  // 转换mode
30
31
  options.mpxConvertMode = options.mpxConvertMode || getConvertMode(global.currentSrcMode)
@@ -74,8 +74,14 @@ function filterOptions (options, type) {
74
74
  if (builtInKeysMap[key]) {
75
75
  return
76
76
  }
77
- if (key === 'properties' || key === 'props') {
78
- newOptions.props = Object.assign({}, options.props, options.properties)
77
+ if (key === 'data' || key === 'initData') {
78
+ if (!hasOwn(newOptions, 'data')) {
79
+ newOptions.data = Object.assign({}, options.initData, options.data)
80
+ }
81
+ } else if (key === 'properties' || key === 'props') {
82
+ if (!hasOwn(newOptions, 'props')) {
83
+ newOptions.props = Object.assign({}, options.props, options.properties)
84
+ }
79
85
  } else if (key === 'methods' && type === 'page') {
80
86
  Object.assign(newOptions, options[key])
81
87
  } else {
@@ -1,10 +1,10 @@
1
1
  import { INNER_LIFECYCLES } from '../../core/innerLifecycle'
2
2
  import { makeMap } from '@mpxjs/utils'
3
3
 
4
- let bulitInKeys
4
+ let builtInKeys
5
5
 
6
6
  if (__mpx_mode__ === 'web') {
7
- bulitInKeys = [
7
+ builtInKeys = [
8
8
  'proto',
9
9
  'mixins',
10
10
  'mpxCustomKeysForBlend',
@@ -15,7 +15,7 @@ if (__mpx_mode__ === 'web') {
15
15
  '__pageCtor__'
16
16
  ]
17
17
  } else {
18
- bulitInKeys = [
18
+ builtInKeys = [
19
19
  'setup',
20
20
  'dataFn',
21
21
  'proto',
@@ -31,4 +31,4 @@ if (__mpx_mode__ === 'web') {
31
31
  ]
32
32
  }
33
33
 
34
- export default makeMap(bulitInKeys.concat(INNER_LIFECYCLES))
34
+ export default makeMap(builtInKeys.concat(INNER_LIFECYCLES))
@@ -1,6 +1,6 @@
1
1
  import builtInKeysMap from '../builtInKeysMap'
2
2
  import mergeOptions from '../../../core/mergeOptions'
3
- import { diffAndCloneA } from '@mpxjs/utils'
3
+ import { diffAndCloneA, hasOwn } from '@mpxjs/utils'
4
4
  import { getCurrentInstance as getCurrentVueInstance } from '../../export/index'
5
5
  import MpxProxy, { setCurrentInstance, unsetCurrentInstance } from '../../../core/proxy'
6
6
  import { BEFOREUPDATE, UPDATED, BEFOREUNMOUNT, UNMOUNTED } from '../../../core/innerLifecycle'
@@ -12,11 +12,13 @@ function filterOptions (options) {
12
12
  return
13
13
  }
14
14
  if (key === 'data' || key === 'dataFn') {
15
- newOptions.data = function mergeFn () {
16
- return Object.assign(
17
- diffAndCloneA(options.data || {}).clone,
18
- options.dataFn && options.dataFn.call(this)
19
- )
15
+ if (!hasOwn(newOptions, 'data')) {
16
+ newOptions.data = function mergeFn () {
17
+ return Object.assign(
18
+ diffAndCloneA(options.data || {}).clone,
19
+ options.dataFn && options.dataFn.call(this)
20
+ )
21
+ }
20
22
  }
21
23
  } else {
22
24
  newOptions[key] = options[key]
@@ -112,8 +112,14 @@ export function filterOptions (options) {
112
112
  if (builtInKeysMap[key]) {
113
113
  return
114
114
  }
115
- if (key === 'properties' || key === 'props') {
116
- newOptions.properties = transformProperties(Object.assign({}, options.properties, options.props))
115
+ if (key === 'data' || key === 'initData') {
116
+ if (!hasOwn(newOptions, 'data')) {
117
+ newOptions.data = Object.assign({}, options.initData, options.data)
118
+ }
119
+ } else if (key === 'properties' || key === 'props') {
120
+ if (!hasOwn(newOptions, 'properties')) {
121
+ newOptions.properties = transformProperties(Object.assign({}, options.props, options.properties))
122
+ }
117
123
  } else if (key === 'methods' && options.__pageCtor__) {
118
124
  // 构造器为Page时抽取所有methods方法到顶层
119
125
  Object.assign(newOptions, options[key])