@mpxjs/core 2.8.0-beta.3 → 2.8.0-beta.4
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 +27 -78
- package/LICENSE +433 -0
- package/package.json +3 -3
- package/src/core/implement.js +1 -1
- package/src/core/proxy.js +2 -0
- package/src/observer/array.js +1 -1
- package/src/platform/builtInMixins/pageStatusMixin.web.js +2 -1
- package/src/platform/builtInMixins/refsMixin.js +2 -1
- package/src/platform/createApp.js +2 -1
- package/src/platform/export/index.web.js +29 -5
- package/src/platform/patch/builtInKeysMap.js +1 -1
- package/src/platform/patch/web/getDefaultOptions.js +2 -2
- package/@types/mpx-store.d.ts +0 -333
- package/src/.DS_Store +0 -0
package/@types/index.d.ts
CHANGED
|
@@ -4,48 +4,29 @@
|
|
|
4
4
|
// TypeScript Version: 4.1.3
|
|
5
5
|
|
|
6
6
|
/// <reference types="miniprogram-api-typings" />
|
|
7
|
-
/// <reference path="./mpx-store.d.ts" />
|
|
8
7
|
/// <reference path="./global.d.ts" />
|
|
9
8
|
/// <reference path="./node.d.ts" />
|
|
10
9
|
|
|
11
10
|
// @ts-ignore
|
|
12
11
|
import VueI18n from 'vue-i18n'
|
|
13
12
|
|
|
13
|
+
import type { GetComputedType } from '@mpxjs/store'
|
|
14
|
+
|
|
15
|
+
export * from '@mpxjs/store'
|
|
16
|
+
|
|
14
17
|
declare module 'vue-i18n' {
|
|
15
18
|
export default interface VueI18n {
|
|
16
19
|
mergeMessages (messages: { [index: string]: VueI18n.LocaleMessageObject }): void;
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
|
-
// declare Store types
|
|
20
|
-
type StoreOpt<S, G, M, A, D extends MpxStore.Deps> = MpxStore.StoreOpt<S, G, M, A, D>
|
|
21
|
-
|
|
22
|
-
type Store<S = {}, G = {}, M = {}, A = {}, D extends Deps = {}> = MpxStore.Store<S, G, M, A, D>
|
|
23
|
-
|
|
24
|
-
type StoreOptWithThis<S, G, M, A, D extends Deps> = MpxStore.StoreOptWithThis<S, G, M, A, D>
|
|
25
|
-
|
|
26
|
-
type StoreWithThis<S = {}, G = {}, M = {}, A = {}, D extends Deps = {}> = MpxStore.StoreWithThis<S, G, M, A, D>
|
|
27
|
-
|
|
28
|
-
type UnboxDepsField<D extends Deps, F> = MpxStore.UnboxDepsField<D, F>
|
|
29
|
-
|
|
30
|
-
type GetComputedType<T> = MpxStore.GetComputedType<T>
|
|
31
|
-
|
|
32
|
-
type GetDispatchAndCommitWithThis<A, D extends Deps, AK extends 'actions' | 'mutations'> = MpxStore.GetDispatchAndCommitWithThis<A, D, AK>
|
|
33
|
-
|
|
34
|
-
type MutationsAndActionsWithThis = MpxStore.MutationsAndActionsWithThis
|
|
35
|
-
|
|
36
|
-
type Actions<S, G extends MpxStore.Getters<S>> = MpxStore.Actions<S, G>
|
|
37
|
-
|
|
38
|
-
type Mutations<S> = MpxStore.Mutations<S>
|
|
39
|
-
|
|
40
|
-
type Getters<S> = MpxStore.Getters<S>
|
|
41
|
-
|
|
42
|
-
type Deps = MpxStore.Deps
|
|
43
22
|
|
|
44
23
|
// utils
|
|
45
24
|
type ObjectOf<T> = {
|
|
46
25
|
[key: string]: T
|
|
47
26
|
}
|
|
48
27
|
|
|
28
|
+
type AnyObject = ObjectOf<any>
|
|
29
|
+
|
|
49
30
|
type UnionToIntersection<U> = (U extends any
|
|
50
31
|
? (k: U) => void
|
|
51
32
|
: never) extends ((k: infer I) => void)
|
|
@@ -182,11 +163,11 @@ type PageOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>> =
|
|
|
182
163
|
ComponentOpt<D, P, C, M, Mi, S>
|
|
183
164
|
& Partial<WechatMiniprogram.Page.ILifetime>
|
|
184
165
|
|
|
185
|
-
type ThisTypedPageOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>, O = {}> =
|
|
166
|
+
type ThisTypedPageOpt<D extends AnyObject, P, C, M, Mi extends Array<any>, S extends Record<any, any>, O = {}> =
|
|
186
167
|
PageOpt<D, P, C, M, Mi, S>
|
|
187
168
|
& ThisType<ComponentIns<D, P, C, M, Mi, S, O>> & O
|
|
188
169
|
|
|
189
|
-
type ThisTypedComponentOpt<D, P, C, M, Mi extends Array<any>, S extends Record<any, any>, O = {}> =
|
|
170
|
+
type ThisTypedComponentOpt<D extends AnyObject, P, C, M, Mi extends Array<any>, S extends Record<any, any>, O = {}> =
|
|
190
171
|
ComponentOpt<D, P, C, M, Mi, S>
|
|
191
172
|
& ThisType<ComponentIns<D, P, C, M, Mi, S, O>> & O
|
|
192
173
|
|
|
@@ -245,12 +226,12 @@ interface ReplaceWxComponentIns {
|
|
|
245
226
|
selectAllComponents (selector: string): Array<ComponentIns<{}, {}, {}, {}, []>>
|
|
246
227
|
}
|
|
247
228
|
|
|
248
|
-
type WxComponentIns<D> =
|
|
229
|
+
type WxComponentIns<D extends AnyObject> =
|
|
249
230
|
ReplaceWxComponentIns
|
|
250
231
|
& WechatMiniprogram.Component.InstanceProperties
|
|
251
232
|
& WechatMiniprogram.Component.InstanceMethods<D>
|
|
252
233
|
|
|
253
|
-
type ComponentIns<D, P, C, M, Mi extends Array<any>, S extends Record<any, any> = {}, O = {}> =
|
|
234
|
+
type ComponentIns<D extends AnyObject, P, C, M, Mi extends Array<any>, S extends Record<any, any> = {}, O = {}> =
|
|
254
235
|
GetDataType<D> & UnboxMixinsField<Mi, 'data'> &
|
|
255
236
|
M & UnboxMixinsField<Mi, 'methods'> & { [K in keyof S]: S[K] extends Ref<infer V> ? V : S[K] } &
|
|
256
237
|
GetPropsType<P & UnboxMixinsField<Mi, 'properties'>> &
|
|
@@ -261,9 +242,9 @@ interface CreateConfig {
|
|
|
261
242
|
customCtor: any
|
|
262
243
|
}
|
|
263
244
|
|
|
264
|
-
export function createComponent<D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], O = {}> (opt: ThisTypedComponentOpt<D, P, C, M, Mi, O>, config?: CreateConfig): void
|
|
245
|
+
export function createComponent<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>, config?: CreateConfig): void
|
|
265
246
|
|
|
266
|
-
export function getMixin<D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], O = {}> (opt: ThisTypedComponentOpt<D, P, C, M, Mi, O>): {
|
|
247
|
+
export function getMixin<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>): {
|
|
267
248
|
data: GetDataType<D> & UnboxMixinsField<Mi, 'data'>
|
|
268
249
|
properties: P & UnboxMixinsField<Mi, 'properties'>
|
|
269
250
|
computed: C & UnboxMixinsField<Mi, 'computed'>
|
|
@@ -271,42 +252,10 @@ export function getMixin<D extends Data = {}, P extends Properties = {}, C = {},
|
|
|
271
252
|
[index: string]: any
|
|
272
253
|
}
|
|
273
254
|
|
|
274
|
-
export function createPage<D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], O = {}> (opt: ThisTypedPageOpt<D, P, C, M, Mi, O>, config?: CreateConfig): void
|
|
255
|
+
export function createPage<D extends Data = {}, P extends Properties = {}, C = {}, M extends Methods = {}, Mi extends Array<any> = [], O extends AnyObject = {}> (opt: ThisTypedPageOpt<D, P, C, M, Mi, O>, config?: CreateConfig): void
|
|
275
256
|
|
|
276
257
|
export function createApp<T extends WechatMiniprogram.IAnyObject> (opt: WechatMiniprogram.App.Options<T>, config?: CreateConfig): void
|
|
277
258
|
|
|
278
|
-
export function createStore<S, G extends Getters<S>, M extends Mutations<S>, A extends Actions<S, G>, D extends Deps = {}> (option: StoreOpt<S, G, M, A, D>): Store<S, G, M, A, D>
|
|
279
|
-
|
|
280
|
-
export function createStoreWithThis<S = {}, G = {}, M extends MutationsAndActionsWithThis = {}, A extends MutationsAndActionsWithThis = {}, D extends Deps = {}> (option: StoreOptWithThis<S, G, M, A, D>): StoreWithThis<S, G, M, A, D>
|
|
281
|
-
|
|
282
|
-
// auxiliary functions
|
|
283
|
-
export function createStateWithThis<S = {}> (state: S): S
|
|
284
|
-
|
|
285
|
-
export function createGettersWithThis<S = {}, D extends Deps = {}, G = {}, OG = {}> (getters: G & ThisType<{ state: S & UnboxDepsField<D, 'state'>, getters: GetComputedType<G & OG> & UnboxDepsField<D, 'getters'>, rootState: any }>, options?: {
|
|
286
|
-
state?: S,
|
|
287
|
-
getters?: OG,
|
|
288
|
-
deps?: D
|
|
289
|
-
}): G
|
|
290
|
-
|
|
291
|
-
export function createMutationsWithThis<S = {}, D extends Deps = {}, M extends MutationsAndActionsWithThis = {}> (mutations: M & ThisType<{ state: S & UnboxDepsField<D, 'state'>, commit: GetDispatchAndCommitWithThis<M, D, 'mutations'> }>, options?: {
|
|
292
|
-
state?: S,
|
|
293
|
-
deps?: D
|
|
294
|
-
}): M
|
|
295
|
-
|
|
296
|
-
export function createActionsWithThis<S = {}, G = {}, M extends MutationsAndActionsWithThis = {}, D extends Deps = {}, A extends MutationsAndActionsWithThis = {}, OA extends MutationsAndActionsWithThis = {}> (actions: A & ThisType<{
|
|
297
|
-
rootState: any,
|
|
298
|
-
state: S & UnboxDepsField<D, 'state'>,
|
|
299
|
-
getters: GetComputedType<G> & UnboxDepsField<D, 'getters'>,
|
|
300
|
-
dispatch: GetDispatchAndCommitWithThis<A & OA, D, 'actions'>,
|
|
301
|
-
commit: GetDispatchAndCommitWithThis<M, D, 'mutations'>
|
|
302
|
-
} & MpxStore.CompatibleDispatch>, options?: {
|
|
303
|
-
state?: S,
|
|
304
|
-
getters?: G,
|
|
305
|
-
mutations?: M,
|
|
306
|
-
actions?: OA,
|
|
307
|
-
deps?: D
|
|
308
|
-
}): A
|
|
309
|
-
|
|
310
259
|
type MixinType = 'app' | 'page' | 'component'
|
|
311
260
|
|
|
312
261
|
export function injectMixins (mixins: object | Array<object>, options?: MixinType | MixinType[] | { types?: MixinType | MixinType[], stage?: number }): void
|
|
@@ -322,12 +271,12 @@ interface AnyConstructor {
|
|
|
322
271
|
interface MpxConfig {
|
|
323
272
|
useStrictDiff: boolean
|
|
324
273
|
ignoreWarning: boolean | string | RegExp | ((msg: string, location: string, e: Error) => boolean)
|
|
325
|
-
|
|
274
|
+
ignoreProxyWhiteList: Array<string>
|
|
326
275
|
observeClassInstance: boolean | Array<AnyConstructor>
|
|
327
|
-
|
|
276
|
+
errorHandler: (e: Error, target: ComponentIns<{}, {}, {}, {}, []>, hookName: string) => any | null
|
|
328
277
|
proxyEventHandler: (e: Event) => any | null
|
|
329
278
|
setDataHandler: (data: object, target: ComponentIns<{}, {}, {}, {}, []>) => any | null
|
|
330
|
-
|
|
279
|
+
forceFlushSync: boolean,
|
|
331
280
|
webRouteConfig: object
|
|
332
281
|
}
|
|
333
282
|
|
|
@@ -341,12 +290,13 @@ interface ImplementOptions {
|
|
|
341
290
|
|
|
342
291
|
export function toPureObject<T extends object> (obj: T): T
|
|
343
292
|
|
|
293
|
+
declare type PluginInstallFunction = (app: Mpx, ...options: any[]) => any;
|
|
294
|
+
|
|
295
|
+
export type Plugin = PluginInstallFunction | {
|
|
296
|
+
install: PluginInstallFunction;
|
|
297
|
+
};
|
|
298
|
+
|
|
344
299
|
export interface Mpx {
|
|
345
|
-
createComponent: typeof createComponent
|
|
346
|
-
createPage: typeof createPage
|
|
347
|
-
createApp: typeof createApp
|
|
348
|
-
createStore: typeof createStore
|
|
349
|
-
createStoreWithThis: typeof createStoreWithThis
|
|
350
300
|
getMixin: typeof getMixin
|
|
351
301
|
mixin: typeof injectMixins
|
|
352
302
|
injectMixins: typeof injectMixins
|
|
@@ -355,7 +305,7 @@ export interface Mpx {
|
|
|
355
305
|
|
|
356
306
|
// watch: typeof watch
|
|
357
307
|
|
|
358
|
-
use (plugin:
|
|
308
|
+
use (plugin: Plugin, ...rest: any[]): Mpx
|
|
359
309
|
|
|
360
310
|
implement (name: string, options?: ImplementOptions): void
|
|
361
311
|
|
|
@@ -488,9 +438,8 @@ type WatchCallback<T> = (
|
|
|
488
438
|
|
|
489
439
|
type WatchSource<T> =
|
|
490
440
|
| Ref<T> // ref
|
|
491
|
-
| ComputedRef<T>
|
|
492
|
-
| Reactive<T>
|
|
493
441
|
| (() => T) // getter
|
|
442
|
+
| ComputedRef<T>
|
|
494
443
|
|
|
495
444
|
type MultiWatchSources = (WatchSource<unknown> | object)[]
|
|
496
445
|
|
|
@@ -498,7 +447,7 @@ interface WatchEffectOptions {
|
|
|
498
447
|
flush?: 'pre' | 'post' | 'sync' // default: 'pre'
|
|
499
448
|
}
|
|
500
449
|
|
|
501
|
-
interface WatchOptions extends WatchEffectOptions {
|
|
450
|
+
export interface WatchOptions extends WatchEffectOptions {
|
|
502
451
|
immediate?: boolean // 默认:false
|
|
503
452
|
deep?: boolean // 默认:false
|
|
504
453
|
flush?: 'pre' | 'post' | 'sync' // 默认:'pre'
|
|
@@ -698,7 +647,7 @@ export const ONRESIZE: string
|
|
|
698
647
|
|
|
699
648
|
declare global {
|
|
700
649
|
const defineProps: <T>(props: T) => Readonly<GetPropsType<T>>
|
|
701
|
-
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
|
|
702
|
-
const defineExpose: <E extends
|
|
650
|
+
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
|
|
651
|
+
const defineExpose: <E extends AnyObject = AnyObject>(exposed?: E) => void
|
|
703
652
|
const useContext: () => Context
|
|
704
653
|
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
1. Definitions.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
21
|
+
|
|
22
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
28
|
+
|
|
29
|
+
the copyright owner that is granting the License.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
35
|
+
|
|
36
|
+
other entities that control, are controlled by, or are under common
|
|
37
|
+
|
|
38
|
+
control with that entity. For the purposes of this definition,
|
|
39
|
+
|
|
40
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
41
|
+
|
|
42
|
+
direction or management of such entity, whether by contract or
|
|
43
|
+
|
|
44
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
45
|
+
|
|
46
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
52
|
+
|
|
53
|
+
exercising permissions granted by this License.
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
59
|
+
|
|
60
|
+
including but not limited to software source code, documentation
|
|
61
|
+
|
|
62
|
+
source, and configuration files.
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
"Object" form shall mean any form resulting from mechanical
|
|
68
|
+
|
|
69
|
+
transformation or translation of a Source form, including but
|
|
70
|
+
|
|
71
|
+
not limited to compiled object code, generated documentation,
|
|
72
|
+
|
|
73
|
+
and conversions to other media types.
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
79
|
+
|
|
80
|
+
Object form, made available under the License, as indicated by a
|
|
81
|
+
|
|
82
|
+
copyright notice that is included in or attached to the work
|
|
83
|
+
|
|
84
|
+
(an example is provided in the Appendix below).
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
90
|
+
|
|
91
|
+
form, that is based on (or derived from) the Work and for which the
|
|
92
|
+
|
|
93
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
94
|
+
|
|
95
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
96
|
+
|
|
97
|
+
of this License, Derivative Works shall not include works that remain
|
|
98
|
+
|
|
99
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
100
|
+
|
|
101
|
+
the Work and Derivative Works thereof.
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
"Contribution" shall mean any work of authorship, including
|
|
107
|
+
|
|
108
|
+
the original version of the Work and any modifications or additions
|
|
109
|
+
|
|
110
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
111
|
+
|
|
112
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
113
|
+
|
|
114
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
115
|
+
|
|
116
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
117
|
+
|
|
118
|
+
means any form of electronic, verbal, or written communication sent
|
|
119
|
+
|
|
120
|
+
to the Licensor or its representatives, including but not limited to
|
|
121
|
+
|
|
122
|
+
communication on electronic mailing lists, source code control systems,
|
|
123
|
+
|
|
124
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
125
|
+
|
|
126
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
127
|
+
|
|
128
|
+
excluding communication that is conspicuously marked or otherwise
|
|
129
|
+
|
|
130
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
136
|
+
|
|
137
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
138
|
+
|
|
139
|
+
subsequently incorporated within the Work.
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
145
|
+
|
|
146
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
147
|
+
|
|
148
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
149
|
+
|
|
150
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
151
|
+
|
|
152
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
153
|
+
|
|
154
|
+
Work and such Derivative Works in Source or Object form.
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
160
|
+
|
|
161
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
162
|
+
|
|
163
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
164
|
+
|
|
165
|
+
(except as stated in this section) patent license to make, have made,
|
|
166
|
+
|
|
167
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
168
|
+
|
|
169
|
+
where such license applies only to those patent claims licensable
|
|
170
|
+
|
|
171
|
+
by such Contributor that are necessarily infringed by their
|
|
172
|
+
|
|
173
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
174
|
+
|
|
175
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
176
|
+
|
|
177
|
+
institute patent litigation against any entity (including a
|
|
178
|
+
|
|
179
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
180
|
+
|
|
181
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
182
|
+
|
|
183
|
+
or contributory patent infringement, then any patent licenses
|
|
184
|
+
|
|
185
|
+
granted to You under this License for that Work shall terminate
|
|
186
|
+
|
|
187
|
+
as of the date such litigation is filed.
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
193
|
+
|
|
194
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
195
|
+
|
|
196
|
+
modifications, and in Source or Object form, provided that You
|
|
197
|
+
|
|
198
|
+
meet the following conditions:
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
(a) You must give any other recipients of the Work or
|
|
204
|
+
|
|
205
|
+
Derivative Works a copy of this License; and
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
(b) You must cause any modified files to carry prominent notices
|
|
211
|
+
|
|
212
|
+
stating that You changed the files; and
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
218
|
+
|
|
219
|
+
that You distribute, all copyright, patent, trademark, and
|
|
220
|
+
|
|
221
|
+
attribution notices from the Source form of the Work,
|
|
222
|
+
|
|
223
|
+
excluding those notices that do not pertain to any part of
|
|
224
|
+
|
|
225
|
+
the Derivative Works; and
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
231
|
+
|
|
232
|
+
distribution, then any Derivative Works that You distribute must
|
|
233
|
+
|
|
234
|
+
include a readable copy of the attribution notices contained
|
|
235
|
+
|
|
236
|
+
within such NOTICE file, excluding those notices that do not
|
|
237
|
+
|
|
238
|
+
pertain to any part of the Derivative Works, in at least one
|
|
239
|
+
|
|
240
|
+
of the following places: within a NOTICE text file distributed
|
|
241
|
+
|
|
242
|
+
as part of the Derivative Works; within the Source form or
|
|
243
|
+
|
|
244
|
+
documentation, if provided along with the Derivative Works; or,
|
|
245
|
+
|
|
246
|
+
within a display generated by the Derivative Works, if and
|
|
247
|
+
|
|
248
|
+
wherever such third-party notices normally appear. The contents
|
|
249
|
+
|
|
250
|
+
of the NOTICE file are for informational purposes only and
|
|
251
|
+
|
|
252
|
+
do not modify the License. You may add Your own attribution
|
|
253
|
+
|
|
254
|
+
notices within Derivative Works that You distribute, alongside
|
|
255
|
+
|
|
256
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
257
|
+
|
|
258
|
+
that such additional attribution notices cannot be construed
|
|
259
|
+
|
|
260
|
+
as modifying the License.
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
You may add Your own copyright statement to Your modifications and
|
|
266
|
+
|
|
267
|
+
may provide additional or different license terms and conditions
|
|
268
|
+
|
|
269
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
270
|
+
|
|
271
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
272
|
+
|
|
273
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
274
|
+
|
|
275
|
+
the conditions stated in this License.
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
281
|
+
|
|
282
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
283
|
+
|
|
284
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
285
|
+
|
|
286
|
+
this License, without any additional terms or conditions.
|
|
287
|
+
|
|
288
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
289
|
+
|
|
290
|
+
the terms of any separate license agreement you may have executed
|
|
291
|
+
|
|
292
|
+
with Licensor regarding such Contributions.
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
298
|
+
|
|
299
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
300
|
+
|
|
301
|
+
except as required for reasonable and customary use in describing the
|
|
302
|
+
|
|
303
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
309
|
+
|
|
310
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
311
|
+
|
|
312
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
313
|
+
|
|
314
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
315
|
+
|
|
316
|
+
implied, including, without limitation, any warranties or conditions
|
|
317
|
+
|
|
318
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
319
|
+
|
|
320
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
321
|
+
|
|
322
|
+
appropriateness of using or redistributing the Work and assume any
|
|
323
|
+
|
|
324
|
+
risks associated with Your exercise of permissions under this License.
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
330
|
+
|
|
331
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
332
|
+
|
|
333
|
+
unless required by applicable law (such as deliberate and grossly
|
|
334
|
+
|
|
335
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
336
|
+
|
|
337
|
+
liable to You for damages, including any direct, indirect, special,
|
|
338
|
+
|
|
339
|
+
incidental, or consequential damages of any character arising as a
|
|
340
|
+
|
|
341
|
+
result of this License or out of the use or inability to use the
|
|
342
|
+
|
|
343
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
344
|
+
|
|
345
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
346
|
+
|
|
347
|
+
other commercial damages or losses), even if such Contributor
|
|
348
|
+
|
|
349
|
+
has been advised of the possibility of such damages.
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
355
|
+
|
|
356
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
357
|
+
|
|
358
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
359
|
+
|
|
360
|
+
or other liability obligations and/or rights consistent with this
|
|
361
|
+
|
|
362
|
+
License. However, in accepting such obligations, You may act only
|
|
363
|
+
|
|
364
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
365
|
+
|
|
366
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
367
|
+
|
|
368
|
+
defend, and hold each Contributor harmless for any liability
|
|
369
|
+
|
|
370
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
371
|
+
|
|
372
|
+
of your accepting any such warranty or additional liability.
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
END OF TERMS AND CONDITIONS
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
To apply the Apache License to your work, attach the following
|
|
388
|
+
|
|
389
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
390
|
+
|
|
391
|
+
replaced with your own identifying information. (Don't include
|
|
392
|
+
|
|
393
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
394
|
+
|
|
395
|
+
comment syntax for the file format. We also recommend that a
|
|
396
|
+
|
|
397
|
+
file or class name and description of purpose be included on the
|
|
398
|
+
|
|
399
|
+
same "printed page" as the copyright notice for easier
|
|
400
|
+
|
|
401
|
+
identification within third-party archives.
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
Copyright (C) 2017 Beijing Didi Infinity Technology and Development Co.,Ltd. All rights reserved.
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
412
|
+
|
|
413
|
+
you may not use this file except in compliance with the License.
|
|
414
|
+
|
|
415
|
+
You may obtain a copy of the License at
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
Unless required by applicable law or agreed to in writing, software
|
|
426
|
+
|
|
427
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
428
|
+
|
|
429
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
430
|
+
|
|
431
|
+
See the License for the specific language governing permissions and
|
|
432
|
+
|
|
433
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.8.0-beta.
|
|
3
|
+
"version": "2.8.0-beta.4",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/index.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mpxjs/utils": "^2.8.0-beta.
|
|
22
|
+
"@mpxjs/utils": "^2.8.0-beta.4",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.0.2"
|
|
25
25
|
},
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"url": "https://github.com/didi/mpx/issues"
|
|
48
48
|
},
|
|
49
49
|
"sideEffects": false,
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "7a3dd6c2d0fceb31ee035e85b7f11091e31409d3"
|
|
51
51
|
}
|
package/src/core/implement.js
CHANGED
|
@@ -2,7 +2,7 @@ import { noop } from '@mpxjs/utils'
|
|
|
2
2
|
|
|
3
3
|
export const implemented = {}
|
|
4
4
|
|
|
5
|
-
export function implement (name, { modes = [], processor = noop
|
|
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/proxy.js
CHANGED
|
@@ -207,6 +207,8 @@ export default class MpxProxy {
|
|
|
207
207
|
if (this.options.__type__ === 'page' && !this.options.__pageCtor__) {
|
|
208
208
|
proxy(this.target, this.options, this.options.mpxCustomKeysForBlend, false, this.createProxyConflictHandler('page options'))
|
|
209
209
|
}
|
|
210
|
+
// 挂载$rawOptions
|
|
211
|
+
this.target.$rawOptions = this.options
|
|
210
212
|
if (__mpx_mode__ !== 'web') {
|
|
211
213
|
// 挂载$watch
|
|
212
214
|
this.target.$watch = this.watch.bind(this)
|
package/src/observer/array.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { CREATED, BEFOREMOUNT, BEFOREUPDATE, UNMOUNTED } from '../../core/innerLifecycle'
|
|
2
|
-
import { noop, error
|
|
2
|
+
import { noop, error } from '@mpxjs/utils'
|
|
3
|
+
import { getEnvObj } from '@mpxjs/utils/src/env'
|
|
3
4
|
|
|
4
5
|
const envObj = getEnvObj()
|
|
5
6
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import transferOptions from '../core/transferOptions'
|
|
2
2
|
import mergeOptions from '../core/mergeOptions'
|
|
3
3
|
import builtInKeysMap from './patch/builtInKeysMap'
|
|
4
|
-
import {
|
|
4
|
+
import { spreadProp } from '@mpxjs/utils'
|
|
5
|
+
import { makeMap } from '@mpxjs/utils/src/array'
|
|
5
6
|
import * as webLifecycle from '../platform/patch/web/lifecycle'
|
|
6
7
|
import Mpx from '../index'
|
|
7
8
|
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
effectScope as vueEffectScope,
|
|
3
|
+
getCurrentScope as getCurrentVueScope,
|
|
4
|
+
onScopeDispose,
|
|
5
|
+
getCurrentInstance as getCurrentVueInstance
|
|
6
|
+
} from 'vue'
|
|
7
|
+
|
|
1
8
|
export {
|
|
2
9
|
// watch
|
|
3
10
|
watchEffect,
|
|
@@ -21,14 +28,31 @@ export {
|
|
|
21
28
|
shallowRef,
|
|
22
29
|
triggerRef,
|
|
23
30
|
// computed
|
|
24
|
-
computed
|
|
25
|
-
|
|
31
|
+
computed
|
|
32
|
+
} from 'vue'
|
|
33
|
+
|
|
34
|
+
const noop = () => {
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const fixEffectScope = (scope) => {
|
|
38
|
+
scope.pause = noop
|
|
39
|
+
scope.resume = noop
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
|
|
43
|
+
const getCurrentScope = () => fixEffectScope(getCurrentVueScope())
|
|
44
|
+
|
|
45
|
+
export {
|
|
26
46
|
effectScope,
|
|
27
47
|
getCurrentScope,
|
|
28
|
-
onScopeDispose
|
|
29
|
-
|
|
48
|
+
onScopeDispose
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getCurrentInstance = () => getCurrentVueInstance()?.__mpxProxy
|
|
52
|
+
|
|
53
|
+
export {
|
|
30
54
|
getCurrentInstance
|
|
31
|
-
}
|
|
55
|
+
}
|
|
32
56
|
|
|
33
57
|
export {
|
|
34
58
|
// i18n
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import builtInKeysMap from '../builtInKeysMap'
|
|
2
2
|
import mergeOptions from '../../../core/mergeOptions'
|
|
3
3
|
import { diffAndCloneA } from '@mpxjs/utils'
|
|
4
|
-
import { getCurrentInstance as
|
|
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'
|
|
7
7
|
|
|
@@ -37,7 +37,7 @@ export function getDefaultOptions (type, { rawOptions = {} }) {
|
|
|
37
37
|
const rawSetup = rawOptions.setup
|
|
38
38
|
if (rawSetup) {
|
|
39
39
|
rawOptions.setup = (props) => {
|
|
40
|
-
const instance =
|
|
40
|
+
const instance = getCurrentVueInstance().proxy
|
|
41
41
|
initProxy(instance, rawOptions)
|
|
42
42
|
setCurrentInstance(instance.__mpxProxy)
|
|
43
43
|
const newContext = {
|
package/@types/mpx-store.d.ts
DELETED
|
@@ -1,333 +0,0 @@
|
|
|
1
|
-
declare namespace MpxStore {
|
|
2
|
-
type UnboxDepField<D, F> = F extends keyof D ? D[F] : {}
|
|
3
|
-
|
|
4
|
-
interface compContext{
|
|
5
|
-
__mpxProxy: object;
|
|
6
|
-
[key: string]: any
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface Deps {
|
|
10
|
-
[key: string]: Store | StoreWithThis
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
type UnboxDepsField<D extends Deps, F> = string extends keyof D ? {} : {
|
|
14
|
-
[K in keyof D]: UnboxDepField<D[K], F>
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type getMutation<M> = M extends (state: any, ...payload: infer P) => infer R ? (...payload: P) => R : never
|
|
18
|
-
|
|
19
|
-
type getAction<A> = A extends (context: object, ...payload: infer P) => infer R ? (...payload: P) => R : never
|
|
20
|
-
|
|
21
|
-
type Mutations<S> = {
|
|
22
|
-
[key: string]: (this: void, state: S, ...payload: any[]) => any
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
interface Getters<S> {
|
|
26
|
-
[key: string]: (this: void, state: S, getters: any, globalState: any) => any
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
type Actions<S, G extends Getters<S>> = {
|
|
30
|
-
[key: string]: (this: void, context: {
|
|
31
|
-
rootState: any,
|
|
32
|
-
state: S,
|
|
33
|
-
getters: GetGetters<G>,
|
|
34
|
-
dispatch: (type: string, ...payload: any[]) => any,
|
|
35
|
-
commit: (type: string, ...payload: any[]) => any
|
|
36
|
-
}, ...payload: any[]) => any
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
type GetGetters<G> = {
|
|
40
|
-
readonly [K in keyof G]: G[K] extends (state: any, getters: any, globalState: any) => infer R ? R : G[K]
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type GetMutations<M> = {
|
|
44
|
-
[K in keyof M]: getMutation<M[K]>
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
type GetActions<A> = {
|
|
48
|
-
[K in keyof A]: getAction<A[K]>
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
type GetDispatch<A, D> = keyof D extends never ? (<T extends keyof A>(type: T, ...payload: A[T] extends (context: any, ...payload: infer P) => any ? P : never) => A[T] extends (context: any, ...payload: any[]) => infer R ? R : never) : ((type: string, ...payload: any[]) => any)
|
|
52
|
-
|
|
53
|
-
type GetCommit<M, D> = keyof D extends never ? (<T extends keyof M>(type: T, ...payload: M[T] extends (state: any, ...payload: infer P) => any ? P : never) => M[T] extends (state: any, ...payload: any[]) => infer R ? R : never) : ((type: string, ...payload: any[]) => any)
|
|
54
|
-
|
|
55
|
-
interface Store<S = {}, G = {}, M = {}, A = {}, D extends Deps = {}> {
|
|
56
|
-
|
|
57
|
-
__deps: D
|
|
58
|
-
__state: S
|
|
59
|
-
__getters: GetGetters<G>
|
|
60
|
-
|
|
61
|
-
state: S & UnboxDepsField<D, 'state'>
|
|
62
|
-
getters: GetGetters<G> & UnboxDepsField<D, 'getters'>
|
|
63
|
-
mutations: GetMutations<M> & UnboxDepsField<D, 'mutations'>
|
|
64
|
-
actions: GetActions<A> & UnboxDepsField<D, 'actions'>
|
|
65
|
-
|
|
66
|
-
dispatch: GetDispatch<A, D>
|
|
67
|
-
|
|
68
|
-
commit: GetCommit<M, D>
|
|
69
|
-
|
|
70
|
-
mapState<K extends keyof S>(maps: K[]): {
|
|
71
|
-
[I in K]: () => S[I]
|
|
72
|
-
}
|
|
73
|
-
mapState(depPath: string, maps: string[]): object
|
|
74
|
-
|
|
75
|
-
// mapState support object
|
|
76
|
-
mapState<T extends { [key: string]: keyof GetAllMapKeys<S, D, 'state'> }>(obj: T): {
|
|
77
|
-
[I in keyof T]: () => GetAllMapKeys<S, D, 'state'>[T[I]]
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
mapGetters<K extends keyof G>(maps: K[]): {
|
|
81
|
-
[I in K]: () => GetGetters<G>[I]
|
|
82
|
-
}
|
|
83
|
-
mapGetters(depPath: string, maps: string[]): {
|
|
84
|
-
[key: string]: () => any
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
mapMutations<K extends keyof M>(maps: K[]): Pick<GetMutations<M>, K>
|
|
88
|
-
mapMutations(depPath: string, maps: string[]): {
|
|
89
|
-
[key: string]: (...payloads: any[]) => any
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
mapActions<K extends keyof A>(maps: K[]): Pick<GetActions<A>, K>
|
|
93
|
-
mapActions(depPath: string, maps: string[]): {
|
|
94
|
-
[key: string]: (...payloads: any[]) => any
|
|
95
|
-
}
|
|
96
|
-
// 下面是新增的异步store的接口类型
|
|
97
|
-
mapStateToInstance<K extends keyof S>(maps: K[], context: compContext): void
|
|
98
|
-
mapStateToInstance(depPath: string, maps: string[], context: compContext): void
|
|
99
|
-
|
|
100
|
-
// mapState support object
|
|
101
|
-
mapStateToInstance<T extends { [key: string]: keyof GetAllMapKeys<S, D, 'state'> }>(obj: T, context: compContext): void
|
|
102
|
-
|
|
103
|
-
mapGettersToInstance<K extends keyof G>(maps: K[], context: compContext): void
|
|
104
|
-
mapGettersToInstance(depPath: string, maps: string[], context: compContext): void
|
|
105
|
-
|
|
106
|
-
mapMutationsToInstance<K extends keyof M>(maps: K[], context: compContext): Pick<GetMutations<M>, K>
|
|
107
|
-
mapMutationsToInstance(depPath: string, maps: string[], context: compContext): void
|
|
108
|
-
|
|
109
|
-
mapActionsToInstance<K extends keyof A>(maps: K[], context: compContext): Pick<GetActions<A>, K>
|
|
110
|
-
mapActionsToInstance(depPath: string, maps: string[], context: compContext): void
|
|
111
|
-
}
|
|
112
|
-
type GetComputedSetKeys<T> = {
|
|
113
|
-
[K in keyof T]: T[K] extends {
|
|
114
|
-
get(): any,
|
|
115
|
-
set(val: any): void
|
|
116
|
-
} ? K : never
|
|
117
|
-
}[keyof T]
|
|
118
|
-
|
|
119
|
-
type GetComputedType<T> = {
|
|
120
|
-
readonly [K in Exclude<keyof T, GetComputedSetKeys<T>>]: T[K] extends () => infer R ? R : T[K]
|
|
121
|
-
} & {
|
|
122
|
-
[K in GetComputedSetKeys<T>]: T[K] extends {
|
|
123
|
-
get(): infer R,
|
|
124
|
-
set(val: any): void
|
|
125
|
-
} ? R : T[K]
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
interface MutationsAndActionsWithThis {
|
|
129
|
-
[key: string]: (...payload: any[]) => any
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
type UnionToIntersection<U> = (U extends any
|
|
133
|
-
? (k: U) => void
|
|
134
|
-
: never) extends ((k: infer I) => void)
|
|
135
|
-
? I
|
|
136
|
-
: never;
|
|
137
|
-
|
|
138
|
-
interface mapStateFunctionType<S, G> {
|
|
139
|
-
[key: string]: (state: S, getter: G) => any
|
|
140
|
-
}
|
|
141
|
-
interface DeeperMutationsAndActions {
|
|
142
|
-
[key: string]: ((...payload: any[]) => any) | MutationsAndActionsWithThis
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
interface DeeperStateAndGetters {
|
|
146
|
-
[key: string]: any | DeeperStateAndGetters
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* remove compatible code in Mpx.
|
|
151
|
-
* if you need using createStoreWithThis mix with createStore
|
|
152
|
-
* you can add a global define file
|
|
153
|
-
* use Declaration Merging(https://www.typescriptlang.org/docs/handbook/declaration-merging.html) on CompatibleDispatch:
|
|
154
|
-
* @example
|
|
155
|
-
* declare module MpxStore {
|
|
156
|
-
* interface CompatibleDispatch {
|
|
157
|
-
* dispatch(type: string, ...payload: any[]): any
|
|
158
|
-
* commit(type: string, ...payload: any[]): any
|
|
159
|
-
* }
|
|
160
|
-
* }
|
|
161
|
-
*/
|
|
162
|
-
interface CompatibleDispatch {
|
|
163
|
-
// dispatch(type: string, ...payload: any[]): any
|
|
164
|
-
// commit(type: string, ...payload: any[]): any
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Store Type Bindings
|
|
168
|
-
type StringKeyof<T> = Exclude<keyof T, symbol>
|
|
169
|
-
|
|
170
|
-
type CombineStringKey<H extends string | number, L extends string | number> = H extends '' ? `${L}` : `${H}.${L}`
|
|
171
|
-
|
|
172
|
-
type GetActionsKey<A, P extends string | number = ''> = UnionToIntersection<{
|
|
173
|
-
[K in StringKeyof<A>]: {
|
|
174
|
-
[RK in CombineStringKey<P, K>]: A[K] extends DeeperMutationsAndActions ? GetActionsKey<A[K], RK> : Record<RK, A[K]>
|
|
175
|
-
}[CombineStringKey<P, K>]
|
|
176
|
-
}[StringKeyof<A>]> // {actA: () => void, storeB.actB: () => void}
|
|
177
|
-
|
|
178
|
-
type GetStateAndGettersKey<D extends Deps, DK extends keyof D, T extends 'state' | 'getters', P extends string | number = ''> = UnionToIntersection<{
|
|
179
|
-
[K in StringKeyof<D[DK][`__${T}`]>]: {
|
|
180
|
-
[RK in CombineStringKey<P, K>]: D[DK][`__${T}`][K]
|
|
181
|
-
}
|
|
182
|
-
}[StringKeyof<D[DK][`__${T}`]>] | {
|
|
183
|
-
[K in StringKeyof<D[DK]['__deps']>]: GetStateAndGettersKey<D[DK]['__deps'], K, T, CombineStringKey<P, K>>
|
|
184
|
-
}[StringKeyof<D[DK]['__deps']>]>
|
|
185
|
-
|
|
186
|
-
// type GetStateAndGettersKey<S, P extends string | number = ''> = UnionToIntersection<{
|
|
187
|
-
// [K in StringKeyof<S>]: {
|
|
188
|
-
// [RK in CombineStringKey<P, K>]: S[K] extends DeeperStateAndGetters ? GetStateAndGettersKey<S[K], RK> : Record<RK, S[K]>
|
|
189
|
-
// }[CombineStringKey<P, K>]
|
|
190
|
-
// }[StringKeyof<S>]> // {stateA: any, storeB.stateB: any}
|
|
191
|
-
|
|
192
|
-
type GetAllDepsType<A, D extends Deps, AK extends 'state' | 'getters' | 'actions' | 'mutations'> = {
|
|
193
|
-
[K in StringKeyof<A>]: A[K]
|
|
194
|
-
} & UnionToIntersection<{
|
|
195
|
-
[K in StringKeyof<D>]: AK extends 'actions' | 'mutations' ? {
|
|
196
|
-
[P in keyof GetActionsKey<D[K][AK], K>]: GetActionsKey<D[K][AK], K>[P]
|
|
197
|
-
} : AK extends 'state' | 'getters' ? { // state, getters
|
|
198
|
-
[P in keyof GetStateAndGettersKey<D, K, AK, K>]: GetStateAndGettersKey<D, K, AK, K>[P]
|
|
199
|
-
// [P in keyof GetStateAndGettersKey<D[K][AK], K>]: GetStateAndGettersKey<D[K][AK], K>[P]
|
|
200
|
-
} : {}
|
|
201
|
-
}[StringKeyof<D>]>
|
|
202
|
-
type GetDispatchAndCommitWithThis<A, D extends Deps, AK extends 'actions' | 'mutations'> = (<T extends keyof GetAllDepsType<A, D, AK>>(type: T, ...payload: GetAllDepsType<A, D, AK>[T] extends (...payload: infer P) => any ? P : never) => GetAllDepsType<A, D, AK>[T] extends (...payload: any[]) => infer R ? R : never)
|
|
203
|
-
|
|
204
|
-
// type GetAllMapKeys<S, D extends Deps, SK extends 'state' | 'getters'> = GetAllDepsType<S, D, SK> & GetStateAndGettersKey<S>
|
|
205
|
-
type GetAllMapKeys<S, D extends Deps, SK extends 'state' | 'getters'> = GetAllDepsType<S, D, SK> // 关闭对state、getters本身传入对象的深层次推导,因为过深的递归会导致ts推导直接挂掉
|
|
206
|
-
|
|
207
|
-
interface StoreOptWithThis<S, G, M, A, D extends Deps> {
|
|
208
|
-
state?: S
|
|
209
|
-
getters?: G & ThisType<{ state: S & UnboxDepsField<D, 'state'>, getters: GetComputedType<G> & UnboxDepsField<D, 'getters'>, rootState: any }>
|
|
210
|
-
mutations?: M & ThisType<{ state: S & UnboxDepsField<D, 'state'> }>
|
|
211
|
-
actions?: A & ThisType<{
|
|
212
|
-
rootState: any,
|
|
213
|
-
state: S & UnboxDepsField<D, 'state'>,
|
|
214
|
-
getters: GetComputedType<G> & UnboxDepsField<D, 'getters'>,
|
|
215
|
-
dispatch: GetDispatchAndCommitWithThis<A, D, 'actions'>,
|
|
216
|
-
commit: GetDispatchAndCommitWithThis<M, D, 'mutations'>
|
|
217
|
-
} & CompatibleDispatch>
|
|
218
|
-
deps?: D
|
|
219
|
-
modules?: Record<string, StoreOptWithThis<{}, {}, {}, {}, {}>>
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
interface IStoreWithThis<S = {}, G = {}, M = {}, A = {}, D extends Deps = {}> {
|
|
223
|
-
|
|
224
|
-
__deps: D
|
|
225
|
-
__state: S
|
|
226
|
-
__getters: GetComputedType<G>
|
|
227
|
-
|
|
228
|
-
state: S & UnboxDepsField<D, 'state'>
|
|
229
|
-
getters: GetComputedType<G> & UnboxDepsField<D, 'getters'>
|
|
230
|
-
mutations: M & UnboxDepsField<D, 'mutations'>
|
|
231
|
-
actions: A & UnboxDepsField<D, 'actions'>
|
|
232
|
-
|
|
233
|
-
dispatch: GetDispatchAndCommitWithThis<A, D, 'actions'>
|
|
234
|
-
|
|
235
|
-
commit: GetDispatchAndCommitWithThis<M, D, 'mutations'>
|
|
236
|
-
|
|
237
|
-
mapState<K extends keyof S>(maps: K[]): {
|
|
238
|
-
[I in K]: () => S[I]
|
|
239
|
-
}
|
|
240
|
-
mapState<T extends string, P extends string>(depPath: P, maps: readonly T[]): {
|
|
241
|
-
[K in T]: () => (CombineStringKey<P, K> extends keyof GetAllMapKeys<S, D, 'state'> ? GetAllMapKeys<S, D, 'state'>[CombineStringKey<P, K>] : any)
|
|
242
|
-
}
|
|
243
|
-
mapState<T extends mapStateFunctionType<S & UnboxDepsField<D, 'state'>, GetComputedType<G> & UnboxDepsField<D, 'getters'>>>(obj: ThisType<any> & T): {
|
|
244
|
-
[I in keyof T]: () => ReturnType<T[I]>
|
|
245
|
-
}
|
|
246
|
-
// Support chain derivation
|
|
247
|
-
mapState<T extends { [key: string]: keyof GetAllMapKeys<S, D, 'state'> }>(obj: T): {
|
|
248
|
-
[I in keyof T]: () => GetAllMapKeys<S, D, 'state'>[T[I]]
|
|
249
|
-
}
|
|
250
|
-
mapState<T extends { [key: string]: keyof S }>(obj: T): {
|
|
251
|
-
[I in keyof T]: () => S[T[I]]
|
|
252
|
-
}
|
|
253
|
-
mapState<T extends { [key: string]: string }>(obj: T): {
|
|
254
|
-
[I in keyof T]: (...payloads: any[]) => any
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
mapGetters<K extends keyof G>(maps: K[]): Pick<G, K>
|
|
258
|
-
mapGetters<T extends string, P extends string>(depPath: P, maps: readonly T[]): {
|
|
259
|
-
// use GetComputedType to get getters' returns
|
|
260
|
-
[K in T]: () => (CombineStringKey<P, K> extends keyof GetAllMapKeys<GetComputedType<G>, D, 'getters'> ? GetAllMapKeys<GetComputedType<G>, D, 'getters'>[CombineStringKey<P, K>] : any)
|
|
261
|
-
}
|
|
262
|
-
// Support chain derivation
|
|
263
|
-
mapGetters<T extends { [key: string]: keyof GetAllMapKeys<GetComputedType<G>, D, 'getters'> }>(obj: T): {
|
|
264
|
-
[I in keyof T]: () => GetAllMapKeys<GetComputedType<G>, D, 'getters'>[T[I]]
|
|
265
|
-
}
|
|
266
|
-
mapGetters<T extends { [key: string]: keyof G }>(obj: T): {
|
|
267
|
-
[I in keyof T]: G[T[I]]
|
|
268
|
-
}
|
|
269
|
-
// When importing js in ts file, use this method to be compatible
|
|
270
|
-
mapGetters<T extends { [key: string]: string }>(obj: T): {
|
|
271
|
-
[I in keyof T]: (...payloads: any[]) => any
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
mapMutations<K extends keyof M>(maps: K[]): Pick<M, K>
|
|
275
|
-
mapMutations<T extends string, P extends string>(depPath: P, maps: readonly T[]): {
|
|
276
|
-
[K in T]: CombineStringKey<P, K> extends keyof GetAllDepsType<M, D, 'mutations'> ? GetAllDepsType<M, D, 'mutations'>[CombineStringKey<P, K>] : (...payloads: any[]) => any
|
|
277
|
-
}
|
|
278
|
-
mapMutations<T extends { [key: string]: keyof M }>(obj: T): {
|
|
279
|
-
[I in keyof T]: M[T[I]]
|
|
280
|
-
}
|
|
281
|
-
mapMutations<T extends { [key: string]: string }>(obj: T): {
|
|
282
|
-
[I in keyof T]: (...payloads: any[]) => any
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
mapActions<K extends keyof A>(maps: K[]): Pick<A, K>
|
|
286
|
-
mapActions<T extends string, P extends string>(depPath: P, maps: readonly T[]): {
|
|
287
|
-
[K in T]: CombineStringKey<P, K> extends keyof GetAllDepsType<A, D, 'actions'> ? GetAllDepsType<A, D, 'actions'>[CombineStringKey<P, K>] : (...payloads: any[]) => any
|
|
288
|
-
}
|
|
289
|
-
mapActions<T extends { [key: string]: keyof A }>(obj: T): {
|
|
290
|
-
[I in keyof T]: A[T[I]]
|
|
291
|
-
}
|
|
292
|
-
mapActions<T extends { [key: string]: string }>(obj: T): {
|
|
293
|
-
[I in keyof T]: (...payloads: any[]) => any
|
|
294
|
-
}
|
|
295
|
-
// 异步store api
|
|
296
|
-
mapStateToInstance<K extends keyof S>(maps: K[], context: compContext): void
|
|
297
|
-
mapStateToInstance<T extends string, P extends string>(depPath: P, maps: readonly T[], context: compContext):void
|
|
298
|
-
mapStateToInstance<T extends mapStateFunctionType<S & UnboxDepsField<D, 'state'>, GetComputedType<G> & UnboxDepsField<D, 'getters'>>>(obj: ThisType<any> & T, context: compContext): void
|
|
299
|
-
// Support chain derivation
|
|
300
|
-
mapStateToInstance<T extends { [key: string]: keyof GetAllMapKeys<S, D, 'state'> }>(obj: T, context: compContext): void
|
|
301
|
-
mapStateToInstance<T extends { [key: string]: keyof S }>(obj: T, context: compContext): void
|
|
302
|
-
mapStateToInstance<T extends { [key: string]: string }>(obj: T, context: compContext): void
|
|
303
|
-
|
|
304
|
-
mapGettersToInstance<K extends keyof G>(maps: K[], context: compContext): void
|
|
305
|
-
mapGettersToInstance<T extends string, P extends string>(depPath: P, maps: readonly T[], context: compContext): void
|
|
306
|
-
// Support chain derivation
|
|
307
|
-
mapGettersToInstance<T extends { [key: string]: keyof GetAllMapKeys<GetComputedType<G>, D, 'getters'> }>(obj: T, context: compContext): void
|
|
308
|
-
mapGettersToInstance<T extends { [key: string]: keyof G }>(obj: T, context: compContext): void
|
|
309
|
-
// When importing js in ts file, use this method to be compatible
|
|
310
|
-
mapGettersToInstance<T extends { [key: string]: string }>(obj: T, context: compContext): void
|
|
311
|
-
|
|
312
|
-
mapMutationsToInstance<K extends keyof M>(maps: K[], context: compContext): void
|
|
313
|
-
mapMutationsToInstance<T extends string, P extends string>(depPath: P, maps: readonly T[], context: compContext): void
|
|
314
|
-
mapMutationsToInstance<T extends { [key: string]: keyof M }>(obj: T, context: compContext): void
|
|
315
|
-
mapMutationsToInstance<T extends { [key: string]: string }>(obj: T, context: compContext): void
|
|
316
|
-
|
|
317
|
-
mapActionsToInstance<K extends keyof A>(maps: K[], context: compContext): void
|
|
318
|
-
mapActionsToInstance<T extends string, P extends string>(depPath: P, maps: readonly T[], context: compContext): void
|
|
319
|
-
mapActionsToInstance<T extends { [key: string]: keyof A }>(obj: T, context: compContext): void
|
|
320
|
-
mapActionsToInstance<T extends { [key: string]: string }>(obj: T, context: compContext): void
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
type StoreWithThis<S = {}, G = {}, M = {}, A = {}, D extends Deps = {}> = IStoreWithThis<S, G, M, A, D> & CompatibleDispatch
|
|
324
|
-
|
|
325
|
-
interface StoreOpt<S, G, M, A, D extends Deps> {
|
|
326
|
-
state?: S,
|
|
327
|
-
getters?: G
|
|
328
|
-
mutations?: M,
|
|
329
|
-
actions?: A,
|
|
330
|
-
deps?: D
|
|
331
|
-
modules?: Record<string, StoreOpt<{}, {}, {}, {}, {}>>
|
|
332
|
-
}
|
|
333
|
-
}
|
package/src/.DS_Store
DELETED
|
Binary file
|