@mpxjs/core 2.9.33 → 2.9.36
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.36",
|
|
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": "
|
|
50
|
+
"gitHead": "23c1e87cde0eafbb4a6526d83551eb5e12740ba8"
|
|
51
51
|
}
|
|
@@ -1,32 +1,17 @@
|
|
|
1
|
-
import { BEFORECREATE
|
|
1
|
+
import { BEFORECREATE } from '../../core/innerLifecycle'
|
|
2
2
|
import { noop, getEnvObj } from '@mpxjs/utils'
|
|
3
3
|
|
|
4
4
|
const envObj = getEnvObj()
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
Object.defineProperty(target.$refs, ref.key, {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
configurable: true,
|
|
10
|
-
get () {
|
|
11
|
-
// for nodes, every time being accessed, returns as a new selector.
|
|
12
|
-
return target.__getRefNode(ref)
|
|
13
|
-
}
|
|
14
|
-
})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const setComponentRef = function (target, ref, isAsync) {
|
|
6
|
+
const setRef = function (target, ref, isAsync) {
|
|
18
7
|
const targetRefs = isAsync ? target.$asyncRefs : target.$refs
|
|
19
|
-
|
|
20
|
-
const key = ref.key
|
|
21
|
-
Object.defineProperty(targetRefs, key, {
|
|
8
|
+
Object.defineProperty(targetRefs, ref.key, {
|
|
22
9
|
enumerable: true,
|
|
23
10
|
configurable: true,
|
|
24
11
|
get () {
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
return cacheMap.get(key)
|
|
12
|
+
// 对于组件,由于分包异步化的存在,每次都需要重新执行selectComponent,避免一直获取到placeholder
|
|
13
|
+
// 对于节点,每次都需要获取全新的selectorQuery
|
|
14
|
+
return target.__getRefNode(ref, isAsync)
|
|
30
15
|
}
|
|
31
16
|
})
|
|
32
17
|
}
|
|
@@ -36,8 +21,6 @@ export default function getRefsMixin () {
|
|
|
36
21
|
[BEFORECREATE] () {
|
|
37
22
|
this.$refs = {}
|
|
38
23
|
this.$asyncRefs = {}
|
|
39
|
-
this.__refCacheMap = new Map()
|
|
40
|
-
this.__asyncRefCacheMap = new Map()
|
|
41
24
|
this.__getRefs()
|
|
42
25
|
|
|
43
26
|
if (__mpx_mode__ === 'ali') {
|
|
@@ -45,19 +28,14 @@ export default function getRefsMixin () {
|
|
|
45
28
|
this.createSelectorQuery = this._createSelectorQuery
|
|
46
29
|
}
|
|
47
30
|
},
|
|
48
|
-
[BEFOREUPDATE] () {
|
|
49
|
-
this.__refCacheMap.clear()
|
|
50
|
-
this.__asyncRefCacheMap.clear()
|
|
51
|
-
},
|
|
52
31
|
methods: {
|
|
53
32
|
__getRefs () {
|
|
54
33
|
if (this.__getRefsData) {
|
|
55
34
|
const refs = this.__getRefsData()
|
|
56
35
|
refs.forEach(ref => {
|
|
57
|
-
const setRef = ref.type === 'node' ? setNodeRef : setComponentRef
|
|
58
36
|
setRef(this, ref)
|
|
59
37
|
if (__mpx_mode__ === 'tt' && ref.type === 'component') {
|
|
60
|
-
|
|
38
|
+
setRef(this, ref, true)
|
|
61
39
|
}
|
|
62
40
|
})
|
|
63
41
|
}
|
|
@@ -94,9 +72,26 @@ export default function getRefsMixin () {
|
|
|
94
72
|
|
|
95
73
|
Object.assign(refsMixin.methods, {
|
|
96
74
|
_createSelectorQuery (...args) {
|
|
97
|
-
|
|
75
|
+
let selectorQuery = this._originCreateSelectorQuery(...args)
|
|
98
76
|
const cbs = []
|
|
99
77
|
|
|
78
|
+
if (typeof selectorQuery === 'undefined') {
|
|
79
|
+
// 兜底 selectorQuery 在ali为 undefined 情况
|
|
80
|
+
// 调用 createSelectorQuery时,组件实例已经被销毁,ali this._originCreateSelectorQuery 返回 undefined。导致后续 selectorQuery[name] 报错
|
|
81
|
+
// 方案:对齐微信,微信实例销毁时,其他调用正常,仅 createSelectorQuery.exec 不执行回调
|
|
82
|
+
// 复现:setTimeout 中调用,倒计时未回调时切换页面
|
|
83
|
+
selectorQuery = {}
|
|
84
|
+
// ['boundingClientRect', 'context', 'exec', 'fields', 'in', 'node', 'scrollOffset', 'select', 'selectAll', 'selectViewport', 'toImage']
|
|
85
|
+
const backupMethodKeys = Object.keys(envObj.createSelectorQuery())
|
|
86
|
+
const backupFn = function () {
|
|
87
|
+
return selectorQuery
|
|
88
|
+
}
|
|
89
|
+
backupMethodKeys.forEach(key => {
|
|
90
|
+
selectorQuery[key] = backupFn
|
|
91
|
+
})
|
|
92
|
+
return selectorQuery
|
|
93
|
+
}
|
|
94
|
+
|
|
100
95
|
proxyMethods.forEach((name) => {
|
|
101
96
|
const originalMethod = selectorQuery[name]
|
|
102
97
|
selectorQuery[name] = function (cb = noop) {
|