@mpxjs/core 2.7.0-beta.0 → 2.7.0
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
|
@@ -304,7 +304,8 @@ interface MpxConfig {
|
|
|
304
304
|
hookErrorHandler: (e: Error, target: ComponentIns<{}, {}, {}, {}, []>, hookName: string) => any | null
|
|
305
305
|
proxyEventHandler: (e: Event) => any | null
|
|
306
306
|
setDataHandler: (data: object, target: ComponentIns<{}, {}, {}, {}, []>) => any | null
|
|
307
|
-
forceRunWatcherSync: boolean
|
|
307
|
+
forceRunWatcherSync: boolean,
|
|
308
|
+
webRouteConfig: object
|
|
308
309
|
}
|
|
309
310
|
|
|
310
311
|
type SupportedMode = 'wx' | 'ali' | 'qq' | 'swan' | 'tt' | 'web' | 'qa'
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.7.0
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"src",
|
|
18
18
|
"@types"
|
|
19
19
|
],
|
|
20
|
+
"main": "src/index.js",
|
|
20
21
|
"dependencies": {
|
|
21
22
|
"lodash": "^4.1.1",
|
|
22
23
|
"miniprogram-api-typings": "^3.0.2"
|
|
@@ -40,5 +41,5 @@
|
|
|
40
41
|
"url": "https://github.com/didi/mpx/issues"
|
|
41
42
|
},
|
|
42
43
|
"sideEffects": false,
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "0f2454782bfca526bd281618b99b9aacb1ca2a75"
|
|
44
45
|
}
|
package/src/core/proxy.js
CHANGED
|
@@ -241,7 +241,7 @@ export default class MPXProxy {
|
|
|
241
241
|
if (typeof EXPORT_MPX.config.hookErrorHandler === 'function') {
|
|
242
242
|
EXPORT_MPX.config.hookErrorHandler(e, this.target, hookName)
|
|
243
243
|
} else {
|
|
244
|
-
|
|
244
|
+
throw e
|
|
245
245
|
}
|
|
246
246
|
}
|
|
247
247
|
}
|
|
@@ -4,7 +4,7 @@ import { getConvertMode } from '../convertor/getConvertMode'
|
|
|
4
4
|
import { findItem } from '../helper/utils'
|
|
5
5
|
import { warn } from '../helper/log'
|
|
6
6
|
|
|
7
|
-
export default function transferOptions (options, type
|
|
7
|
+
export default function transferOptions (options, type) {
|
|
8
8
|
let currentInject
|
|
9
9
|
if (global.currentInject && global.currentInject.moduleId === global.currentModuleId) {
|
|
10
10
|
currentInject = global.currentInject
|
|
@@ -26,10 +26,9 @@ export default function transferOptions (options, type, builtInMixins = []) {
|
|
|
26
26
|
// 转换mode
|
|
27
27
|
options.mpxConvertMode = options.mpxConvertMode || getConvertMode(global.currentSrcMode)
|
|
28
28
|
const rawOptions = mergeOptions(options, type)
|
|
29
|
-
|
|
30
|
-
rawOptions.mixins = builtInMixins
|
|
29
|
+
|
|
31
30
|
if (currentInject && currentInject.propKeys) {
|
|
32
|
-
const computedKeys = Object.keys(
|
|
31
|
+
const computedKeys = Object.keys(rawOptions.computed || {})
|
|
33
32
|
// 头条和百度小程序由于props传递为异步操作,通过props向子组件传递computed数据时,子组件无法在初始时(created/attached)获取到computed数据,如需进一步处理数据建议通过watch获取
|
|
34
33
|
currentInject.propKeys.forEach(key => {
|
|
35
34
|
if (findItem(computedKeys, key)) {
|
package/src/index.js
CHANGED
|
@@ -205,12 +205,13 @@ EXPORT_MPX.config = {
|
|
|
205
205
|
hookErrorHandler: null,
|
|
206
206
|
proxyEventHandler: null,
|
|
207
207
|
setDataHandler: null,
|
|
208
|
-
forceRunWatcherSync: false
|
|
208
|
+
forceRunWatcherSync: false,
|
|
209
|
+
webRouteConfig: {}
|
|
209
210
|
}
|
|
210
211
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
global.__mpx = EXPORT_MPX
|
|
213
|
+
|
|
214
|
+
if (__mpx_mode__ !== 'web') {
|
|
214
215
|
if (global.i18n) {
|
|
215
216
|
observe(global.i18n)
|
|
216
217
|
// 挂载翻译方法
|
|
@@ -3,6 +3,7 @@ import mergeOptions from '../core/mergeOptions'
|
|
|
3
3
|
import builtInKeysMap from './patch/builtInKeysMap'
|
|
4
4
|
import { makeMap, spreadProp } from '../helper/utils'
|
|
5
5
|
import * as webLifecycle from '../platform/patch/web/lifecycle'
|
|
6
|
+
import EXPORT_MPX from '../index'
|
|
6
7
|
|
|
7
8
|
const webAppHooksMap = makeMap(webLifecycle.LIFECYCLE.APP_HOOKS)
|
|
8
9
|
|
|
@@ -22,7 +23,12 @@ function filterOptions (options, appData) {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export default function createApp (option, config = {}) {
|
|
25
|
-
|
|
26
|
+
// 在App中挂载mpx对象供周边工具访问,如e2e测试
|
|
27
|
+
const builtInMixins = [{
|
|
28
|
+
getMpx () {
|
|
29
|
+
return EXPORT_MPX
|
|
30
|
+
}
|
|
31
|
+
}]
|
|
26
32
|
const appData = {}
|
|
27
33
|
if (__mpx_mode__ === 'web') {
|
|
28
34
|
builtInMixins.push({
|
|
@@ -62,7 +68,8 @@ export default function createApp (option, config = {}) {
|
|
|
62
68
|
}
|
|
63
69
|
})
|
|
64
70
|
}
|
|
65
|
-
const { rawOptions } = transferOptions(option, 'app'
|
|
71
|
+
const { rawOptions } = transferOptions(option, 'app')
|
|
72
|
+
rawOptions.mixins = builtInMixins
|
|
66
73
|
const defaultOptions = filterOptions(spreadProp(mergeOptions(rawOptions, 'app', false), 'methods'), appData)
|
|
67
74
|
|
|
68
75
|
if (__mpx_mode__ === 'web') {
|
|
@@ -4,6 +4,7 @@ import { getDefaultOptions as getWxDefaultOptions } from './wx/getDefaultOptions
|
|
|
4
4
|
import { getDefaultOptions as getAliDefaultOptions } from './ali/getDefaultOptions'
|
|
5
5
|
import { getDefaultOptions as getSwanDefaultOptions } from './swan/getDefaultOptions'
|
|
6
6
|
import { getDefaultOptions as getWebDefaultOptions } from './web/getDefaultOptions'
|
|
7
|
+
import { error } from '../../helper/log'
|
|
7
8
|
|
|
8
9
|
export default function createFactory (type) {
|
|
9
10
|
return (options, { isNative, customCtor, customCtorType } = {}) => {
|
|
@@ -23,6 +24,9 @@ export default function createFactory (type) {
|
|
|
23
24
|
if (global.currentCtorType === 'page') {
|
|
24
25
|
options.__pageCtor__ = true
|
|
25
26
|
}
|
|
27
|
+
if (global.currentResourceType && global.currentResourceType !== type) {
|
|
28
|
+
error(`The ${global.currentResourceType} [${global.currentResource}] is not supported to be created by ${type} constructor.`)
|
|
29
|
+
}
|
|
26
30
|
} else {
|
|
27
31
|
if (type === 'page') {
|
|
28
32
|
ctor = Page
|
|
@@ -45,9 +49,10 @@ export default function createFactory (type) {
|
|
|
45
49
|
getDefaultOptions = getWxDefaultOptions
|
|
46
50
|
}
|
|
47
51
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
const { rawOptions, currentInject } = transferOptions(options, type)
|
|
53
|
+
// 注入内建的mixins, 内建mixin是按原始平台编写的,所以合并规则和rootMixins保持一致
|
|
54
|
+
// 将合并后的用户定义的rawOptions传入获取当前应该注入的内建mixins
|
|
55
|
+
rawOptions.mixins = getBuiltInMixins(rawOptions, type)
|
|
51
56
|
const defaultOptions = getDefaultOptions(type, { rawOptions, currentInject })
|
|
52
57
|
if (__mpx_mode__ === 'web') {
|
|
53
58
|
global.currentOption = defaultOptions
|