@mpxjs/core 2.7.52 → 2.8.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/@types/index.d.ts +342 -27
- package/package.json +10 -5
- package/src/convertor/convertor.js +2 -2
- package/src/convertor/mergeLifecycle.js +4 -4
- package/src/convertor/wxToAli.js +3 -4
- package/src/convertor/wxToSwan.js +2 -2
- package/src/convertor/wxToTt.js +1 -10
- package/src/convertor/wxToWeb.js +14 -7
- package/src/core/implement.js +2 -2
- package/src/core/injectMixins.js +1 -1
- package/src/core/innerLifecycle.js +15 -2
- package/src/core/mergeOptions.js +11 -5
- package/src/core/proxy.js +343 -229
- package/src/core/transferOptions.js +5 -2
- package/src/helper/const.js +10 -0
- package/src/index.js +73 -147
- package/src/observer/array.js +12 -17
- package/src/observer/computed.js +27 -56
- package/src/observer/dep.js +1 -1
- package/src/observer/effect.js +113 -0
- package/src/observer/effectScope.js +109 -0
- package/src/observer/{index.js → reactive.js} +74 -70
- package/src/observer/ref.js +97 -0
- package/src/observer/scheduler.js +171 -56
- package/src/observer/watch.js +163 -39
- package/src/platform/builtInMixins/i18nMixin.js +238 -31
- package/src/platform/builtInMixins/pageScrollMixin.web.js +4 -5
- package/src/platform/builtInMixins/pageStatusMixin.js +76 -54
- package/src/platform/builtInMixins/pageStatusMixin.web.js +35 -22
- package/src/platform/builtInMixins/proxyEventMixin.js +40 -22
- package/src/platform/builtInMixins/proxyEventMixin.web.js +16 -24
- package/src/platform/builtInMixins/refsMixin.js +82 -73
- package/src/platform/builtInMixins/refsMixin.web.js +0 -47
- package/src/platform/builtInMixins/relationsMixin.js +10 -9
- package/src/platform/builtInMixins/renderHelperMixin.js +1 -1
- package/src/platform/builtInMixins/showMixin.js +1 -1
- package/src/platform/createApp.js +5 -5
- package/src/platform/export/api.js +23 -0
- package/src/platform/export/api.web.js +26 -0
- package/src/platform/export/index.js +45 -0
- package/src/platform/export/index.web.js +36 -0
- package/src/platform/index.js +1 -5
- package/src/platform/patch/ali/getDefaultOptions.js +33 -31
- package/src/platform/patch/ali/lifecycle.js +21 -13
- package/src/platform/patch/builtInKeysMap.js +2 -1
- package/src/platform/patch/index.js +4 -9
- package/src/platform/patch/swan/getDefaultOptions.js +3 -3
- package/src/platform/patch/swan/lifecycle.js +17 -14
- package/src/platform/patch/web/getDefaultOptions.js +40 -16
- package/src/platform/patch/web/lifecycle.js +6 -3
- package/src/platform/patch/wx/getDefaultOptions.js +38 -31
- package/src/platform/patch/wx/lifecycle.js +18 -11
- package/src/runtime/createFactory.js +6 -2
- package/src/vue.web.js +3 -0
- package/src/vuePlugin.js +31 -0
- package/src/core/createStore.js +0 -241
- package/src/core/mapStore.js +0 -94
- package/src/helper/env.js +0 -20
- package/src/helper/getByPath.js +0 -127
- package/src/helper/log.js +0 -31
- package/src/helper/utils.js +0 -652
- package/src/observer/watcher.js +0 -244
package/@types/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ import VueI18n from 'vue-i18n'
|
|
|
13
13
|
|
|
14
14
|
declare module 'vue-i18n' {
|
|
15
15
|
export default interface VueI18n {
|
|
16
|
-
mergeMessages(messages: {[index: string]:VueI18n.LocaleMessageObject}): void;
|
|
16
|
+
mergeMessages (messages: { [index: string]: VueI18n.LocaleMessageObject }): void;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
// declare Store types
|
|
@@ -135,7 +135,19 @@ type UnboxMixinField<T extends Mixin<{}, {}, {}, {}>, F> = F extends keyof T ? T
|
|
|
135
135
|
type UnboxMixinsField<Mi extends Array<any>, F> =
|
|
136
136
|
UnionToIntersection<RequiredPropertiesForUnion<UnboxMixinField<ArrayType<Mi>, F>>>
|
|
137
137
|
|
|
138
|
-
interface
|
|
138
|
+
interface Context {
|
|
139
|
+
triggerEvent: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['triggerEvent']
|
|
140
|
+
refs: ObjectOf<WechatMiniprogram.NodesRef & ComponentIns<{}, {}, {}, {}, []>>
|
|
141
|
+
|
|
142
|
+
forceUpdate (params?: object, callback?: () => void): void
|
|
143
|
+
|
|
144
|
+
selectComponent: ReplaceWxComponentIns['selectComponent']
|
|
145
|
+
selectAllComponents: ReplaceWxComponentIns['selectAllComponents']
|
|
146
|
+
createSelectorQuery: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createSelectorQuery']
|
|
147
|
+
createIntersectionObserver: WechatMiniprogram.Component.InstanceMethods<Record<string, any>>['createIntersectionObserver']
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
interface ComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> extends Partial<WechatMiniprogram.Component.Lifetimes> {
|
|
139
151
|
data?: D
|
|
140
152
|
properties?: P
|
|
141
153
|
computed?: C
|
|
@@ -149,6 +161,8 @@ interface ComponentOpt<D, P, C, M, Mi extends Array<any>> extends Partial<Wechat
|
|
|
149
161
|
styleIsolation: string
|
|
150
162
|
}>
|
|
151
163
|
|
|
164
|
+
setup?: (props: GetPropsType<P & UnboxMixinsField<Mi, 'properties'>>, context: Context) => S
|
|
165
|
+
|
|
152
166
|
pageShow?: () => void
|
|
153
167
|
|
|
154
168
|
pageHide?: () => void
|
|
@@ -164,17 +178,17 @@ interface ComponentOpt<D, P, C, M, Mi extends Array<any>> extends Partial<Wechat
|
|
|
164
178
|
[index: string]: any
|
|
165
179
|
}
|
|
166
180
|
|
|
167
|
-
type PageOpt<D, P, C, M, Mi extends Array<any>> =
|
|
168
|
-
ComponentOpt<D, P, C, M, Mi>
|
|
181
|
+
type PageOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> =
|
|
182
|
+
ComponentOpt<D, P, C, M, Mi, S>
|
|
169
183
|
& Partial<WechatMiniprogram.Page.ILifetime>
|
|
170
184
|
|
|
171
|
-
type ThisTypedPageOpt<D, P, C, M, Mi extends Array<any>, O = {}> =
|
|
172
|
-
PageOpt<D, P, C, M, Mi>
|
|
173
|
-
& ThisType<ComponentIns<D, P, C, M, Mi, O>> & O
|
|
185
|
+
type ThisTypedPageOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>, O = {}> =
|
|
186
|
+
PageOpt<D, P, C, M, Mi, S>
|
|
187
|
+
& ThisType<ComponentIns<D, P, C, M, Mi, S, O>> & O
|
|
174
188
|
|
|
175
|
-
type ThisTypedComponentOpt<D, P, C, M, Mi extends Array<any>, O = {}> =
|
|
176
|
-
ComponentOpt<D, P, C, M, Mi>
|
|
177
|
-
& ThisType<ComponentIns<D, P, C, M, Mi, O>> & O
|
|
189
|
+
type ThisTypedComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>, O = {}> =
|
|
190
|
+
ComponentOpt<D, P, C, M, Mi, S>
|
|
191
|
+
& ThisType<ComponentIns<D, P, C, M, Mi, S, O>> & O
|
|
178
192
|
|
|
179
193
|
type I18nValues = {
|
|
180
194
|
[k: string]: string
|
|
@@ -182,9 +196,9 @@ type I18nValues = {
|
|
|
182
196
|
|
|
183
197
|
declare function get (obj: object, key: string): any
|
|
184
198
|
|
|
185
|
-
declare function set (obj: object, key: string, value: any): any
|
|
199
|
+
// declare function set (obj: object, key: string, value: any): any
|
|
186
200
|
|
|
187
|
-
declare function del (obj: object, key: string): any
|
|
201
|
+
// declare function del (obj: object, key: string): any
|
|
188
202
|
|
|
189
203
|
declare function t (key: string, values?: I18nValues): string
|
|
190
204
|
|
|
@@ -192,6 +206,8 @@ declare function tc (key: string, choice: number, values?: I18nValues): string
|
|
|
192
206
|
|
|
193
207
|
declare function te (key: string): boolean
|
|
194
208
|
|
|
209
|
+
declare function tm (key: string): any
|
|
210
|
+
|
|
195
211
|
export function observable<T extends object> (obj: T): T
|
|
196
212
|
|
|
197
213
|
type MpxComProps<O> = { $rawOptions: O }
|
|
@@ -212,16 +228,14 @@ export interface MpxComponentIns {
|
|
|
212
228
|
|
|
213
229
|
$nextTick (fn: () => void): void
|
|
214
230
|
|
|
215
|
-
$i18n: {
|
|
216
|
-
locale: string
|
|
217
|
-
}
|
|
218
|
-
|
|
219
231
|
$t: typeof t
|
|
220
232
|
|
|
221
233
|
$tc: typeof tc
|
|
222
234
|
|
|
223
235
|
$te: typeof te
|
|
224
236
|
|
|
237
|
+
$tm: typeof tm
|
|
238
|
+
|
|
225
239
|
[k: string]: any
|
|
226
240
|
}
|
|
227
241
|
|
|
@@ -236,9 +250,9 @@ type WxComponentIns<D> =
|
|
|
236
250
|
& WechatMiniprogram.Component.InstanceProperties
|
|
237
251
|
& WechatMiniprogram.Component.InstanceMethods<D>
|
|
238
252
|
|
|
239
|
-
type ComponentIns<D, P, C, M, Mi extends Array<any>, O = {}> =
|
|
253
|
+
type ComponentIns<D, P, C, M, Mi extends Array<any>, S extends Record<any, any> = {}, O = {}> =
|
|
240
254
|
GetDataType<D> & UnboxMixinsField<Mi, 'data'> &
|
|
241
|
-
M & UnboxMixinsField<Mi, 'methods'> &
|
|
255
|
+
M & UnboxMixinsField<Mi, 'methods'> & { [K in keyof S]: S[K] extends Ref<infer V> ? V : S[K] } &
|
|
242
256
|
GetPropsType<P & UnboxMixinsField<Mi, 'properties'>> &
|
|
243
257
|
GetComputedType<C & UnboxMixinsField<Mi, 'computed'>> &
|
|
244
258
|
WxComponentIns<D> & MpxComponentIns & MpxComProps<O>
|
|
@@ -297,7 +311,7 @@ type MixinType = 'app' | 'page' | 'component'
|
|
|
297
311
|
|
|
298
312
|
export function injectMixins (mixins: object | Array<object>, options?: MixinType | MixinType[] | { types?: MixinType | MixinType[], stage?: number }): void
|
|
299
313
|
|
|
300
|
-
export function watch (expr: string | (() => any), handler: WatchHandler | WatchOptWithHandler, options?: WatchOpt): () => void
|
|
314
|
+
// export function watch (expr: string | (() => any), handler: WatchHandler | WatchOptWithHandler, options?: WatchOpt): () => void
|
|
301
315
|
|
|
302
316
|
interface AnyConstructor {
|
|
303
317
|
new (...args: any[]): any
|
|
@@ -339,7 +353,7 @@ export interface Mpx {
|
|
|
339
353
|
toPureObject: typeof toPureObject
|
|
340
354
|
observable: typeof observable
|
|
341
355
|
|
|
342
|
-
watch: typeof watch
|
|
356
|
+
// watch: typeof watch
|
|
343
357
|
|
|
344
358
|
use (plugin: ((...args: any) => any) | { install: (...args: any) => any, [key: string]: any }, ...rest: any): Mpx
|
|
345
359
|
|
|
@@ -354,13 +368,8 @@ export interface Mpx {
|
|
|
354
368
|
config: MpxConfig
|
|
355
369
|
|
|
356
370
|
i18n: {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
t: typeof t
|
|
360
|
-
tc: typeof tc
|
|
361
|
-
te: typeof te
|
|
362
|
-
mergeMessages (messages: object): void
|
|
363
|
-
mergeLocaleMessage (locale: string, message: object): void
|
|
371
|
+
readonly global: UseI18n
|
|
372
|
+
dispose (): void
|
|
364
373
|
}
|
|
365
374
|
}
|
|
366
375
|
|
|
@@ -371,3 +380,309 @@ type GetFunctionKey<T> = {
|
|
|
371
380
|
declare let mpx: Mpx & Pick<WechatMiniprogram.Wx, GetFunctionKey<WechatMiniprogram.Wx>>
|
|
372
381
|
|
|
373
382
|
export default mpx
|
|
383
|
+
|
|
384
|
+
// composition api
|
|
385
|
+
|
|
386
|
+
declare const RefSymbol: unique symbol
|
|
387
|
+
declare const ReactiveSymbol: unique symbol
|
|
388
|
+
declare const ComputedRefSymbol: unique symbol
|
|
389
|
+
declare const ShallowRefMarker: unique symbol
|
|
390
|
+
declare const ShallowReactiveMarker: unique symbol
|
|
391
|
+
|
|
392
|
+
export interface Ref<T = any> {
|
|
393
|
+
value: T
|
|
394
|
+
/**
|
|
395
|
+
* Type differentiator only.
|
|
396
|
+
* We need this to be in public d.ts but don't want it to show up in IDE
|
|
397
|
+
* autocomplete, so we use a private Symbol instead.
|
|
398
|
+
*/
|
|
399
|
+
[RefSymbol]: true
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
type CollectionTypes = IterableCollections | WeakCollections
|
|
403
|
+
|
|
404
|
+
type IterableCollections = Map<any, any> | Set<any>
|
|
405
|
+
type WeakCollections = WeakMap<any, any> | WeakSet<any>
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* This is a special exported interface for other packages to declare
|
|
409
|
+
* additional types that should bail out for ref unwrapping. For example
|
|
410
|
+
*
|
|
411
|
+
* ``` ts
|
|
412
|
+
* declare module '@mpxjs/core' {
|
|
413
|
+
* export interface RefUnwrapBailTypes {
|
|
414
|
+
* runtimeDOMBailTypes: Node | Window
|
|
415
|
+
* }
|
|
416
|
+
* }
|
|
417
|
+
* ```
|
|
418
|
+
*
|
|
419
|
+
* Note that api-extractor somehow refuses to include `declare module`
|
|
420
|
+
* augmentations in its generated d.ts, so we have to manually append them
|
|
421
|
+
* to the final generated d.ts in our build process.
|
|
422
|
+
*/
|
|
423
|
+
export interface RefUnwrapBailTypes {
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
export type UnwrapRef<T> = T extends ShallowRef<infer V>
|
|
427
|
+
? V
|
|
428
|
+
: T extends Ref<infer V>
|
|
429
|
+
? UnwrapRefSimple<V>
|
|
430
|
+
: UnwrapRefSimple<T>
|
|
431
|
+
|
|
432
|
+
export type UnwrapRefSimple<T> = T extends | Function
|
|
433
|
+
| CollectionTypes
|
|
434
|
+
| string | number | boolean
|
|
435
|
+
| Ref
|
|
436
|
+
| RefUnwrapBailTypes[keyof RefUnwrapBailTypes]
|
|
437
|
+
? T
|
|
438
|
+
: T extends Array<any>
|
|
439
|
+
? { [K in keyof T]: UnwrapRefSimple<T[K]> }
|
|
440
|
+
: T extends object & { [ShallowReactiveMarker]?: never } // not a shallowReactive
|
|
441
|
+
? { [P in keyof T]: P extends symbol ? T[P] : UnwrapRef<T[P]> }
|
|
442
|
+
: T
|
|
443
|
+
|
|
444
|
+
// If the the type T accepts type "any", output type Y, otherwise output type N.
|
|
445
|
+
// https://stackoverflow.com/questions/49927523/disallow-call-with-any/49928360#49928360
|
|
446
|
+
export type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N
|
|
447
|
+
export type ToRef<T> = IfAny<T, Ref<T>, [T] extends [Ref] ? T : Ref<T>>
|
|
448
|
+
|
|
449
|
+
export type ToRefs<T = any> = {
|
|
450
|
+
[K in keyof T]: ToRef<T[K]>
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
export type CustomRefFactory<T> = (
|
|
454
|
+
track: () => void,
|
|
455
|
+
trigger: () => void
|
|
456
|
+
) => {
|
|
457
|
+
get: () => T
|
|
458
|
+
set: (value: T) => void
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
export type ShallowRef<T = any> = Ref<T> & { [ShallowRefMarker]?: true }
|
|
462
|
+
|
|
463
|
+
export type ShallowReactive<T> = T & { [ShallowReactiveMarker]?: true }
|
|
464
|
+
|
|
465
|
+
export type UnwrapNestedRefs<T> = T extends Ref ? T : UnwrapRefSimple<T>
|
|
466
|
+
|
|
467
|
+
export type Reactive<T> = UnwrapNestedRefs<T> & { [ReactiveSymbol]: true }
|
|
468
|
+
|
|
469
|
+
export interface WritableComputedOptions<T> {
|
|
470
|
+
get: (...args: any[]) => T
|
|
471
|
+
set: (v: T) => void
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
export interface ComputedRef<T = any> extends WritableComputedRef<T> {
|
|
475
|
+
readonly value: T
|
|
476
|
+
[ComputedRefSymbol]: true
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
export interface WritableComputedRef<T> extends Ref<T> {
|
|
480
|
+
// readonly effect: ReactiveEffect<T>
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
type WatchCallback<T> = (
|
|
484
|
+
value: T,
|
|
485
|
+
oldValue: T,
|
|
486
|
+
onCleanup: (cleanupFn: () => void) => void
|
|
487
|
+
) => void
|
|
488
|
+
|
|
489
|
+
type WatchSource<T> =
|
|
490
|
+
| Ref<T> // ref
|
|
491
|
+
| ComputedRef<T>
|
|
492
|
+
| Reactive<T>
|
|
493
|
+
| (() => T) // getter
|
|
494
|
+
|
|
495
|
+
type MultiWatchSources = (WatchSource<unknown> | object)[]
|
|
496
|
+
|
|
497
|
+
interface WatchEffectOptions {
|
|
498
|
+
flush?: 'pre' | 'post' | 'sync' // default: 'pre'
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
interface WatchOptions extends WatchEffectOptions {
|
|
502
|
+
immediate?: boolean // 默认:false
|
|
503
|
+
deep?: boolean // 默认:false
|
|
504
|
+
flush?: 'pre' | 'post' | 'sync' // 默认:'pre'
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
interface EffectScope {
|
|
508
|
+
run<T> (fn: () => T): T | undefined // 如果作用域不活跃就为 undefined
|
|
509
|
+
stop (): void
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
|
|
513
|
+
type StringObj = {
|
|
514
|
+
[k: string]: string | StringObj
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
interface UseI18n {
|
|
518
|
+
id: number
|
|
519
|
+
locale: string
|
|
520
|
+
fallbackLocale: string
|
|
521
|
+
readonly messages: StringObj
|
|
522
|
+
readonly isGlobal: boolean
|
|
523
|
+
inheritLocale: boolean
|
|
524
|
+
fallbackRoot: boolean
|
|
525
|
+
|
|
526
|
+
t (key: string, values?: I18nValues): string
|
|
527
|
+
|
|
528
|
+
t (key: string, choice: number, values?: I18nValues): string
|
|
529
|
+
|
|
530
|
+
te (key: string): boolean
|
|
531
|
+
|
|
532
|
+
tm (key: string): any
|
|
533
|
+
|
|
534
|
+
getLocaleMessage (locale: string): StringObj
|
|
535
|
+
|
|
536
|
+
setLocaleMessage (locale: string, messages: StringObj): void
|
|
537
|
+
|
|
538
|
+
mergeLocaleMessage (locale: string, messages: StringObj): void
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
export function ref<T extends object> (
|
|
543
|
+
value: T
|
|
544
|
+
): [T] extends [Ref] ? T : Ref<UnwrapRef<T>>
|
|
545
|
+
export function ref<T> (value: T): Ref<UnwrapRef<T>>
|
|
546
|
+
export function ref<T = any> (): Ref<T | undefined>
|
|
547
|
+
|
|
548
|
+
export function unref<T> (ref: T | Ref<T>): T
|
|
549
|
+
|
|
550
|
+
export function toRef<T extends object, K extends keyof T> (object: T, key: K): ToRef<T[K]>
|
|
551
|
+
export function toRef<T extends object, K extends keyof T> (object: T, key: K, defaultValue: T[K]): ToRef<Exclude<T[K], undefined>>
|
|
552
|
+
|
|
553
|
+
export function toRefs<T extends object> (object: T): ToRefs<T>
|
|
554
|
+
|
|
555
|
+
export function isRef<T> (r: Ref<T> | unknown): r is Ref<T>
|
|
556
|
+
export function isRef (r: any): r is Ref
|
|
557
|
+
|
|
558
|
+
export function customRef<T> (factory: CustomRefFactory<T>): Ref<T>
|
|
559
|
+
|
|
560
|
+
export function shallowRef<T extends object> (value: T): T extends Ref ? T : ShallowRef<T>
|
|
561
|
+
export function shallowRef<T> (value: T): ShallowRef<T>
|
|
562
|
+
export function shallowRef<T = any> (): ShallowRef<T | undefined>
|
|
563
|
+
|
|
564
|
+
export function triggerRef (ref: Ref): void
|
|
565
|
+
|
|
566
|
+
export function reactive<T extends object> (target: T): Reactive<T>
|
|
567
|
+
|
|
568
|
+
export function isReactive (value: unknown): boolean
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Return a shallowly-reactive copy of the original object, where only the root
|
|
572
|
+
* level properties are reactive. It also does not auto-unwrap refs (even at the
|
|
573
|
+
* root level).
|
|
574
|
+
*/
|
|
575
|
+
export function shallowReactive<T extends object> (target: T): ShallowReactive<T>
|
|
576
|
+
|
|
577
|
+
export function computed<T> (
|
|
578
|
+
getter: (...args: any[]) => T
|
|
579
|
+
): ComputedRef<T>
|
|
580
|
+
export function computed<T> (
|
|
581
|
+
options: WritableComputedOptions<T>
|
|
582
|
+
): WritableComputedRef<T>
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
export function watchEffect (
|
|
586
|
+
effect: (onCleanup: (cleanupFn: () => void) => void) => void,
|
|
587
|
+
options?: WatchEffectOptions
|
|
588
|
+
): () => void
|
|
589
|
+
|
|
590
|
+
export function watchSyncEffect (
|
|
591
|
+
effect: (onCleanup: (cleanupFn: () => void) => void) => void,
|
|
592
|
+
options?: WatchEffectOptions
|
|
593
|
+
): void
|
|
594
|
+
|
|
595
|
+
export function watchPostEffect (
|
|
596
|
+
effect: (onCleanup: (cleanupFn: () => void) => void) => void,
|
|
597
|
+
options?: WatchEffectOptions
|
|
598
|
+
): void
|
|
599
|
+
|
|
600
|
+
export function watch<T extends MultiWatchSources> (
|
|
601
|
+
sources: [...T],
|
|
602
|
+
callback: WatchCallback<T>,
|
|
603
|
+
options?: WatchOptions
|
|
604
|
+
): () => void
|
|
605
|
+
export function watch<T extends Readonly<MultiWatchSources>> (
|
|
606
|
+
sources: T,
|
|
607
|
+
callback: WatchCallback<T>,
|
|
608
|
+
options?: WatchOptions
|
|
609
|
+
): () => void
|
|
610
|
+
export function watch<T> ( // for single watcher
|
|
611
|
+
source: WatchSource<T>,
|
|
612
|
+
callback: WatchCallback<T>,
|
|
613
|
+
options?: WatchOptions
|
|
614
|
+
): () => void
|
|
615
|
+
export function watch<T extends Reactive<object>> ( // for reactive value
|
|
616
|
+
source: T,
|
|
617
|
+
callback: WatchCallback<T>,
|
|
618
|
+
options?: WatchOptions
|
|
619
|
+
): () => void
|
|
620
|
+
|
|
621
|
+
export function effectScope (detached?: boolean): EffectScope
|
|
622
|
+
|
|
623
|
+
export function getCurrentScope (): EffectScope | undefined
|
|
624
|
+
|
|
625
|
+
export function onScopeDispose (fn: () => void): void
|
|
626
|
+
|
|
627
|
+
export function set<T extends object> (target: T, key: string | number, value: any): void
|
|
628
|
+
|
|
629
|
+
export function del<T extends object> (target: T, key: keyof T): void
|
|
630
|
+
|
|
631
|
+
// nextTick
|
|
632
|
+
export function nextTick (fn: () => any): void
|
|
633
|
+
|
|
634
|
+
// lifecycle
|
|
635
|
+
export function onBeforeMount (callback: () => void): void
|
|
636
|
+
|
|
637
|
+
export function onMounted (callback: () => void): void
|
|
638
|
+
|
|
639
|
+
export function onBeforeUpdate (callback: () => void): void
|
|
640
|
+
|
|
641
|
+
export function onUpdated (callback: () => void): void
|
|
642
|
+
|
|
643
|
+
export function onBeforeUnmount (callback: () => void): void
|
|
644
|
+
|
|
645
|
+
export function onUnmounted (callback: () => void): void
|
|
646
|
+
|
|
647
|
+
export function onLoad<T extends object> (callback: (query: T) => void): void
|
|
648
|
+
|
|
649
|
+
export function onShow (callback: () => void): void
|
|
650
|
+
|
|
651
|
+
export function onHide (callback: () => void): void
|
|
652
|
+
|
|
653
|
+
export function onResize (callback: () => void): void
|
|
654
|
+
|
|
655
|
+
// get instance
|
|
656
|
+
export function getCurrentInstance<T extends object> (): { target: T }
|
|
657
|
+
|
|
658
|
+
// I18n
|
|
659
|
+
export function useI18n<Options extends {
|
|
660
|
+
inheritLocale?: boolean
|
|
661
|
+
fallbackRoot?: boolean
|
|
662
|
+
locale?: string
|
|
663
|
+
fallbackLocale?: string
|
|
664
|
+
messages: StringObj
|
|
665
|
+
}> (
|
|
666
|
+
options?: Options
|
|
667
|
+
): UseI18n
|
|
668
|
+
|
|
669
|
+
// inner lifecycle
|
|
670
|
+
export const BEFORECREATE: string
|
|
671
|
+
export const CREATED: string
|
|
672
|
+
export const BEFOREMOUNT: string
|
|
673
|
+
export const MOUNTED: string
|
|
674
|
+
export const BEFOREUPDATE: string
|
|
675
|
+
export const UPDATED: string
|
|
676
|
+
export const BEFOREUNMOUNT: string
|
|
677
|
+
export const UNMOUNTED: string
|
|
678
|
+
export const ONLOAD: string
|
|
679
|
+
export const ONSHOW: string
|
|
680
|
+
export const ONHIDE: string
|
|
681
|
+
export const ONRESIZE: string
|
|
682
|
+
|
|
683
|
+
declare global {
|
|
684
|
+
const defineProps: <T>(props: T) => Readonly<GetPropsType<T>>
|
|
685
|
+
const defineOptions: <D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], O = {}> (opt: ThisTypedComponentOpt<D, P, C, M, Mi, O>) => void
|
|
686
|
+
const defineExpose: <E extends Record<string, any> = Record<string, any>>(exposed?: E) => void
|
|
687
|
+
const useContext: () => Context
|
|
688
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0-beta.2",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -19,16 +19,21 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/index.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@mpxjs/utils": "^2.8.0-beta.2",
|
|
22
23
|
"lodash": "^4.1.1",
|
|
23
24
|
"miniprogram-api-typings": "^3.0.2"
|
|
24
25
|
},
|
|
25
26
|
"peerDependencies": {
|
|
26
27
|
"@mpxjs/api-proxy": "^2.7.44",
|
|
27
|
-
"
|
|
28
|
-
"vue
|
|
28
|
+
"@mpxjs/store": "^2.8.0",
|
|
29
|
+
"vue": "^2.7.10",
|
|
30
|
+
"vue-demi": "^0.13.11",
|
|
31
|
+
"vue-i18n": "^8.27.2",
|
|
32
|
+
"vue-i18n-bridge": "^9.2.2"
|
|
29
33
|
},
|
|
30
34
|
"publishConfig": {
|
|
31
|
-
"registry": "https://registry.npmjs.org"
|
|
35
|
+
"registry": "https://registry.npmjs.org",
|
|
36
|
+
"access": "public"
|
|
32
37
|
},
|
|
33
38
|
"scripts": {
|
|
34
39
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
@@ -42,5 +47,5 @@
|
|
|
42
47
|
"url": "https://github.com/didi/mpx/issues"
|
|
43
48
|
},
|
|
44
49
|
"sideEffects": false,
|
|
45
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "cd57f83a9d47236f527bd51a8650119514f4b433"
|
|
46
51
|
}
|
|
@@ -3,7 +3,7 @@ import * as aliLifecycle from '../platform/patch/ali/lifecycle'
|
|
|
3
3
|
import * as webLifecycle from '../platform/patch/web/lifecycle'
|
|
4
4
|
import * as swanLifecycle from '../platform/patch/swan/lifecycle'
|
|
5
5
|
import { mergeLifecycle } from './mergeLifecycle'
|
|
6
|
-
import { error } from '
|
|
6
|
+
import { error } from '@mpxjs/utils'
|
|
7
7
|
import wxToAliRule from './wxToAli'
|
|
8
8
|
import wxToWebRule from './wxToWeb'
|
|
9
9
|
import wxToSwanRule from './wxToSwan'
|
|
@@ -59,7 +59,7 @@ const rulesMap = {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export function getConvertRule (convertMode) {
|
|
62
|
-
|
|
62
|
+
const rule = rulesMap[convertMode]
|
|
63
63
|
if (!rule || !rule.lifecycle) {
|
|
64
64
|
error(`Absence of convert rule for ${convertMode}, please check.`)
|
|
65
65
|
} else {
|
|
@@ -6,10 +6,10 @@ export function mergeLifecycle (lifecycle) {
|
|
|
6
6
|
const pageHooks = (lifecycle.PAGE_HOOKS || []).concat(INNER_LIFECYCLES)
|
|
7
7
|
const componentHooks = (lifecycle.COMPONENT_HOOKS || []).concat(INNER_LIFECYCLES)
|
|
8
8
|
return {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
app: appHooks,
|
|
10
|
+
page: pageHooks,
|
|
11
|
+
component: componentHooks,
|
|
12
|
+
blend: pageHooks.concat(lifecycle.COMPONENT_HOOKS || [])
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
}
|
package/src/convertor/wxToAli.js
CHANGED
|
@@ -2,9 +2,8 @@ import * as wxLifecycle from '../platform/patch/wx/lifecycle'
|
|
|
2
2
|
import * as aliLifecycle from '../platform/patch/ali/lifecycle'
|
|
3
3
|
import { mergeLifecycle } from './mergeLifecycle'
|
|
4
4
|
import { mergeToArray } from '../core/mergeOptions'
|
|
5
|
-
import { error } from '
|
|
5
|
+
import { error, hasOwn, isDev } from '@mpxjs/utils'
|
|
6
6
|
import { implemented } from '../core/implement'
|
|
7
|
-
import { hasOwn } from '../helper/utils'
|
|
8
7
|
|
|
9
8
|
const unsupported = ['moved', 'definitionFilter']
|
|
10
9
|
|
|
@@ -16,7 +15,7 @@ function notSupportTip (options) {
|
|
|
16
15
|
unsupported.forEach(key => {
|
|
17
16
|
if (options[key]) {
|
|
18
17
|
if (!implemented[key]) {
|
|
19
|
-
|
|
18
|
+
isDev && convertErrorDesc(key)
|
|
20
19
|
delete options[key]
|
|
21
20
|
} else if (implemented[key].remove) {
|
|
22
21
|
delete options[key]
|
|
@@ -24,7 +23,7 @@ function notSupportTip (options) {
|
|
|
24
23
|
}
|
|
25
24
|
})
|
|
26
25
|
// relations部分支持
|
|
27
|
-
const relations = options
|
|
26
|
+
const relations = options.relations
|
|
28
27
|
if (relations) {
|
|
29
28
|
Object.keys(relations).forEach(path => {
|
|
30
29
|
const item = relations[path]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { error } from '
|
|
1
|
+
import { error, isDev } from '@mpxjs/utils'
|
|
2
2
|
import { implemented } from '../core/implement'
|
|
3
3
|
import { mergeLifecycle } from './mergeLifecycle'
|
|
4
4
|
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
|
|
@@ -19,7 +19,7 @@ function notSupportTip (options) {
|
|
|
19
19
|
unsupported.forEach(key => {
|
|
20
20
|
if (options[key]) {
|
|
21
21
|
if (!implemented[key]) {
|
|
22
|
-
|
|
22
|
+
isDev && convertErrorDesc(key)
|
|
23
23
|
delete options[key]
|
|
24
24
|
} else if (implemented[key].remove) {
|
|
25
25
|
delete options[key]
|
package/src/convertor/wxToTt.js
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
import { error } from '../helper/log'
|
|
2
|
-
|
|
3
1
|
export default {
|
|
4
2
|
convert (options) {
|
|
5
|
-
|
|
6
|
-
options.behaviors.forEach((behavior, idx) => {
|
|
7
|
-
if (typeof behavior === 'string') {
|
|
8
|
-
error(`Built-in behavior "${behavior}" is not supported in tt environment!`, global.currentResource)
|
|
9
|
-
options.behaviors.splice(idx, 1)
|
|
10
|
-
}
|
|
11
|
-
})
|
|
12
|
-
}
|
|
3
|
+
// 暂时无需转换
|
|
13
4
|
}
|
|
14
5
|
}
|
package/src/convertor/wxToWeb.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
|
|
2
2
|
import * as webLifecycle from '../platform/patch/web/lifecycle'
|
|
3
3
|
import { mergeLifecycle } from './mergeLifecycle'
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
isObject,
|
|
6
|
+
diffAndCloneA,
|
|
7
|
+
error,
|
|
8
|
+
hasOwn,
|
|
9
|
+
isDev
|
|
10
|
+
} from '@mpxjs/utils'
|
|
6
11
|
import { implemented } from '../core/implement'
|
|
7
12
|
|
|
8
13
|
// 暂不支持的wx选项,后期需要各种花式支持
|
|
9
|
-
const unsupported = ['moved', 'definitionFilter', 'onShareAppMessage'
|
|
14
|
+
const unsupported = ['moved', 'definitionFilter', 'onShareAppMessage']
|
|
10
15
|
|
|
11
16
|
function convertErrorDesc (key) {
|
|
12
17
|
error(`Options.${key} is not supported in runtime conversion from wx to web.`, global.currentResource)
|
|
@@ -16,7 +21,7 @@ function notSupportTip (options) {
|
|
|
16
21
|
unsupported.forEach(key => {
|
|
17
22
|
if (options[key]) {
|
|
18
23
|
if (!implemented[key]) {
|
|
19
|
-
|
|
24
|
+
isDev && convertErrorDesc(key)
|
|
20
25
|
delete options[key]
|
|
21
26
|
} else if (implemented[key].remove) {
|
|
22
27
|
delete options[key]
|
|
@@ -46,9 +51,11 @@ export default {
|
|
|
46
51
|
}
|
|
47
52
|
if (hasOwn(prop, 'value')) {
|
|
48
53
|
// vue中对于引用类型数据需要使用函数返回
|
|
49
|
-
newProp.default = isObject(prop.value)
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
newProp.default = isObject(prop.value)
|
|
55
|
+
? function propFn () {
|
|
56
|
+
return diffAndCloneA(prop.value).clone
|
|
57
|
+
}
|
|
58
|
+
: prop.value
|
|
52
59
|
}
|
|
53
60
|
props[key] = newProp
|
|
54
61
|
} else {
|
package/src/core/implement.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { noop } from '
|
|
1
|
+
import { noop } from '@mpxjs/utils'
|
|
2
2
|
|
|
3
3
|
export const implemented = {}
|
|
4
4
|
|
|
5
|
-
export
|
|
5
|
+
export function implement (name, { modes = [], processor = noop(), remove = false } = {}) {
|
|
6
6
|
if (!name) return
|
|
7
7
|
if (modes.indexOf(__mpx_mode__) > -1) {
|
|
8
8
|
processor()
|
package/src/core/injectMixins.js
CHANGED
|
@@ -2,13 +2,26 @@ export const BEFORECREATE = '__beforeCreate__'
|
|
|
2
2
|
export const CREATED = '__created__'
|
|
3
3
|
export const BEFOREMOUNT = '__beforeMount__'
|
|
4
4
|
export const MOUNTED = '__mounted__'
|
|
5
|
+
export const BEFOREUPDATE = '__beforeUpdate__'
|
|
5
6
|
export const UPDATED = '__updated__'
|
|
6
|
-
export const
|
|
7
|
+
export const BEFOREUNMOUNT = '__beforeUnmount__'
|
|
8
|
+
export const UNMOUNTED = '__unmounted__'
|
|
9
|
+
export const ONLOAD = '__onLoad__'
|
|
10
|
+
export const ONSHOW = '__onShow__'
|
|
11
|
+
export const ONHIDE = '__onHide__'
|
|
12
|
+
export const ONRESIZE = '__onResize__'
|
|
13
|
+
|
|
7
14
|
export const INNER_LIFECYCLES = [
|
|
8
15
|
BEFORECREATE,
|
|
9
16
|
CREATED,
|
|
10
17
|
BEFOREMOUNT,
|
|
11
18
|
MOUNTED,
|
|
19
|
+
BEFOREUPDATE,
|
|
12
20
|
UPDATED,
|
|
13
|
-
|
|
21
|
+
BEFOREUNMOUNT,
|
|
22
|
+
UNMOUNTED,
|
|
23
|
+
ONLOAD,
|
|
24
|
+
ONSHOW,
|
|
25
|
+
ONHIDE,
|
|
26
|
+
ONRESIZE
|
|
14
27
|
]
|