@mpxjs/core 2.7.26 → 2.7.33
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 +2 -0
- package/package.json +2 -2
- package/src/core/proxy.js +42 -12
- package/src/observer/computed.js +6 -4
- package/src/platform/builtInMixins/pageStatusMixin.js +1 -1
- package/src/platform/builtInMixins/refsMixin.js +2 -1
- package/src/platform/patch/ali/getDefaultOptions.js +14 -12
- package/src/platform/patch/swan/getDefaultOptions.js +4 -8
- package/src/platform/patch/web/getDefaultOptions.js +16 -14
- package/src/platform/patch/wx/getDefaultOptions.js +14 -13
package/@types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.33",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"url": "https://github.com/didi/mpx/issues"
|
|
42
42
|
},
|
|
43
43
|
"sideEffects": false,
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "c1d2e39bcfef9bf20484dcbb301381b86a5939e6"
|
|
45
45
|
}
|
package/src/core/proxy.js
CHANGED
|
@@ -41,13 +41,14 @@ export default class MPXProxy {
|
|
|
41
41
|
this.uid = uid++
|
|
42
42
|
this.name = options.name || ''
|
|
43
43
|
this.options = options
|
|
44
|
-
//
|
|
45
|
-
this.state =
|
|
44
|
+
// beforeCreate -> created -> mounted -> destroyed
|
|
45
|
+
this.state = BEFORECREATE
|
|
46
46
|
this.lockTask = asyncLock()
|
|
47
47
|
this.ignoreProxyMap = makeMap(EXPORT_MPX.config.ignoreProxyWhiteList)
|
|
48
48
|
if (__mpx_mode__ !== 'web') {
|
|
49
49
|
this._watchers = []
|
|
50
50
|
this._namedWatchers = {}
|
|
51
|
+
this._computedWatchers = {}
|
|
51
52
|
this._watcher = null
|
|
52
53
|
this.localKeysMap = {} // 非props key
|
|
53
54
|
this.renderData = {} // 渲染函数中收集的数据
|
|
@@ -62,16 +63,33 @@ export default class MPXProxy {
|
|
|
62
63
|
this.initApi()
|
|
63
64
|
this.callUserHook(BEFORECREATE)
|
|
64
65
|
if (__mpx_mode__ !== 'web') {
|
|
65
|
-
this.initState(
|
|
66
|
+
this.initState()
|
|
66
67
|
}
|
|
67
68
|
this.state = CREATED
|
|
68
69
|
this.callUserHook(CREATED, params)
|
|
69
70
|
if (__mpx_mode__ !== 'web') {
|
|
70
|
-
|
|
71
|
-
this.options.__nativeRender__ ? this.doRender() : this.initRender()
|
|
71
|
+
this.initRender()
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
reCreated (params) {
|
|
76
|
+
const options = this.options
|
|
77
|
+
this.state = BEFORECREATE
|
|
78
|
+
this.callUserHook(BEFORECREATE)
|
|
79
|
+
if (__mpx_mode__ !== 'web') {
|
|
80
|
+
this.initComputed(options.computed, true)
|
|
81
|
+
this.initWatch(options.watch)
|
|
82
|
+
}
|
|
83
|
+
this.state = CREATED
|
|
84
|
+
this.callUserHook(CREATED, params)
|
|
85
|
+
if (__mpx_mode__ !== 'web') {
|
|
86
|
+
this.initRender()
|
|
87
|
+
}
|
|
88
|
+
this.nextTick(() => {
|
|
89
|
+
this.mounted()
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
75
93
|
renderTaskExecutor (isEmptyRender) {
|
|
76
94
|
if ((!this.isMounted() && this.curRenderTask) || (this.isMounted() && isEmptyRender)) {
|
|
77
95
|
return
|
|
@@ -118,6 +136,10 @@ export default class MPXProxy {
|
|
|
118
136
|
this.callUserHook(DESTROYED)
|
|
119
137
|
}
|
|
120
138
|
|
|
139
|
+
isDestroyed () {
|
|
140
|
+
return this.state === DESTROYED
|
|
141
|
+
}
|
|
142
|
+
|
|
121
143
|
initApi () {
|
|
122
144
|
// 挂载扩展属性到实例上
|
|
123
145
|
proxy(this.target, this.options.proto, Object.keys(this.options.proto), true, (key) => {
|
|
@@ -168,10 +190,15 @@ export default class MPXProxy {
|
|
|
168
190
|
this.initWatch(options.watch)
|
|
169
191
|
}
|
|
170
192
|
|
|
171
|
-
initComputed (computedOpt) {
|
|
193
|
+
initComputed (computedOpt, reInit) {
|
|
172
194
|
if (computedOpt) {
|
|
173
|
-
|
|
174
|
-
|
|
195
|
+
if (reInit) {
|
|
196
|
+
// target传递null以跳过computed挂载,仅重新初始化watchers
|
|
197
|
+
initComputed(this, null, computedOpt)
|
|
198
|
+
} else {
|
|
199
|
+
this.collectLocalKeys(computedOpt)
|
|
200
|
+
initComputed(this, this.data, computedOpt)
|
|
201
|
+
}
|
|
175
202
|
}
|
|
176
203
|
}
|
|
177
204
|
|
|
@@ -194,7 +221,9 @@ export default class MPXProxy {
|
|
|
194
221
|
})
|
|
195
222
|
Object.assign(this.data, dataFn.call(this.target))
|
|
196
223
|
}
|
|
224
|
+
// 此时data中不包括props数据
|
|
197
225
|
this.collectLocalKeys(this.data)
|
|
226
|
+
// 将props数据合并到data中
|
|
198
227
|
Object.keys(initialData).forEach((key) => {
|
|
199
228
|
if (!hasOwn(this.data, key)) {
|
|
200
229
|
// 除了data函数返回的数据外深拷贝切断引用关系,避免后续watch由于小程序内部对data赋值重复触发watch
|
|
@@ -263,6 +292,7 @@ export default class MPXProxy {
|
|
|
263
292
|
while (i--) {
|
|
264
293
|
this._watchers[i].teardown()
|
|
265
294
|
}
|
|
295
|
+
this._watchers.length = 0
|
|
266
296
|
}
|
|
267
297
|
|
|
268
298
|
render () {
|
|
@@ -414,9 +444,10 @@ export default class MPXProxy {
|
|
|
414
444
|
}
|
|
415
445
|
|
|
416
446
|
initRender () {
|
|
417
|
-
|
|
447
|
+
if (this.options.__nativeRender__) return this.doRender()
|
|
448
|
+
|
|
418
449
|
if (this.target.__injectedRender) {
|
|
419
|
-
|
|
450
|
+
this._watcher = new Watcher(this, () => {
|
|
420
451
|
try {
|
|
421
452
|
return this.target.__injectedRender()
|
|
422
453
|
} catch (e) {
|
|
@@ -425,11 +456,10 @@ export default class MPXProxy {
|
|
|
425
456
|
}
|
|
426
457
|
}, noop, { pausable: true })
|
|
427
458
|
} else {
|
|
428
|
-
|
|
459
|
+
this._watcher = new Watcher(this, () => {
|
|
429
460
|
this.render()
|
|
430
461
|
}, noop, { pausable: true })
|
|
431
462
|
}
|
|
432
|
-
this._watcher = renderWatcher
|
|
433
463
|
}
|
|
434
464
|
|
|
435
465
|
forceUpdate (data, options, callback) {
|
package/src/observer/computed.js
CHANGED
|
@@ -20,10 +20,12 @@ export function initComputed (vm, target, computed) {
|
|
|
20
20
|
noop,
|
|
21
21
|
{ lazy: true }
|
|
22
22
|
)
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
if (target) {
|
|
24
|
+
if (!(key in target)) {
|
|
25
|
+
defineComputed(vm, target, key, userDef)
|
|
26
|
+
} else {
|
|
27
|
+
error(`The computed key [${key}] is duplicated with data/props, please check.`, vm.options.mpxFileResource)
|
|
28
|
+
}
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
}
|
|
@@ -35,7 +35,7 @@ export default function pageStatusMixin (mixinType) {
|
|
|
35
35
|
[CREATED] () {
|
|
36
36
|
const options = this.$rawOptions
|
|
37
37
|
const hasPageShow = options.pageShow || options.pageHide
|
|
38
|
-
const needPageLifetimes = options.pageLifetimes &&
|
|
38
|
+
const needPageLifetimes = options.pageLifetimes && __mpx_mode__ === 'ali'
|
|
39
39
|
|
|
40
40
|
if (hasPageShow || needPageLifetimes) {
|
|
41
41
|
let currentPage
|
|
@@ -22,7 +22,8 @@ const setComponentRef = function (target, ref, context, isAsync) {
|
|
|
22
22
|
enumerable: true,
|
|
23
23
|
configurable: true,
|
|
24
24
|
get () {
|
|
25
|
-
|
|
25
|
+
// wx由于分包异步化的存在,每次访问refs都需要重新执行selectComponen,避免一直拿到缓存中的placeholder
|
|
26
|
+
if (__mpx_mode__ === 'wx' || !cacheRef) {
|
|
26
27
|
return (cacheRef = context.__getRefNode(ref, isAsync))
|
|
27
28
|
}
|
|
28
29
|
return cacheRef
|
|
@@ -84,23 +84,24 @@ function filterOptions (options, type) {
|
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function initProxy (context, rawOptions, currentInject, params) {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
if (!context.__mpxProxy) {
|
|
88
|
+
// 提供代理对象需要的api
|
|
89
|
+
transformApiForProxy(context, currentInject)
|
|
90
|
+
// 缓存options
|
|
91
|
+
context.$rawOptions = rawOptions
|
|
92
|
+
// 创建proxy对象
|
|
93
|
+
context.__mpxProxy = new MPXProxy(rawOptions, context)
|
|
94
|
+
context.__mpxProxy.created(params)
|
|
95
|
+
} else if (context.__mpxProxy.isDestroyed()) {
|
|
96
|
+
context.__mpxProxy.reCreated(params)
|
|
97
|
+
}
|
|
95
98
|
}
|
|
96
99
|
|
|
97
100
|
export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
|
|
98
101
|
const hookNames = type === 'component' ? ['onInit', 'didMount', 'didUnmount'] : ['onLoad', 'onReady', 'onUnload']
|
|
99
102
|
const rootMixins = [{
|
|
100
103
|
[hookNames[0]] (...params) {
|
|
101
|
-
|
|
102
|
-
initProxy(this, rawOptions, currentInject, params)
|
|
103
|
-
}
|
|
104
|
+
initProxy(this, rawOptions, currentInject, params)
|
|
104
105
|
},
|
|
105
106
|
deriveDataFromProps (nextProps) {
|
|
106
107
|
if (this.__mpxProxy && this.__mpxProxy.isMounted() && nextProps && nextProps !== this.props) {
|
|
@@ -130,6 +131,7 @@ export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
|
|
|
130
131
|
},
|
|
131
132
|
didUpdate () {
|
|
132
133
|
if (this.__mpxProxy) {
|
|
134
|
+
// todo: lockTask必要性待验证,属性更新触发自身setData时,updated执行与wx对齐,updated触发机制也考虑与wx对齐(props update && setData callback)
|
|
133
135
|
this.__mpxProxy.lockTask(() => {
|
|
134
136
|
this.__mpxProxy.updated()
|
|
135
137
|
})
|
|
@@ -143,7 +145,7 @@ export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
|
|
|
143
145
|
}
|
|
144
146
|
},
|
|
145
147
|
[hookNames[2]] () {
|
|
146
|
-
this.__mpxProxy
|
|
148
|
+
if (this.__mpxProxy) this.__mpxProxy.destroyed()
|
|
147
149
|
}
|
|
148
150
|
}]
|
|
149
151
|
rawOptions.mixins = rawOptions.mixins ? rootMixins.concat(rawOptions.mixins) : rootMixins
|
|
@@ -10,24 +10,20 @@ export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
|
|
|
10
10
|
|
|
11
11
|
const rootMixin = {
|
|
12
12
|
[hookNames[0]] (...params) {
|
|
13
|
-
|
|
14
|
-
initProxy(this, rawOptions, currentInject, params)
|
|
15
|
-
}
|
|
13
|
+
initProxy(this, rawOptions, currentInject, params)
|
|
16
14
|
},
|
|
17
15
|
[hookNames[1]] () {
|
|
18
|
-
this.__mpxProxy
|
|
16
|
+
if (this.__mpxProxy) this.__mpxProxy.mounted()
|
|
19
17
|
},
|
|
20
18
|
[hookNames[2]] () {
|
|
21
|
-
this.__mpxProxy
|
|
19
|
+
if (this.__mpxProxy) this.__mpxProxy.destroyed()
|
|
22
20
|
}
|
|
23
21
|
}
|
|
24
22
|
|
|
25
23
|
// 如构造页面,优先使用onInit进行初始化
|
|
26
24
|
if (type === 'page') {
|
|
27
25
|
rootMixin.onInit = function (...params) {
|
|
28
|
-
|
|
29
|
-
initProxy(this, rawOptions, currentInject, params)
|
|
30
|
-
}
|
|
26
|
+
initProxy(this, rawOptions, currentInject, params)
|
|
31
27
|
}
|
|
32
28
|
}
|
|
33
29
|
|
|
@@ -24,31 +24,33 @@ function filterOptions (options) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function initProxy (context, rawOptions, params) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if (!context.__mpxProxy) {
|
|
28
|
+
// 缓存options
|
|
29
|
+
context.$rawOptions = rawOptions
|
|
30
|
+
// 创建proxy对象
|
|
31
|
+
context.__mpxProxy = new MPXProxy(rawOptions, context)
|
|
32
|
+
context.__mpxProxy.created(params)
|
|
33
|
+
} else if (context.__mpxProxy.isDestroyed()) {
|
|
34
|
+
context.__mpxProxy.reCreated(params)
|
|
35
|
+
}
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
export function getDefaultOptions (type, { rawOptions = {} }) {
|
|
36
39
|
const rootMixins = [{
|
|
37
40
|
created () {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
41
|
+
const query = (global.__mpxRouter && global.__mpxRouter.currentRoute && global.__mpxRouter.currentRoute.query) || {}
|
|
42
|
+
initProxy(this, rawOptions, [query])
|
|
43
|
+
// web中单独触发onLoad
|
|
44
|
+
this.onLoad && this.onLoad(query)
|
|
43
45
|
},
|
|
44
46
|
mounted () {
|
|
45
|
-
this.__mpxProxy
|
|
47
|
+
if (this.__mpxProxy) this.__mpxProxy.mounted()
|
|
46
48
|
},
|
|
47
49
|
updated () {
|
|
48
|
-
this.__mpxProxy
|
|
50
|
+
if (this.__mpxProxy) this.__mpxProxy.updated()
|
|
49
51
|
},
|
|
50
52
|
destroyed () {
|
|
51
|
-
this.__mpxProxy
|
|
53
|
+
if (this.__mpxProxy) this.__mpxProxy.destroyed()
|
|
52
54
|
}
|
|
53
55
|
}]
|
|
54
56
|
// 为了在builtMixin中可以使用某些rootMixin实现的特性(如数据响应等),此处builtInMixin在rootMixin之后执行,但是当builtInMixin使用存在对应内建生命周期的目标平台声明周期写法时,可能会出现用户生命周期比builtInMixin中的生命周期先执行的情况,为了避免这种情况发生,builtInMixin应该尽可能使用内建生命周期来编写
|
|
@@ -117,14 +117,17 @@ export function filterOptions (options) {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
export function initProxy (context, rawOptions, currentInject, params) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
if (!context.__mpxProxy) {
|
|
121
|
+
// 提供代理对象需要的api
|
|
122
|
+
transformApiForProxy(context, currentInject)
|
|
123
|
+
// 缓存options
|
|
124
|
+
context.$rawOptions = rawOptions
|
|
125
|
+
// 创建proxy对象
|
|
126
|
+
context.__mpxProxy = new MPXProxy(rawOptions, context)
|
|
127
|
+
context.__mpxProxy.created(params)
|
|
128
|
+
} else if (context.__mpxProxy.isDestroyed()) {
|
|
129
|
+
context.__mpxProxy.reCreated(params)
|
|
130
|
+
}
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
|
|
@@ -135,15 +138,13 @@ export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
|
|
|
135
138
|
}
|
|
136
139
|
const rootMixins = [{
|
|
137
140
|
[hookNames[0]] (...params) {
|
|
138
|
-
|
|
139
|
-
initProxy(this, rawOptions, currentInject, params)
|
|
140
|
-
}
|
|
141
|
+
initProxy(this, rawOptions, currentInject, params)
|
|
141
142
|
},
|
|
142
143
|
[hookNames[1]] () {
|
|
143
|
-
this.__mpxProxy
|
|
144
|
+
if (this.__mpxProxy) this.__mpxProxy.mounted()
|
|
144
145
|
},
|
|
145
146
|
[hookNames[2]] () {
|
|
146
|
-
this.__mpxProxy
|
|
147
|
+
if (this.__mpxProxy) this.__mpxProxy.destroyed()
|
|
147
148
|
}
|
|
148
149
|
}]
|
|
149
150
|
rawOptions.mixins = rawOptions.mixins ? rootMixins.concat(rawOptions.mixins) : rootMixins
|