@mpxjs/core 2.8.61 → 2.8.62

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
@@ -46,7 +46,7 @@ type FullPropType<T> = {
46
46
  }
47
47
 
48
48
  interface Properties {
49
- [key: string]: WechatMiniprogram.Component.AllProperty | PropType<any> | FullPropType<any>
49
+ [key: string]: WechatMiniprogram.Component.AllProperty
50
50
  }
51
51
 
52
52
  interface Methods {
@@ -82,12 +82,12 @@ type PropValueType<Def> = Def extends {
82
82
  }
83
83
  ? T
84
84
  : Def extends (...args: any[]) => infer T
85
- ? T
86
- : Def extends FullPropType<infer T>
87
- ? T
88
- : Def extends PropType<infer T>
89
- ? T
90
- : any;
85
+ ? T
86
+ : Def extends FullPropType<infer T>
87
+ ? T
88
+ : Def extends PropType<infer T>
89
+ ? T
90
+ : any;
91
91
 
92
92
  type GetPropsType<T> = {
93
93
  readonly [K in keyof T]: PropValueType<T[K]>
@@ -240,7 +240,10 @@ export function createApp<T extends WechatMiniprogram.IAnyObject> (opt: WechatMi
240
240
 
241
241
  type MixinType = 'app' | 'page' | 'component'
242
242
 
243
- export function injectMixins (mixins: object | Array<object>, options?: MixinType | MixinType[] | { types?: MixinType | MixinType[], stage?: number }): Mpx
243
+ export function injectMixins (mixins: object | Array<object>, options?: MixinType | MixinType[] | {
244
+ types?: MixinType | MixinType[],
245
+ stage?: number
246
+ }): Mpx
244
247
 
245
248
  // export function watch (expr: string | (() => any), handler: WatchHandler | WatchOptWithHandler, options?: WatchOpt): () => void
246
249
 
@@ -339,7 +342,7 @@ export interface Ref<T = any> {
339
342
  * We need this to be in public d.ts but don't want it to show up in IDE
340
343
  * autocomplete, so we use a private Symbol instead.
341
344
  */
342
- [RefSymbol]: true
345
+ [RefSymbol]: true
343
346
  }
344
347
 
345
348
  type CollectionTypes = IterableCollections | WeakCollections
@@ -448,7 +451,11 @@ export interface WatchOptions extends WatchEffectOptions {
448
451
 
449
452
  interface EffectScope {
450
453
  run<T> (fn: () => T): T | undefined // 如果作用域不活跃就为 undefined
451
- stop (): void
454
+ stop (fromParent?: boolean): void
455
+
456
+ pause (): void
457
+
458
+ resume (ignoreDirty?: boolean): void
452
459
  }
453
460
 
454
461
 
@@ -614,7 +621,7 @@ export function onTabItemTap (callback: WechatMiniprogram.Page.ILifetime['onTabI
614
621
  export function onSaveExitState (callback: () => void): void
615
622
 
616
623
  // get instance
617
- export function getCurrentInstance<T extends ComponentIns<{}, {}, {}>> (): T
624
+ export function getCurrentInstance<T extends ComponentIns<{}, {}, {}>> (): { proxy: T, [x: string]: any }
618
625
 
619
626
  // I18n
620
627
  export function useI18n<Options extends {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.8.61",
3
+ "version": "2.8.62",
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": "f393ffc439f21b24f5f09a65ef99db20b145e19a"
50
+ "gitHead": "968ecb02c86fcd5e9f8f827645907ea4225266ff"
51
51
  }
@@ -119,7 +119,9 @@ export class ReactiveEffect {
119
119
  }
120
120
 
121
121
  pause () {
122
- this.pausedState = PausedState.paused
122
+ if (this.pausedState !== PausedState.dirty) {
123
+ this.pausedState = PausedState.paused
124
+ }
123
125
  }
124
126
 
125
127
  resume (ignoreDirty = false) {
@@ -1,8 +1,60 @@
1
- import {
2
- effectScope as vueEffectScope,
3
- getCurrentScope as vueGetCurrentScope,
4
- onScopeDispose
5
- } from 'vue'
1
+ import { EffectScope } from 'vue'
2
+ import { hasOwn } from '@mpxjs/utils'
3
+ import { PausedState } from '../../helper/const'
4
+
5
+ const hackEffectScope = () => {
6
+ EffectScope.prototype.pause = function () {
7
+ if (this.active) {
8
+ let i, l
9
+ for (i = 0, l = this.effects.length; i < l; i++) {
10
+ const effect = this.effects[i]
11
+ // vue2.7中存在对于watcher实例方法的重写(doWatch),因此无法通过修改Watcher.prototype统一实现pause和resume,只能逐个实例修改实现
12
+ if (!hasOwn(effect, 'pausedState')) {
13
+ effect.pausedState = PausedState.resumed
14
+ const rawUpdate = effect.update
15
+ effect.update = function () {
16
+ if (effect.pausedState !== PausedState.resumed) {
17
+ effect.pausedState = PausedState.dirty
18
+ } else {
19
+ rawUpdate.call(effect)
20
+ }
21
+ }
22
+ }
23
+ if (effect.pausedState !== PausedState.dirty) {
24
+ effect.pausedState = PausedState.paused
25
+ }
26
+ }
27
+ if (this.scopes) {
28
+ for (i = 0, l = this.scopes.length; i < l; i++) {
29
+ this.scopes[i].pause()
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ EffectScope.prototype.resume = function (ignoreDirty = false) {
36
+ if (this.active) {
37
+ let i, l
38
+ for (i = 0, l = this.effects.length; i < l; i++) {
39
+ const effect = this.effects[i]
40
+ if (hasOwn(effect, 'pausedState')) {
41
+ const lastPausedState = effect.pausedState
42
+ effect.pausedState = PausedState.resumed
43
+ if (!ignoreDirty && lastPausedState === PausedState.dirty) {
44
+ effect.update()
45
+ }
46
+ }
47
+ }
48
+ if (this.scopes) {
49
+ for (i = 0, l = this.scopes.length; i < l; i++) {
50
+ this.scopes[i].resume(ignoreDirty)
51
+ }
52
+ }
53
+ }
54
+ }
55
+ }
56
+
57
+ hackEffectScope()
6
58
 
7
59
  export {
8
60
  // watch
@@ -29,27 +81,12 @@ export {
29
81
  // computed
30
82
  computed,
31
83
  // instance
32
- getCurrentInstance
33
- } from 'vue'
34
-
35
- const noop = () => {
36
- }
37
-
38
- const fixEffectScope = (scope) => {
39
- scope.pause = noop
40
- scope.resume = noop
41
- return scope
42
- }
43
-
44
- const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
45
- const getCurrentScope = () => fixEffectScope(vueGetCurrentScope())
46
-
47
- export {
84
+ getCurrentInstance,
48
85
  // effectScope
49
86
  effectScope,
50
87
  getCurrentScope,
51
88
  onScopeDispose
52
- }
89
+ } from 'vue'
53
90
 
54
91
  export {
55
92
  // i18n