@mpxjs/core 2.8.62 → 2.8.64-bridgetest
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 +12 -10
- 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/createApp.js +21 -12
- package/src/platform/patch/web/getDefaultOptions.js +4 -1
- package/src/platform/patch/web/lifecycle.js +5 -2
- 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.8.
|
|
3
|
+
"version": "2.8.64-bridgetest",
|
|
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.8.
|
|
22
|
+
"@mpxjs/utils": "^2.8.64-bridgetest",
|
|
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": "4080623bc3f493d1cfb7a506dffaec0f79084af6"
|
|
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
|
@@ -314,17 +314,19 @@ export function mergeToArray (parent, child, key) {
|
|
|
314
314
|
function composeHooks (target, includes) {
|
|
315
315
|
Object.keys(target).forEach(key => {
|
|
316
316
|
if (!includes || includes[key]) {
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
317
|
+
const hooks = target[key]
|
|
318
|
+
if (Array.isArray(hooks)) {
|
|
319
|
+
target[key] = function (...args) {
|
|
320
|
+
let result
|
|
321
|
+
for (let i = 0; i < hooks.length; i++) {
|
|
322
|
+
if (typeof hooks[i] === 'function') {
|
|
323
|
+
const data = hooks[i].apply(this, args)
|
|
324
|
+
data !== undefined && (result = data)
|
|
325
|
+
}
|
|
324
326
|
}
|
|
327
|
+
return result
|
|
325
328
|
}
|
|
326
|
-
|
|
327
|
-
})
|
|
329
|
+
}
|
|
328
330
|
}
|
|
329
331
|
})
|
|
330
332
|
}
|
|
@@ -352,7 +354,7 @@ function transformHOOKS (options) {
|
|
|
352
354
|
const componentHooksMap = makeMap(convertRule.lifecycle.component)
|
|
353
355
|
for (const key in options) {
|
|
354
356
|
// 使用Component创建page实例,页面专属生命周期&自定义方法需写在methods内部
|
|
355
|
-
if (typeof options[key] === 'function' && key !== 'dataFn' && key !== 'setup' && !componentHooksMap[key]) {
|
|
357
|
+
if (typeof options[key] === 'function' && key !== 'dataFn' && key !== 'setup' && key !== 'serverPrefetch' && !componentHooksMap[key]) {
|
|
356
358
|
if (!options.methods) options.methods = {}
|
|
357
359
|
options.methods[key] = options[key]
|
|
358
360
|
delete options[key]
|
package/src/core/proxy.js
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
BEFOREUPDATE,
|
|
38
38
|
UPDATED,
|
|
39
39
|
BEFOREUNMOUNT,
|
|
40
|
+
SERVERPREFETCH,
|
|
40
41
|
UNMOUNTED,
|
|
41
42
|
ONLOAD,
|
|
42
43
|
ONSHOW,
|
|
@@ -659,6 +660,7 @@ export const onLoad = createHook(ONLOAD)
|
|
|
659
660
|
export const onShow = createHook(ONSHOW)
|
|
660
661
|
export const onHide = createHook(ONHIDE)
|
|
661
662
|
export const onResize = createHook(ONRESIZE)
|
|
663
|
+
export const onServerPrefetch = createHook(SERVERPREFETCH)
|
|
662
664
|
export const onPullDownRefresh = createHook('__onPullDownRefresh__')
|
|
663
665
|
export const onReachBottom = createHook('__onReachBottom__')
|
|
664
666
|
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
|
})
|
|
@@ -1,11 +1,12 @@
|
|
|
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
|
+
import { mergeLifecycle } from '../convertor/mergeLifecycle'
|
|
5
6
|
import * as webLifecycle from '../platform/patch/web/lifecycle'
|
|
6
7
|
import Mpx from '../index'
|
|
7
8
|
|
|
8
|
-
const webAppHooksMap = makeMap(webLifecycle.LIFECYCLE.
|
|
9
|
+
const webAppHooksMap = makeMap(mergeLifecycle(webLifecycle.LIFECYCLE).app)
|
|
9
10
|
|
|
10
11
|
function filterOptions (options, appData) {
|
|
11
12
|
const newOptions = {}
|
|
@@ -35,7 +36,7 @@ export default function createApp (option, config = {}) {
|
|
|
35
36
|
created () {
|
|
36
37
|
Object.assign(this, Mpx.prototype)
|
|
37
38
|
Object.assign(this, appData)
|
|
38
|
-
const current =
|
|
39
|
+
const current = this.$root.$options?.router?.currentRoute || {}
|
|
39
40
|
const options = {
|
|
40
41
|
path: current.path && current.path.replace(/^\//, ''),
|
|
41
42
|
query: current.query,
|
|
@@ -49,19 +50,24 @@ export default function createApp (option, config = {}) {
|
|
|
49
50
|
hide: [],
|
|
50
51
|
error: []
|
|
51
52
|
}
|
|
52
|
-
if (
|
|
53
|
-
this.$options.onShow
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
53
|
+
if (isBrowser) {
|
|
54
|
+
if (this.$options.onShow) {
|
|
55
|
+
this.$options.onShow.call(this, options)
|
|
56
|
+
global.__mpxAppCbs.show.push(this.$options.onShow.bind(this))
|
|
57
|
+
}
|
|
58
|
+
if (this.$options.onHide) {
|
|
59
|
+
global.__mpxAppCbs.hide.push(this.$options.onHide.bind(this))
|
|
60
|
+
}
|
|
61
|
+
if (this.$options.onError) {
|
|
62
|
+
global.__mpxAppCbs.error.push(this.$options.onError.bind(this))
|
|
63
|
+
}
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
})
|
|
64
67
|
} else {
|
|
68
|
+
if (option.onAppInit) {
|
|
69
|
+
option.onAppInit()
|
|
70
|
+
}
|
|
65
71
|
builtInMixins.push({
|
|
66
72
|
onLaunch () {
|
|
67
73
|
Object.assign(this, Mpx.prototype)
|
|
@@ -77,6 +83,9 @@ export default function createApp (option, config = {}) {
|
|
|
77
83
|
global.__mpxOptionsMap = global.__mpxOptionsMap || {}
|
|
78
84
|
global.__mpxOptionsMap[global.currentModuleId] = defaultOptions
|
|
79
85
|
global.getApp = function () {
|
|
86
|
+
if (!isBrowser) {
|
|
87
|
+
console.error('[Mpx runtime error]: Dangerous API! global.getApp method is running in non browser environments')
|
|
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应该尽可能使用内建生命周期来编写
|
|
@@ -9,7 +9,8 @@ const COMPONENT_HOOKS = [
|
|
|
9
9
|
'deactivated',
|
|
10
10
|
'beforeDestroy',
|
|
11
11
|
'destroyed',
|
|
12
|
-
'errorCaptured'
|
|
12
|
+
'errorCaptured',
|
|
13
|
+
'serverPrefetch'
|
|
13
14
|
]
|
|
14
15
|
|
|
15
16
|
const PAGE_HOOKS = [
|
|
@@ -38,7 +39,9 @@ const APP_HOOKS = [
|
|
|
38
39
|
'onError',
|
|
39
40
|
'onPageNotFound',
|
|
40
41
|
'onUnhandledRejection',
|
|
41
|
-
'onThemeChange'
|
|
42
|
+
'onThemeChange',
|
|
43
|
+
'onSSRAppCreated',
|
|
44
|
+
'onAppInit'
|
|
42
45
|
]
|
|
43
46
|
|
|
44
47
|
export const LIFECYCLE = {
|