@mpxjs/core 2.8.24 → 2.8.25-alpha.12
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/global.d.ts +1 -1
- package/README.md +0 -1
- package/package.json +5 -3
- package/src/convertor/convertor.js +6 -0
- package/src/convertor/getConvertMode.js +1 -0
- package/src/convertor/wxToTenon.js +86 -0
- package/src/core/proxy.js +5 -5
- package/src/index.js +1 -1
- package/src/platform/builtInMixins/index.js +5 -0
- package/src/platform/builtInMixins/pageStatusMixin.tenon.js +40 -0
- package/src/platform/builtInMixins/proxyEventMixin.tenon.js +46 -0
- package/src/platform/createApp.js +8 -1
- package/src/platform/export/index.tenon.js +75 -0
- package/src/platform/patch/builtInKeysMap.js +1 -1
- package/src/platform/patch/index.js +5 -2
- package/src/platform/patch/tenon/getDefaultOptions.js +97 -0
- package/src/platform/patch/tenon/lifecycle.js +48 -0
- package/src/vue.tenon.js +13 -0
package/@types/global.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// declaration for mpx mode
|
|
2
|
-
declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | '
|
|
2
|
+
declare let __mpx_mode__: 'wx' | 'ali' | 'swan' | 'qq' | 'tt' | 'dd' | 'qa' | 'jd' | 'web' | 'tenon'
|
|
3
3
|
|
|
4
4
|
// declaration for mpx env
|
|
5
5
|
declare let __mpx_env__: string
|
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/core",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.25-alpha.12",
|
|
4
4
|
"description": "mpx runtime core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"miniprogram",
|
|
@@ -19,11 +19,13 @@
|
|
|
19
19
|
],
|
|
20
20
|
"main": "src/index.js",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@mpxjs/utils": "^2.8.
|
|
22
|
+
"@mpxjs/utils": "^2.8.23-alpha",
|
|
23
23
|
"lodash": "^4.1.1",
|
|
24
24
|
"miniprogram-api-typings": "^3.0.2"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
+
"@hummer/tenon-store": "^1.7.0",
|
|
28
|
+
"@hummer/tenon-vue": "^1.5.1",
|
|
27
29
|
"@mpxjs/api-proxy": "^2.7.44",
|
|
28
30
|
"@mpxjs/store": "^2.8.0",
|
|
29
31
|
"vue": "^2.7.10",
|
|
@@ -47,5 +49,5 @@
|
|
|
47
49
|
"url": "https://github.com/didi/mpx/issues"
|
|
48
50
|
},
|
|
49
51
|
"sideEffects": false,
|
|
50
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "faf3231b0c19d3a72f9711dbf03bc2c9b431c8c6"
|
|
51
53
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
|
|
2
2
|
import * as aliLifecycle from '../platform/patch/ali/lifecycle'
|
|
3
3
|
import * as webLifecycle from '../platform/patch/web/lifecycle'
|
|
4
|
+
import * as tenonLifecycle from '../platform/patch/tenon/lifecycle'
|
|
4
5
|
import * as swanLifecycle from '../platform/patch/swan/lifecycle'
|
|
5
6
|
import { mergeLifecycle } from './mergeLifecycle'
|
|
6
7
|
import { error } from '@mpxjs/utils'
|
|
7
8
|
import wxToAliRule from './wxToAli'
|
|
8
9
|
import wxToWebRule from './wxToWeb'
|
|
10
|
+
import wxToTenonRule from './wxToTenon'
|
|
9
11
|
import wxToSwanRule from './wxToSwan'
|
|
10
12
|
import wxToQqRule from './wxToQq'
|
|
11
13
|
import wxToTtRule from './wxToTt'
|
|
@@ -19,6 +21,9 @@ let pageMode
|
|
|
19
21
|
if (__mpx_mode__ === 'web') {
|
|
20
22
|
lifecycleInfo = webLifecycle
|
|
21
23
|
pageMode = ''
|
|
24
|
+
} else if (__mpx_mode__ === 'tenon') {
|
|
25
|
+
lifecycleInfo = tenonLifecycle
|
|
26
|
+
pageMode = ''
|
|
22
27
|
} else if (__mpx_mode__ === 'ali') {
|
|
23
28
|
lifecycleInfo = aliLifecycle
|
|
24
29
|
pageMode = ''
|
|
@@ -50,6 +55,7 @@ const rulesMap = {
|
|
|
50
55
|
local: { ...defaultConvertRule },
|
|
51
56
|
default: defaultConvertRule,
|
|
52
57
|
wxToWeb: wxToWebRule,
|
|
58
|
+
wxToTenon: wxToTenonRule,
|
|
53
59
|
wxToAli: wxToAliRule,
|
|
54
60
|
wxToSwan: wxToSwanRule,
|
|
55
61
|
wxToQq: { ...defaultConvertRule, ...wxToQqRule },
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as wxLifecycle from '../platform/patch/wx/lifecycle'
|
|
2
|
+
import * as tenonLifecycle from '../platform/patch/tenon/lifecycle'
|
|
3
|
+
import { mergeLifecycle } from './mergeLifecycle'
|
|
4
|
+
import { error, isObject, diffAndCloneA, hasOwn } from '@mpxjs/utils'
|
|
5
|
+
import { implemented } from '../core/implement'
|
|
6
|
+
import { CREATED, UNMOUNTED } from '../core/innerLifecycle'
|
|
7
|
+
|
|
8
|
+
// 暂不支持的wx选项,后期需要各种花式支持
|
|
9
|
+
const unsupported = [
|
|
10
|
+
'moved',
|
|
11
|
+
'definitionFilter',
|
|
12
|
+
'onShareAppMessage',
|
|
13
|
+
'activated',
|
|
14
|
+
'deactivated',
|
|
15
|
+
'pageShow',
|
|
16
|
+
'pageHide',
|
|
17
|
+
'onPullDownRefresh',
|
|
18
|
+
'onReachBottom',
|
|
19
|
+
'onPageScroll',
|
|
20
|
+
'onTabItemTap',
|
|
21
|
+
'onResize',
|
|
22
|
+
'onUnhandledRejection',
|
|
23
|
+
'onThemeChange'
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
function convertErrorDesc (key) {
|
|
27
|
+
error(`Options.${key} is not supported in runtime conversion from wx to tenon.`, global.currentResource)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function notSupportTip (options) {
|
|
31
|
+
unsupported.forEach(key => {
|
|
32
|
+
if (options[key]) {
|
|
33
|
+
if (!implemented[key]) {
|
|
34
|
+
process.env.NODE_ENV !== 'production' && convertErrorDesc(key)
|
|
35
|
+
delete options[key]
|
|
36
|
+
} else if (implemented[key].remove) {
|
|
37
|
+
delete options[key]
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default {
|
|
44
|
+
lifecycle: mergeLifecycle(wxLifecycle.LIFECYCLE),
|
|
45
|
+
lifecycle2: mergeLifecycle(tenonLifecycle.LIFECYCLE),
|
|
46
|
+
pageMode: 'blend',
|
|
47
|
+
// support传递为true以将methods外层的方法函数合入methods中
|
|
48
|
+
support: true,
|
|
49
|
+
// wx输出tenon时额外将onLoad代理到CREATED
|
|
50
|
+
lifecycleProxyMap: Object.assign({}, wxLifecycle.lifecycleProxyMap, {
|
|
51
|
+
[CREATED]: ['created', 'attached', 'onLoad'],
|
|
52
|
+
[UNMOUNTED]: ['destroyed', 'detached', 'onUnload', 'unmounted']
|
|
53
|
+
}),
|
|
54
|
+
convert (options) {
|
|
55
|
+
const props = Object.assign({}, options.properties, options.props)
|
|
56
|
+
if (props) {
|
|
57
|
+
Object.keys(props).forEach(key => {
|
|
58
|
+
const prop = props[key]
|
|
59
|
+
if (prop) {
|
|
60
|
+
if (hasOwn(prop, 'type')) {
|
|
61
|
+
const newProp = {}
|
|
62
|
+
if (hasOwn(prop, 'optionalTypes')) {
|
|
63
|
+
newProp.type = [prop.type, ...prop.optionalTypes]
|
|
64
|
+
} else {
|
|
65
|
+
newProp.type = prop.type
|
|
66
|
+
}
|
|
67
|
+
if (hasOwn(prop, 'value')) {
|
|
68
|
+
// vue中对于引用类型数据需要使用函数返回
|
|
69
|
+
newProp.default = isObject(prop.value)
|
|
70
|
+
? function propFn () {
|
|
71
|
+
return diffAndCloneA(prop.value).clone
|
|
72
|
+
}
|
|
73
|
+
: prop.value
|
|
74
|
+
}
|
|
75
|
+
props[key] = newProp
|
|
76
|
+
} else {
|
|
77
|
+
props[key] = prop
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
options.props = props
|
|
82
|
+
delete options.properties
|
|
83
|
+
}
|
|
84
|
+
notSupportTip(options)
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/core/proxy.js
CHANGED
|
@@ -102,7 +102,7 @@ export default class MpxProxy {
|
|
|
102
102
|
this.ignoreProxyMap = makeMap(Mpx.config.ignoreProxyWhiteList)
|
|
103
103
|
// 收集setup中动态注册的hooks,小程序与web环境都需要
|
|
104
104
|
this.hooks = {}
|
|
105
|
-
if (__mpx_mode__ !== 'web') {
|
|
105
|
+
if (__mpx_mode__ !== 'web' && __mpx_mode__ !== 'tenon') {
|
|
106
106
|
this.scope = effectScope(true)
|
|
107
107
|
// props响应式数据代理
|
|
108
108
|
this.props = {}
|
|
@@ -124,8 +124,8 @@ export default class MpxProxy {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
created () {
|
|
127
|
-
if (__mpx_mode__ !== 'web') {
|
|
128
|
-
// web中BEFORECREATE钩子通过vue的beforeCreate钩子单独驱动
|
|
127
|
+
if (__mpx_mode__ !== 'web' && __mpx_mode__ !== 'tenon') {
|
|
128
|
+
// web和tenon中BEFORECREATE钩子通过vue的beforeCreate钩子单独驱动
|
|
129
129
|
this.callHook(BEFORECREATE)
|
|
130
130
|
setCurrentInstance(this)
|
|
131
131
|
this.initProps()
|
|
@@ -139,7 +139,7 @@ export default class MpxProxy {
|
|
|
139
139
|
this.state = CREATED
|
|
140
140
|
this.callHook(CREATED)
|
|
141
141
|
|
|
142
|
-
if (__mpx_mode__ !== 'web') {
|
|
142
|
+
if (__mpx_mode__ !== 'web' && __mpx_mode__ !== 'tenon') {
|
|
143
143
|
this.initRender()
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -210,7 +210,7 @@ export default class MpxProxy {
|
|
|
210
210
|
}
|
|
211
211
|
// 挂载$rawOptions
|
|
212
212
|
this.target.$rawOptions = this.options
|
|
213
|
-
if (__mpx_mode__ !== 'web') {
|
|
213
|
+
if (__mpx_mode__ !== 'web' && __mpx_mode__ !== 'tenon') {
|
|
214
214
|
// 挂载$watch
|
|
215
215
|
this.target.$watch = this.watch.bind(this)
|
|
216
216
|
// 强制执行render
|
package/src/index.js
CHANGED
|
@@ -118,7 +118,7 @@ function factory () {
|
|
|
118
118
|
Object.assign(Mpx, APIs)
|
|
119
119
|
Object.assign(Mpx.prototype, InstanceAPIs)
|
|
120
120
|
// 输出web时在mpx上挂载Vue对象
|
|
121
|
-
if (__mpx_mode__ === 'web') {
|
|
121
|
+
if (__mpx_mode__ === 'web' || __mpx_mode__ === 'tenon') {
|
|
122
122
|
Mpx.__vue = Vue
|
|
123
123
|
}
|
|
124
124
|
return Mpx
|
|
@@ -26,6 +26,11 @@ export default function getBuiltInMixins (options, type) {
|
|
|
26
26
|
// 由于relation可能是通过mixin注入的,不能通过当前的用户options中是否存在relations来简单判断是否注入该项mixin
|
|
27
27
|
relationsMixin(type)
|
|
28
28
|
]
|
|
29
|
+
} else if (__mpx_mode__ === 'tenon') {
|
|
30
|
+
bulitInMixins = [
|
|
31
|
+
proxyEventMixin(),
|
|
32
|
+
pageStatusMixin(type)
|
|
33
|
+
]
|
|
29
34
|
} else {
|
|
30
35
|
// 此为差异抹平类mixins,原生模式下也需要注入也抹平平台差异
|
|
31
36
|
bulitInMixins = [
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CREATED, ONSHOW, ONHIDE } from '../../core/innerLifecycle'
|
|
2
|
+
|
|
3
|
+
export default function pageStatusMixin (mixinType) {
|
|
4
|
+
if (mixinType === 'page') {
|
|
5
|
+
return {
|
|
6
|
+
data: {
|
|
7
|
+
mpxPageStatus: 'show'
|
|
8
|
+
},
|
|
9
|
+
onShow () {
|
|
10
|
+
this.mpxPageStatus = 'show'
|
|
11
|
+
this.__mpxProxy.callHook(ONSHOW)
|
|
12
|
+
},
|
|
13
|
+
onHide () {
|
|
14
|
+
this.mpxPageStatus = 'hide'
|
|
15
|
+
this.__mpxProxy.callHook(ONHIDE)
|
|
16
|
+
},
|
|
17
|
+
onBack () {
|
|
18
|
+
return this.onBack && this.onBack()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// components
|
|
23
|
+
return {
|
|
24
|
+
[CREATED] () {
|
|
25
|
+
const pageInstance = global.__currentPageInstance
|
|
26
|
+
if (!pageInstance) return
|
|
27
|
+
this.$watch(
|
|
28
|
+
() => pageInstance.mpxPageStatus,
|
|
29
|
+
status => {
|
|
30
|
+
if (!status) return
|
|
31
|
+
const pageLifetimes = (this.$rawOptions && this.$rawOptions.pageLifetimes) || {}
|
|
32
|
+
// show & hide
|
|
33
|
+
if (status in pageLifetimes && typeof pageLifetimes[status] === 'function') {
|
|
34
|
+
pageLifetimes[status].call(this)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { setByPath } from '@mpxjs/utils'
|
|
2
|
+
|
|
3
|
+
export default function proxyEventMixin () {
|
|
4
|
+
const methods = {
|
|
5
|
+
triggerEvent (eventName, eventDetail) {
|
|
6
|
+
return this.$emit(eventName, {
|
|
7
|
+
type: eventName,
|
|
8
|
+
detail: eventDetail
|
|
9
|
+
})
|
|
10
|
+
},
|
|
11
|
+
__model (expr, $event, valuePath = ['value'], filterMethod) {
|
|
12
|
+
const innerFilter = {
|
|
13
|
+
trim: val => typeof val === 'string' && val.trim()
|
|
14
|
+
}
|
|
15
|
+
const originValue = valuePath.reduce((acc, cur) => acc[cur], $event.detail)
|
|
16
|
+
const value = filterMethod ? (innerFilter[filterMethod] ? innerFilter[filterMethod](originValue) : typeof this[filterMethod] === 'function' && this[filterMethod]) : originValue
|
|
17
|
+
setByPath(this, expr, value)
|
|
18
|
+
},
|
|
19
|
+
getOpenerEventChannel () {
|
|
20
|
+
const router = global.__mpxRouter
|
|
21
|
+
const eventChannel = router && router.__mpxAction && router.__mpxAction.eventChannel
|
|
22
|
+
return eventChannel
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return {
|
|
27
|
+
beforeCreate () {
|
|
28
|
+
const modelEvent = this.$attrs.mpxModelEvent
|
|
29
|
+
const modelEventId = this.$attrs.mpxModelEventId
|
|
30
|
+
if (modelEvent && modelEventId) {
|
|
31
|
+
Hummer.notifyCenter.addEventListener(modelEventId, (e) => {
|
|
32
|
+
this.$emit('mpxModel', e)
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
beforeDestroy () {
|
|
37
|
+
const modelEvent = this.$attrs.mpxModelEvent
|
|
38
|
+
const modelEventId = this.$attrs.mpxModelEventId
|
|
39
|
+
if (modelEvent && modelEventId) {
|
|
40
|
+
Hummer.notifyCenter.removeEventListener(modelEventId)
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
methods
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -61,6 +61,13 @@ export default function createApp (option, config = {}) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
})
|
|
64
|
+
} else if (__mpx_mode__ === 'tenon') {
|
|
65
|
+
// todo add tenon mixins
|
|
66
|
+
builtInMixins.push({
|
|
67
|
+
onLaunch () {
|
|
68
|
+
// console.log('tenon mixins')
|
|
69
|
+
}
|
|
70
|
+
})
|
|
64
71
|
} else {
|
|
65
72
|
builtInMixins.push({
|
|
66
73
|
onLaunch () {
|
|
@@ -73,7 +80,7 @@ export default function createApp (option, config = {}) {
|
|
|
73
80
|
rawOptions.mixins = builtInMixins
|
|
74
81
|
const defaultOptions = filterOptions(spreadProp(mergeOptions(rawOptions, 'app', false), 'methods'), appData)
|
|
75
82
|
|
|
76
|
-
if (__mpx_mode__ === 'web') {
|
|
83
|
+
if (__mpx_mode__ === 'web' || __mpx_mode__ === 'tenon') {
|
|
77
84
|
global.__mpxOptionsMap = global.__mpxOptionsMap || {}
|
|
78
85
|
global.__mpxOptionsMap[global.currentModuleId] = defaultOptions
|
|
79
86
|
global.getApp = function () {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {
|
|
2
|
+
effectScope as vueEffectScope,
|
|
3
|
+
getCurrentScope as getCurrentVueScope,
|
|
4
|
+
onScopeDispose
|
|
5
|
+
} from '@hummer/tenon-vue'
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
hasOwn,
|
|
9
|
+
isValidArrayIndex
|
|
10
|
+
} from '@mpxjs/utils'
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
// watch
|
|
14
|
+
watchEffect,
|
|
15
|
+
watchSyncEffect,
|
|
16
|
+
watchPostEffect,
|
|
17
|
+
watch,
|
|
18
|
+
// reactive
|
|
19
|
+
reactive,
|
|
20
|
+
isReactive,
|
|
21
|
+
shallowReactive,
|
|
22
|
+
markRaw,
|
|
23
|
+
// ref
|
|
24
|
+
ref,
|
|
25
|
+
unref,
|
|
26
|
+
toRef,
|
|
27
|
+
toRefs,
|
|
28
|
+
isRef,
|
|
29
|
+
customRef,
|
|
30
|
+
shallowRef,
|
|
31
|
+
triggerRef,
|
|
32
|
+
// computed
|
|
33
|
+
computed,
|
|
34
|
+
// instance
|
|
35
|
+
getCurrentInstance
|
|
36
|
+
} from '@hummer/tenon-vue'
|
|
37
|
+
|
|
38
|
+
export function set (target, key, val) {
|
|
39
|
+
if (Array.isArray(target) && isValidArrayIndex(key)) {
|
|
40
|
+
target.length = Math.max(target.length, key)
|
|
41
|
+
target.splice(key, 1, val)
|
|
42
|
+
return val
|
|
43
|
+
}
|
|
44
|
+
target[key] = val
|
|
45
|
+
return val
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function del (target, key) {
|
|
49
|
+
if (Array.isArray(target) && isValidArrayIndex(key)) {
|
|
50
|
+
target.splice(key, 1)
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
if (!hasOwn(target, key)) {
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
delete target[key]
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const noop = () => {
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const fixEffectScope = (scope) => {
|
|
63
|
+
scope.pause = noop
|
|
64
|
+
scope.resume = noop
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
|
|
68
|
+
const getCurrentScope = () => fixEffectScope(getCurrentVueScope())
|
|
69
|
+
|
|
70
|
+
export {
|
|
71
|
+
// effectScope
|
|
72
|
+
effectScope,
|
|
73
|
+
getCurrentScope,
|
|
74
|
+
onScopeDispose
|
|
75
|
+
}
|
|
@@ -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 { getDefaultOptions as getTenonDefaultOptions } from './tenon/getDefaultOptions'
|
|
7
8
|
import { error } from '@mpxjs/utils'
|
|
8
9
|
|
|
9
10
|
export default function createFactory (type) {
|
|
@@ -11,7 +12,7 @@ export default function createFactory (type) {
|
|
|
11
12
|
options.__nativeRender__ = !!isNative
|
|
12
13
|
options.__type__ = type
|
|
13
14
|
let ctor
|
|
14
|
-
if (__mpx_mode__ !== 'web') {
|
|
15
|
+
if (__mpx_mode__ !== 'web' && __mpx_mode__ !== 'tenon') {
|
|
15
16
|
if (customCtor) {
|
|
16
17
|
ctor = customCtor
|
|
17
18
|
customCtorType = customCtorType || type
|
|
@@ -41,6 +42,8 @@ export default function createFactory (type) {
|
|
|
41
42
|
let getDefaultOptions
|
|
42
43
|
if (__mpx_mode__ === 'web') {
|
|
43
44
|
getDefaultOptions = getWebDefaultOptions
|
|
45
|
+
} else if (__mpx_mode__ === 'tenon') {
|
|
46
|
+
getDefaultOptions = getTenonDefaultOptions
|
|
44
47
|
} else if (__mpx_mode__ === 'ali') {
|
|
45
48
|
getDefaultOptions = getAliDefaultOptions
|
|
46
49
|
} else if (__mpx_mode__ === 'swan') {
|
|
@@ -57,7 +60,7 @@ export default function createFactory (type) {
|
|
|
57
60
|
// 将合并后的用户定义的rawOptions传入获取当前应该注入的内建mixins
|
|
58
61
|
rawOptions.mixins = getBuiltInMixins(rawOptions, type)
|
|
59
62
|
const defaultOptions = getDefaultOptions(type, { rawOptions, currentInject })
|
|
60
|
-
if (__mpx_mode__ === 'web') {
|
|
63
|
+
if (__mpx_mode__ === 'web' || __mpx_mode__ === 'tenon') {
|
|
61
64
|
global.__mpxOptionsMap = global.__mpxOptionsMap || {}
|
|
62
65
|
global.__mpxOptionsMap[global.currentModuleId] = defaultOptions
|
|
63
66
|
} else if (ctor) {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import builtInKeysMap from '../builtInKeysMap'
|
|
2
|
+
import mergeOptions from '../../../core/mergeOptions'
|
|
3
|
+
import { getCurrentInstance as getCurrentVueInstance } from '../../export/index'
|
|
4
|
+
import MpxProxy, { setCurrentInstance, unsetCurrentInstance } from '../../../core/proxy'
|
|
5
|
+
import { diffAndCloneA, warn } from '@mpxjs/utils'
|
|
6
|
+
import { UPDATED, CREATED, MOUNTED, UNMOUNTED } from '../../../core/innerLifecycle'
|
|
7
|
+
|
|
8
|
+
function filterOptions (options) {
|
|
9
|
+
const newOptions = {}
|
|
10
|
+
Object.keys(options).forEach(key => {
|
|
11
|
+
if (builtInKeysMap[key]) {
|
|
12
|
+
return
|
|
13
|
+
}
|
|
14
|
+
if (key === 'data' || key === 'dataFn') {
|
|
15
|
+
newOptions.data = function mergeFn () {
|
|
16
|
+
return Object.assign(
|
|
17
|
+
diffAndCloneA(options.data || {}).clone,
|
|
18
|
+
options.dataFn && options.dataFn.call(this)
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
} else {
|
|
22
|
+
newOptions[key] = options[key]
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
return newOptions
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function initProxy (context, rawOptions) {
|
|
29
|
+
if (!context.__mpxProxy) {
|
|
30
|
+
// 缓存options
|
|
31
|
+
context.$rawOptions = rawOptions
|
|
32
|
+
// 创建proxy对象
|
|
33
|
+
context.__mpxProxy = new MpxProxy(rawOptions, context)
|
|
34
|
+
// todo 待问题修复后需要还原
|
|
35
|
+
// context.__mpxProxy.callHook(CREATED, Hummer.pageInfo && Hummer.pageInfo.params && [Hummer.pageInfo.params])
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
|
|
40
|
+
const rawSetup = rawOptions.setup
|
|
41
|
+
if (rawSetup) {
|
|
42
|
+
rawOptions.setup = (props) => {
|
|
43
|
+
const { proxy: instance } = getCurrentVueInstance()
|
|
44
|
+
initProxy(instance, rawOptions)
|
|
45
|
+
setCurrentInstance(instance.__mpxProxy)
|
|
46
|
+
const newContext = {
|
|
47
|
+
triggerEvent: (eventName, eventDetail) => {
|
|
48
|
+
return instance.$emit(eventName, {
|
|
49
|
+
type: eventName,
|
|
50
|
+
detail: eventDetail
|
|
51
|
+
})
|
|
52
|
+
},
|
|
53
|
+
get refs () { return instance.$refs },
|
|
54
|
+
forceUpdate: instance.$forceUpdate.bind(instance),
|
|
55
|
+
selectComponent: () => {
|
|
56
|
+
warn('selectComponent is not supported in Tenon')
|
|
57
|
+
},
|
|
58
|
+
selectAllComponents: () => {
|
|
59
|
+
warn('selectAllComponents is not supported in Tenon')
|
|
60
|
+
},
|
|
61
|
+
createSelectorQuery: () => {
|
|
62
|
+
warn('createSelectorQuery is not supported in Tenon')
|
|
63
|
+
},
|
|
64
|
+
createIntersectionObserver: () => {
|
|
65
|
+
warn('createIntersectionObserver is not supported in Tenon')
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const setupRes = rawSetup(props, newContext)
|
|
69
|
+
unsetCurrentInstance(instance.__mpxProxy)
|
|
70
|
+
return setupRes
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const hookNames = type === 'page' ? ['onLoad', 'onReady', 'onUnload'] : ['created', 'mounted', 'unmounted']
|
|
75
|
+
const rootMixins = [{
|
|
76
|
+
[hookNames[0]] (...params) {
|
|
77
|
+
if (!this.__mpxProxy) {
|
|
78
|
+
initProxy(this, rawOptions, currentInject, params)
|
|
79
|
+
}
|
|
80
|
+
// todo 待问题修复后需要移除,目前逻辑是已经创建实例的情况下依旧会重复执行
|
|
81
|
+
this.__mpxProxy.callHook(CREATED, Hummer.pageInfo && Hummer.pageInfo.params && [Hummer.pageInfo.params])
|
|
82
|
+
},
|
|
83
|
+
[hookNames[1]] () {
|
|
84
|
+
this.__mpxProxy && this.__mpxProxy.callHook(MOUNTED, Hummer.pageInfo && Hummer.pageInfo.params && [Hummer.pageInfo.params])
|
|
85
|
+
},
|
|
86
|
+
updated () {
|
|
87
|
+
this.__mpxProxy && this.__mpxProxy.callHook(UPDATED)
|
|
88
|
+
},
|
|
89
|
+
[hookNames[2]] () {
|
|
90
|
+
this.__mpxProxy && this.__mpxProxy.callHook(UNMOUNTED)
|
|
91
|
+
}
|
|
92
|
+
}]
|
|
93
|
+
// 为了在builtMixin中可以使用某些rootMixin实现的特性(如数据响应等),此处builtInMixin在rootMixin之后执行,但是当builtInMixin使用存在对应内建生命周期的目标平台声明周期写法时,可能会出现用户生命周期比builtInMixin中的生命周期先执行的情况,为了避免这种情况发生,builtInMixin应该尽可能使用内建生命周期来编写
|
|
94
|
+
rawOptions.mixins = rawOptions.mixins ? rootMixins.concat(rawOptions.mixins) : rootMixins
|
|
95
|
+
rawOptions = mergeOptions(rawOptions, type, false)
|
|
96
|
+
return filterOptions(rawOptions)
|
|
97
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const COMPONENT_HOOKS = [
|
|
2
|
+
'beforeCreate',
|
|
3
|
+
'created',
|
|
4
|
+
'beforeMount',
|
|
5
|
+
'mounted',
|
|
6
|
+
'beforeUpdate',
|
|
7
|
+
'updated',
|
|
8
|
+
// 'activated',
|
|
9
|
+
// 'deactivated',
|
|
10
|
+
'beforeDestroy',
|
|
11
|
+
'destroyed',
|
|
12
|
+
'errorCaptured',
|
|
13
|
+
'beforeUnmount',
|
|
14
|
+
'unmounted'
|
|
15
|
+
// 'onPageNotFound'
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
const PAGE_HOOKS = [
|
|
19
|
+
...COMPONENT_HOOKS,
|
|
20
|
+
'onLoad',
|
|
21
|
+
'onReady',
|
|
22
|
+
'onShow',
|
|
23
|
+
'onHide',
|
|
24
|
+
'onUnload'
|
|
25
|
+
// 'onBack',
|
|
26
|
+
// 'onPullDownRefresh',
|
|
27
|
+
// 'onReachBottom',
|
|
28
|
+
// 'onPageScroll',
|
|
29
|
+
// 'onTabItemTap',
|
|
30
|
+
// 'onResize'
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
const APP_HOOKS = [
|
|
34
|
+
...COMPONENT_HOOKS,
|
|
35
|
+
'onLaunch',
|
|
36
|
+
'onShow',
|
|
37
|
+
'onHide',
|
|
38
|
+
'onError'
|
|
39
|
+
// 'onPageNotFound',
|
|
40
|
+
// 'onUnhandledRejection',
|
|
41
|
+
// 'onThemeChange'
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
export const LIFECYCLE = {
|
|
45
|
+
APP_HOOKS,
|
|
46
|
+
PAGE_HOOKS,
|
|
47
|
+
COMPONENT_HOOKS
|
|
48
|
+
}
|