@mpxjs/core 2.8.42 → 2.9.0-beta.1
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 +4 -4
- package/src/core/innerLifecycle.js +2 -0
- package/src/core/mergeOptions.js +1 -1
- package/src/core/proxy.js +2 -0
- package/src/index.js +2 -0
- package/src/platform/builtInMixins/pageStatusMixin.web.js +21 -19
- package/src/platform/builtInMixins/proxyEventMixin.web.js +1 -1
- package/src/platform/createApp.js +20 -11
- package/src/platform/patch/web/getDefaultOptions.js +4 -1
- package/src/platform/patch/web/lifecycle.js +3 -1
- package/src/platform/patch/wx/lifecycle.js +2 -1
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0-beta.1",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
7
7
|
"mpx"
|
|
8
8
|
],
|
|
9
9
|
"author": "donghongping",
|
|
10
|
-
"license": "Apache",
|
|
10
|
+
"license": "Apache-2.0",
|
|
11
11
|
"module": "src/index.js",
|
|
12
12
|
"types": "@types/index.d.ts",
|
|
13
13
|
"directories": {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/index.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mpxjs/utils": "^2.
|
|
22
|
+
"@mpxjs/utils": "^2.9.0-beta.1",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.10.0"
|
|
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": "5e4b44c9b8132e9192cfd119f63196ecc6c4486c"
|
|
51
51
|
}
|
|
@@ -10,6 +10,7 @@ export const ONLOAD = '__onLoad__'
|
|
|
10
10
|
export const ONSHOW = '__onShow__'
|
|
11
11
|
export const ONHIDE = '__onHide__'
|
|
12
12
|
export const ONRESIZE = '__onResize__'
|
|
13
|
+
export const SERVERPREFETCH = '__serverPrefetch__'
|
|
13
14
|
|
|
14
15
|
export const INNER_LIFECYCLES = [
|
|
15
16
|
BEFORECREATE,
|
|
@@ -19,6 +20,7 @@ export const INNER_LIFECYCLES = [
|
|
|
19
20
|
BEFOREUPDATE,
|
|
20
21
|
UPDATED,
|
|
21
22
|
BEFOREUNMOUNT,
|
|
23
|
+
SERVERPREFETCH,
|
|
22
24
|
UNMOUNTED,
|
|
23
25
|
ONLOAD,
|
|
24
26
|
ONSHOW,
|
package/src/core/mergeOptions.js
CHANGED
|
@@ -352,7 +352,7 @@ function transformHOOKS (options) {
|
|
|
352
352
|
const componentHooksMap = makeMap(convertRule.lifecycle.component)
|
|
353
353
|
for (const key in options) {
|
|
354
354
|
// 使用Component创建page实例,页面专属生命周期&自定义方法需写在methods内部
|
|
355
|
-
if (typeof options[key] === 'function' && key !== 'dataFn' && key !== 'setup' && !componentHooksMap[key]) {
|
|
355
|
+
if (typeof options[key] === 'function' && key !== 'dataFn' && key !== 'setup' && key !== 'serverPrefetch' && !componentHooksMap[key]) {
|
|
356
356
|
if (!options.methods) options.methods = {}
|
|
357
357
|
options.methods[key] = options[key]
|
|
358
358
|
delete options[key]
|
package/src/core/proxy.js
CHANGED
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
BEFOREUPDATE,
|
|
37
37
|
UPDATED,
|
|
38
38
|
BEFOREUNMOUNT,
|
|
39
|
+
SERVERPREFETCH,
|
|
39
40
|
UNMOUNTED,
|
|
40
41
|
ONLOAD,
|
|
41
42
|
ONSHOW,
|
|
@@ -641,6 +642,7 @@ export const onLoad = createHook(ONLOAD)
|
|
|
641
642
|
export const onShow = createHook(ONSHOW)
|
|
642
643
|
export const onHide = createHook(ONHIDE)
|
|
643
644
|
export const onResize = createHook(ONRESIZE)
|
|
645
|
+
export const onServerPrefetch = createHook(SERVERPREFETCH)
|
|
644
646
|
export const onPullDownRefresh = createHook('__onPullDownRefresh__')
|
|
645
647
|
export const onReachBottom = createHook('__onReachBottom__')
|
|
646
648
|
export const onShareAppMessage = createHook('__onShareAppMessage__')
|
package/src/index.js
CHANGED
|
@@ -63,7 +63,7 @@ export default function pageStatusMixin (mixinType) {
|
|
|
63
63
|
},
|
|
64
64
|
created () {
|
|
65
65
|
// onLoad应该在用户声明周期CREATED后再执行,故此处使用原生created声明周期来触发onLoad
|
|
66
|
-
const query =
|
|
66
|
+
const query = this.$root.$options?.router?.currentRoute?.query || {}
|
|
67
67
|
this.__mpxProxy.callHook(ONLOAD, [query])
|
|
68
68
|
}
|
|
69
69
|
})
|
|
@@ -71,25 +71,27 @@ export default function pageStatusMixin (mixinType) {
|
|
|
71
71
|
|
|
72
72
|
Object.assign(mixin, {
|
|
73
73
|
[CREATED] () {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
74
|
+
if (isBrowser) {
|
|
75
|
+
const pageInstance = mixinType === 'page' ? this : getCurrentPageInstance()
|
|
76
|
+
if (pageInstance) {
|
|
77
|
+
this.$watch(() => pageInstance.mpxPageStatus, status => {
|
|
78
|
+
if (!status) return
|
|
79
|
+
if (status === 'show') this.__mpxProxy.callHook(ONSHOW)
|
|
80
|
+
if (status === 'hide') this.__mpxProxy.callHook(ONHIDE)
|
|
81
|
+
const pageLifetimes = this.__mpxProxy.options.pageLifetimes
|
|
82
|
+
if (pageLifetimes) {
|
|
83
|
+
if (/^resize/.test(status) && isFunction(pageLifetimes.resize)) {
|
|
84
|
+
// resize
|
|
85
|
+
pageLifetimes.resize.call(this, systemInfo)
|
|
86
|
+
} else if (isFunction(pageLifetimes[status])) {
|
|
87
|
+
// show & hide
|
|
88
|
+
pageLifetimes[status].call(this)
|
|
89
|
+
}
|
|
88
90
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
91
|
+
}, {
|
|
92
|
+
sync: true
|
|
93
|
+
})
|
|
94
|
+
}
|
|
93
95
|
}
|
|
94
96
|
}
|
|
95
97
|
})
|
|
@@ -20,7 +20,7 @@ export default function proxyEventMixin () {
|
|
|
20
20
|
setByPath(this, expr, value)
|
|
21
21
|
},
|
|
22
22
|
getOpenerEventChannel () {
|
|
23
|
-
const router =
|
|
23
|
+
const router = this.$root.$options && this.$root.$options.router
|
|
24
24
|
const eventChannel = router && router.__mpxAction && router.__mpxAction.eventChannel
|
|
25
25
|
return eventChannel
|
|
26
26
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import transferOptions from '../core/transferOptions'
|
|
2
2
|
import mergeOptions from '../core/mergeOptions'
|
|
3
3
|
import builtInKeysMap from './patch/builtInKeysMap'
|
|
4
|
-
import { makeMap, spreadProp } from '@mpxjs/utils'
|
|
4
|
+
import { makeMap, spreadProp, isBrowser } from '@mpxjs/utils'
|
|
5
5
|
import * as webLifecycle from '../platform/patch/web/lifecycle'
|
|
6
6
|
import Mpx from '../index'
|
|
7
7
|
|
|
@@ -35,7 +35,7 @@ export default function createApp (option, config = {}) {
|
|
|
35
35
|
created () {
|
|
36
36
|
Object.assign(this, Mpx.prototype)
|
|
37
37
|
Object.assign(this, appData)
|
|
38
|
-
const current =
|
|
38
|
+
const current = this.$root.$options?.router?.currentRoute || {}
|
|
39
39
|
const options = {
|
|
40
40
|
path: current.path && current.path.replace(/^\//, ''),
|
|
41
41
|
query: current.query,
|
|
@@ -49,19 +49,24 @@ export default function createApp (option, config = {}) {
|
|
|
49
49
|
hide: [],
|
|
50
50
|
error: []
|
|
51
51
|
}
|
|
52
|
-
if (
|
|
53
|
-
this.$options.onShow
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
52
|
+
if (isBrowser) {
|
|
53
|
+
if (this.$options.onShow) {
|
|
54
|
+
this.$options.onShow.call(this, options)
|
|
55
|
+
global.__mpxAppCbs.show.push(this.$options.onShow.bind(this))
|
|
56
|
+
}
|
|
57
|
+
if (this.$options.onHide) {
|
|
58
|
+
global.__mpxAppCbs.hide.push(this.$options.onHide.bind(this))
|
|
59
|
+
}
|
|
60
|
+
if (this.$options.onError) {
|
|
61
|
+
global.__mpxAppCbs.error.push(this.$options.onError.bind(this))
|
|
62
|
+
}
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
})
|
|
64
66
|
} else {
|
|
67
|
+
if (option.onAppInit) {
|
|
68
|
+
option.onAppInit()
|
|
69
|
+
}
|
|
65
70
|
builtInMixins.push({
|
|
66
71
|
onLaunch () {
|
|
67
72
|
Object.assign(this, Mpx.prototype)
|
|
@@ -77,6 +82,10 @@ export default function createApp (option, config = {}) {
|
|
|
77
82
|
global.__mpxOptionsMap = global.__mpxOptionsMap || {}
|
|
78
83
|
global.__mpxOptionsMap[global.currentModuleId] = defaultOptions
|
|
79
84
|
global.getApp = function () {
|
|
85
|
+
if (!isBrowser) {
|
|
86
|
+
console.error('[Mpx runtime error]: Dangerous API! global.getApp method is running in non browser environments')
|
|
87
|
+
return
|
|
88
|
+
}
|
|
80
89
|
return appData
|
|
81
90
|
}
|
|
82
91
|
} else {
|
|
@@ -3,7 +3,7 @@ import mergeOptions from '../../../core/mergeOptions'
|
|
|
3
3
|
import { diffAndCloneA, hasOwn } from '@mpxjs/utils'
|
|
4
4
|
import { getCurrentInstance as getCurrentVueInstance } from '../../export/index'
|
|
5
5
|
import MpxProxy, { setCurrentInstance, unsetCurrentInstance } from '../../../core/proxy'
|
|
6
|
-
import { BEFORECREATE, BEFOREUPDATE, UPDATED, BEFOREUNMOUNT, UNMOUNTED } from '../../../core/innerLifecycle'
|
|
6
|
+
import { BEFORECREATE, BEFOREUPDATE, UPDATED, BEFOREUNMOUNT, UNMOUNTED, SERVERPREFETCH } from '../../../core/innerLifecycle'
|
|
7
7
|
|
|
8
8
|
function filterOptions (options) {
|
|
9
9
|
const newOptions = {}
|
|
@@ -79,6 +79,9 @@ export function getDefaultOptions (type, { rawOptions = {} }) {
|
|
|
79
79
|
},
|
|
80
80
|
destroyed () {
|
|
81
81
|
if (this.__mpxProxy) this.__mpxProxy.callHook(UNMOUNTED)
|
|
82
|
+
},
|
|
83
|
+
serverPrefetch () {
|
|
84
|
+
if (this.__mpxProxy) return this.__mpxProxy.callHook(SERVERPREFETCH)
|
|
82
85
|
}
|
|
83
86
|
}]
|
|
84
87
|
// 为了在builtMixin中可以使用某些rootMixin实现的特性(如数据响应等),此处builtInMixin在rootMixin之后执行,但是当builtInMixin使用存在对应内建生命周期的目标平台声明周期写法时,可能会出现用户生命周期比builtInMixin中的生命周期先执行的情况,为了避免这种情况发生,builtInMixin应该尽可能使用内建生命周期来编写
|