@mpxjs/core 2.9.6 → 2.9.10

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
@@ -24,30 +24,33 @@ type UnionToIntersection<U> = (U extends any
24
24
  ? (k: U) => void
25
25
  : never) extends ((k: infer I) => void)
26
26
  ? I
27
- : never;
27
+ : never
28
28
 
29
- type ArrayType<T extends any[]> = T extends Array<infer R> ? R : never;
29
+ type ArrayType<T extends any[]> = T extends Array<infer R> ? R : never
30
30
 
31
31
  // Mpx types
32
32
  type Data = object | (() => object)
33
33
 
34
- export type PropType<T> = T & (
35
- T extends string
34
+ export type PropType<T> = {
35
+ __type: T
36
+ } & (
37
+ T extends String
36
38
  ? StringConstructor
37
- : T extends number
39
+ : T extends number
38
40
  ? NumberConstructor
39
41
  : T extends boolean
40
42
  ? BooleanConstructor
41
43
  : T extends any[]
42
44
  ? ArrayConstructor
43
- : T extends object
45
+ : T extends object
44
46
  ? ObjectConstructor
45
- : never )
47
+ : never
48
+ )
46
49
 
47
50
  type FullPropType<T> = {
48
- type: PropType<T>;
49
- value?: T;
50
- optionalTypes?: PropType<T>[];
51
+ type: PropType<T>
52
+ value?: T
53
+ optionalTypes?: WechatMiniprogram.Component.ShortProperty[]
51
54
  }
52
55
 
53
56
  interface Properties {
@@ -80,27 +83,17 @@ interface WatchField {
80
83
 
81
84
  type GetDataType<T> = T extends () => any ? ReturnType<T> : T
82
85
 
83
- type PropValueType<Def> = Def extends FullPropType<infer T>
84
- ? T
85
- : Def extends PropType<infer T>
86
- ? T
87
- : Def extends {
88
- type: (...args: any[]) => infer T;
89
- optionalType?: ((...args: any[]) => infer T)[];
90
- value?: infer T;
91
- }
92
- ? T
93
- : Def extends (...args: any[]) => infer T
94
- ? T
95
- : any;
96
-
97
- type GetPropsType<T> = {
98
- readonly [K in keyof T]: PropValueType<T[K]>
86
+ type GetPropsType<T extends Properties> = {
87
+ readonly [K in keyof T]: T[K] extends FullPropType<infer V>
88
+ ? V
89
+ : T[K] extends PropType<infer V>
90
+ ? V
91
+ : WechatMiniprogram.Component.PropertyToData<T[K]>
99
92
  }
100
93
 
101
94
  type RequiredPropertyNames<T> = {
102
95
  [K in keyof T]-?: T[K] extends undefined ? never : K
103
- }[keyof T];
96
+ }[keyof T]
104
97
 
105
98
  type RequiredPropertiesForUnion<T> = T extends object ? Pick<T, RequiredPropertyNames<T>> : never
106
99
 
@@ -131,7 +124,7 @@ interface Context {
131
124
  createIntersectionObserver: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createIntersectionObserver']
132
125
  }
133
126
 
134
- interface ComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> extends Partial<WechatMiniprogram.Component.Lifetimes & WechatMiniprogram.Component.OtherOption> {
127
+ interface ComponentOpt<D extends Data, P extends Properties, C, M extends Methods, Mi extends Array<any>, S extends Record<any, any>> extends Partial<WechatMiniprogram.Component.Lifetimes & WechatMiniprogram.Component.OtherOption> {
135
128
  data?: D
136
129
  properties?: P
137
130
  computed?: C
@@ -149,7 +142,7 @@ interface ComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any,
149
142
  [index: string]: any
150
143
  }
151
144
 
152
- type PageOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> =
145
+ type PageOpt<D extends Data, P extends Properties, C, M extends Methods, Mi extends Array<any>, S extends Record<any, any>> =
153
146
  ComponentOpt<D, P, C, M, Mi, S>
154
147
  & Partial<WechatMiniprogram.Page.ILifetime>
155
148
 
@@ -286,11 +279,15 @@ interface ImplementOptions {
286
279
 
287
280
  export function toPureObject<T extends object> (obj: T): T
288
281
 
289
- declare type PluginInstallFunction = (app: Mpx, ...options: any[]) => any;
282
+ declare type PluginInstallFunction = (app: Mpx, ...options: any[]) => any
290
283
 
291
284
  export type Plugin = PluginInstallFunction | {
292
- install: PluginInstallFunction;
293
- };
285
+ install: PluginInstallFunction
286
+ }
287
+
288
+ export type PluginFunction<T extends Plugin> = T extends PluginInstallFunction ? T : T extends { install: infer U } ? U : never;
289
+
290
+ export type PluginFunctionParams<T extends PluginInstallFunction> = T extends (app: any, ...args: infer P) => any ? P : [];
294
291
 
295
292
  export interface Mpx {
296
293
  getMixin: typeof getMixin
@@ -300,7 +297,7 @@ export interface Mpx {
300
297
  observable: typeof observable
301
298
  watch: typeof watch
302
299
 
303
- use (plugin: Plugin, ...rest: any[]): Mpx
300
+ use <T extends Plugin = Plugin>(plugin: T, ...rest: PluginFunctionParams<PluginFunction<T>>): Mpx
304
301
 
305
302
  implement (name: string, options?: ImplementOptions): void
306
303
 
@@ -322,6 +319,8 @@ export interface Mpx {
322
319
  te: typeof te
323
320
  tm: typeof tm
324
321
  }
322
+
323
+ __vue: any
325
324
  }
326
325
 
327
326
  type GetFunctionKey<T> = {
@@ -675,7 +674,7 @@ export const ONHIDE: string
675
674
  export const ONRESIZE: string
676
675
 
677
676
  declare global {
678
- const defineProps: (<T>(props: T) => Readonly<GetPropsType<T>>) & (<T>() => Readonly<T>)
677
+ const defineProps: (<T extends Properties = {}>(props: T) => Readonly<GetPropsType<T>>) & (<T>() => Readonly<T>)
679
678
  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
680
679
  const defineExpose: <E extends AnyObject = AnyObject>(exposed?: E) => void
681
680
  const useContext: () => Context
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.9.6",
3
+ "version": "2.9.10",
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": "9034343edacc95da66b6e8ddb5c2f64a4be97231"
50
+ "gitHead": "d2e853a8246e8f9c37f8439c9e276bde22c3ba38"
51
51
  }
@@ -69,10 +69,11 @@ export function queueJob (job) {
69
69
  // if the job is a watch() callback, the search will start with a +1 index to
70
70
  // allow it recursively trigger itself - it is the user's responsibility to
71
71
  // ensure it doesn't end up in an infinite loop.
72
- if ((!queue.length ||
73
- !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)) &&
74
- job !== currentPreFlushParentJob
75
- ) {
72
+ if ((
73
+ !queue.length ||
74
+ !queue.includes(job, isFlushing && job.allowRecurse ? flushIndex + 1 : flushIndex)
75
+ ) &&
76
+ job !== currentPreFlushParentJob) {
76
77
  if (job.id == null) {
77
78
  queue.push(job)
78
79
  } else {
@@ -93,11 +94,17 @@ function queueFlush () {
93
94
  }
94
95
  }
95
96
 
97
+ // todo follow vue
96
98
  export function flushPreFlushCbs (seen, parentJob = null) {
97
99
  if (pendingPreFlushCbs.length) {
98
- currentPreFlushParentJob = parentJob
99
- activePreFlushCbs = [...new Set(pendingPreFlushCbs)]
100
+ const deduped = [...new Set(pendingPreFlushCbs)]
100
101
  pendingPreFlushCbs.length = 0
102
+ if (activePreFlushCbs) {
103
+ activePreFlushCbs.push(...deduped)
104
+ return
105
+ }
106
+ currentPreFlushParentJob = parentJob
107
+ activePreFlushCbs = deduped
101
108
  if (isDev) seen = seen || new Map()
102
109
  for (
103
110
  preFlushIndex = 0;
@@ -117,10 +124,14 @@ export function flushPreFlushCbs (seen, parentJob = null) {
117
124
 
118
125
  export function flushPostFlushCbs (seen) {
119
126
  if (pendingPostFlushCbs.length) {
120
- activePostFlushCbs = [...new Set(pendingPostFlushCbs)]
127
+ const deduped = [...new Set(pendingPostFlushCbs)]
121
128
  pendingPostFlushCbs.length = 0
129
+ if (activePostFlushCbs) {
130
+ activePostFlushCbs.push(...deduped)
131
+ return
132
+ }
133
+ activePostFlushCbs = deduped
122
134
  if (isDev) seen = seen || new Map()
123
-
124
135
  // activePostFlushCbs.sort((a, b) => getId(a) - getId(b))
125
136
  for (
126
137
  postFlushIndex = 0;