@mpxjs/core 2.9.70-alpha.0 → 2.9.71
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/LICENSE +433 -0
- package/package.json +9 -6
- package/src/convertor/convertor.js +0 -2
- package/src/convertor/getConvertMode.js +0 -1
- package/src/core/mergeOptions.js +3 -6
- package/src/core/proxy.js +17 -16
- package/src/index.js +3 -14
- package/src/observer/reactive.js +4 -3
- package/src/platform/builtInMixins/directiveHelperMixin.ios.js +4 -1
- package/src/platform/builtInMixins/index.js +0 -5
- package/src/platform/builtInMixins/proxyEventMixin.web.js +53 -5
- package/src/platform/builtInMixins/styleHelperMixin.ios.js +1 -1
- package/src/platform/createApp.ios.js +54 -54
- package/src/platform/createApp.js +26 -37
- package/src/platform/env/event.js +105 -0
- package/src/platform/env/index.ios.js +51 -0
- package/src/platform/env/index.js +8 -0
- package/src/platform/env/index.web.js +48 -0
- package/src/{external → platform/env}/vuePlugin.js +10 -4
- package/src/platform/export/index.js +1 -1
- package/src/platform/export/{apiInject.js → inject.js} +2 -3
- package/src/platform/patch/builtInKeysMap.js +1 -1
- package/src/platform/patch/getDefaultOptions.ios.js +18 -19
- package/src/platform/patch/getDefaultOptions.js +0 -2
- package/src/platform/patch/index.js +3 -3
- package/src/convertor/wxToTenon.js +0 -86
- package/src/external/vue.js +0 -1
- package/src/external/vue.tenon.js +0 -13
- package/src/external/vue.web.js +0 -6
- package/src/platform/builtInMixins/pageStatusMixin.tenon.js +0 -40
- package/src/platform/builtInMixins/proxyEventMixin.tenon.js +0 -46
- package/src/platform/export/apiInject.tenon.js +0 -1
- package/src/platform/export/index.tenon.js +0 -78
- package/src/platform/patch/getDefaultOptions.tenon.js +0 -99
- package/src/platform/patch/lifecycle/index.tenon.js +0 -52
- /package/src/platform/export/{apiInject.web.js → inject.web.js} +0 -0
|
@@ -11,11 +11,10 @@ const providesMap = {
|
|
|
11
11
|
global.__mpxProvidesMap = providesMap
|
|
12
12
|
|
|
13
13
|
/** @internal createApp() 初始化应用层 scope provide */
|
|
14
|
-
export function initAppProvides (
|
|
15
|
-
const provideOpt = appOptions.provide
|
|
14
|
+
export function initAppProvides (provideOpt, instance) {
|
|
16
15
|
if (provideOpt) {
|
|
17
16
|
const provided = isFunction(provideOpt)
|
|
18
|
-
? callWithErrorHandling(provideOpt.bind(
|
|
17
|
+
? callWithErrorHandling(provideOpt.bind(instance), instance, 'createApp provide function')
|
|
19
18
|
: provideOpt
|
|
20
19
|
if (isObject(provided)) {
|
|
21
20
|
providesMap.__app = provided
|
|
@@ -3,7 +3,7 @@ import * as ReactNative from 'react-native'
|
|
|
3
3
|
import { ReactiveEffect } from '../../observer/effect'
|
|
4
4
|
import { watch } from '../../observer/watch'
|
|
5
5
|
import { reactive, set, del } from '../../observer/reactive'
|
|
6
|
-
import { hasOwn, isFunction, noop, isObject, isArray, getByPath, collectDataset, hump2dash, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
|
|
6
|
+
import { hasOwn, isFunction, noop, isObject, isArray, getByPath, collectDataset, hump2dash, dash2hump, callWithErrorHandling, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
|
|
7
7
|
import MpxProxy from '../../core/proxy'
|
|
8
8
|
import { BEFOREUPDATE, ONLOAD, UPDATED, ONSHOW, ONHIDE, ONRESIZE, REACTHOOKSEXEC } from '../../core/innerLifecycle'
|
|
9
9
|
import mergeOptions from '../../core/mergeOptions'
|
|
@@ -52,20 +52,18 @@ function createEffect (proxy, components) {
|
|
|
52
52
|
proxy.effect = new ReactiveEffect(() => {
|
|
53
53
|
// reset instance
|
|
54
54
|
proxy.target.__resetInstance()
|
|
55
|
-
return proxy.target.__injectedRender(innerCreateElement, getComponent)
|
|
55
|
+
return callWithErrorHandling(proxy.target.__injectedRender.bind(proxy.target), proxy, 'render function', [innerCreateElement, getComponent])
|
|
56
56
|
}, () => queueJob(update), proxy.scope)
|
|
57
57
|
// render effect允许自触发
|
|
58
58
|
proxy.toggleRecurse(true)
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
function getRootProps (props) {
|
|
61
|
+
function getRootProps (props, validProps) {
|
|
62
62
|
const rootProps = {}
|
|
63
63
|
for (const key in props) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
rootProps[key] = props[key]
|
|
68
|
-
}
|
|
64
|
+
const altKey = dash2hump(key)
|
|
65
|
+
if (!hasOwn(validProps, key) && !hasOwn(validProps, altKey) && key !== 'children') {
|
|
66
|
+
rootProps[key] = props[key]
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
return rootProps
|
|
@@ -367,14 +365,10 @@ function usePageStatus (navigation, pageId) {
|
|
|
367
365
|
const blurSubscription = navigation.addListener('blur', () => {
|
|
368
366
|
pageStatusMap[pageId] = 'hide'
|
|
369
367
|
})
|
|
370
|
-
const unWatchAppFocusedState = watch(global.__mpxAppFocusedState, (value) => {
|
|
371
|
-
pageStatusMap[pageId] = value
|
|
372
|
-
})
|
|
373
368
|
|
|
374
369
|
return () => {
|
|
375
370
|
focusSubscription()
|
|
376
371
|
blurSubscription()
|
|
377
|
-
unWatchAppFocusedState()
|
|
378
372
|
del(pageStatusMap, pageId)
|
|
379
373
|
}
|
|
380
374
|
}, [navigation])
|
|
@@ -444,10 +438,17 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
444
438
|
|
|
445
439
|
useEffect(() => {
|
|
446
440
|
if (type === 'page') {
|
|
447
|
-
if (!global.
|
|
441
|
+
if (!global.__mpxAppHotLaunched && global.__mpxAppOnLaunch) {
|
|
448
442
|
global.__mpxAppOnLaunch(props.navigation)
|
|
449
443
|
}
|
|
450
|
-
|
|
444
|
+
const loadParams = {}
|
|
445
|
+
// 此处拿到的props.route.params内属性的value被进行过了一次decode, 不符合预期,此处额外进行一次encode来与微信对齐
|
|
446
|
+
if (isObject(props.route.params)) {
|
|
447
|
+
for (const key in props.route.params) {
|
|
448
|
+
loadParams[key] = encodeURIComponent(props.route.params[key])
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
proxy.callHook(ONLOAD, [loadParams])
|
|
451
452
|
}
|
|
452
453
|
proxy.mounted()
|
|
453
454
|
return () => {
|
|
@@ -474,7 +475,8 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
474
475
|
|
|
475
476
|
const root = useMemo(() => proxy.effect.run(), [finalMemoVersion])
|
|
476
477
|
if (root && root.props.ishost) {
|
|
477
|
-
|
|
478
|
+
// 对于组件未注册的属性继承到host节点上,如事件、样式和其他属性等
|
|
479
|
+
const rootProps = getRootProps(props, validProps)
|
|
478
480
|
rootProps.style = Object.assign({}, root.props.style, rootProps.style)
|
|
479
481
|
// update root props
|
|
480
482
|
return cloneElement(root, rootProps)
|
|
@@ -560,10 +562,7 @@ export function getDefaultOptions ({ type, rawOptions = {}, currentInject }) {
|
|
|
560
562
|
backgroundColor: pageConfig.backgroundColor || '#ffffff'
|
|
561
563
|
},
|
|
562
564
|
ref: rootRef,
|
|
563
|
-
onLayout
|
|
564
|
-
onTouchStart: () => {
|
|
565
|
-
ReactNative.Keyboard.isVisible() && ReactNative.Keyboard.dismiss()
|
|
566
|
-
}
|
|
565
|
+
onLayout
|
|
567
566
|
},
|
|
568
567
|
createElement(RouteContext.Provider,
|
|
569
568
|
{
|
|
@@ -23,13 +23,11 @@ function transformProperties (properties) {
|
|
|
23
23
|
} else {
|
|
24
24
|
newFiled = Object.assign({}, rawFiled)
|
|
25
25
|
}
|
|
26
|
-
const rawObserver = rawFiled?.observer
|
|
27
26
|
newFiled.observer = function (value, oldValue) {
|
|
28
27
|
if (this.__mpxProxy) {
|
|
29
28
|
this[key] = value
|
|
30
29
|
this.__mpxProxy.propsUpdated()
|
|
31
30
|
}
|
|
32
|
-
rawObserver && rawObserver.call(this, value, oldValue)
|
|
33
31
|
}
|
|
34
32
|
newProps[key] = newFiled
|
|
35
33
|
})
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import transferOptions from '../../core/transferOptions'
|
|
2
2
|
import getBuiltInMixins from '../builtInMixins/index'
|
|
3
3
|
import { getDefaultOptions } from './getDefaultOptions'
|
|
4
|
-
import { error, isReact, isWeb
|
|
4
|
+
import { error, isReact, isWeb } from '@mpxjs/utils'
|
|
5
5
|
|
|
6
6
|
export default function createFactory (type) {
|
|
7
7
|
return (options = {}, { isNative, customCtor, customCtorType } = {}) => {
|
|
8
8
|
options.__nativeRender__ = !!isNative
|
|
9
9
|
options.__type__ = type
|
|
10
10
|
let ctor
|
|
11
|
-
if (!isWeb && !isReact
|
|
11
|
+
if (!isWeb && !isReact) {
|
|
12
12
|
if (customCtor) {
|
|
13
13
|
ctor = customCtor
|
|
14
14
|
customCtorType = customCtorType || type
|
|
@@ -43,7 +43,7 @@ export default function createFactory (type) {
|
|
|
43
43
|
// 将合并后的用户定义的rawOptions传入获取当前应该注入的内建mixins
|
|
44
44
|
rawOptions.mixins = getBuiltInMixins({ type, rawOptions, currentInject })
|
|
45
45
|
const defaultOptions = getDefaultOptions({ type, rawOptions, currentInject })
|
|
46
|
-
if (isWeb || isReact
|
|
46
|
+
if (isWeb || isReact) {
|
|
47
47
|
global.__mpxOptionsMap = global.__mpxOptionsMap || {}
|
|
48
48
|
global.__mpxOptionsMap[currentInject.moduleId] = defaultOptions
|
|
49
49
|
} else if (ctor) {
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import * as wxLifecycle from '../platform/patch/lifecycle/index.wx'
|
|
2
|
-
import * as tenonLifecycle from '../platform/patch/lifecycle/index.tenon'
|
|
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/external/vue.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {}
|
package/src/external/vue.web.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { provide, inject } from '@hummer/tenon-vue'
|
|
@@ -1,78 +0,0 @@
|
|
|
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
|
-
provide,
|
|
37
|
-
inject
|
|
38
|
-
} from '@hummer/tenon-vue'
|
|
39
|
-
|
|
40
|
-
export function set (target, key, val) {
|
|
41
|
-
if (Array.isArray(target) && isValidArrayIndex(key)) {
|
|
42
|
-
target.length = Math.max(target.length, key)
|
|
43
|
-
target.splice(key, 1, val)
|
|
44
|
-
return val
|
|
45
|
-
}
|
|
46
|
-
target[key] = val
|
|
47
|
-
return val
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function del (target, key) {
|
|
51
|
-
if (Array.isArray(target) && isValidArrayIndex(key)) {
|
|
52
|
-
target.splice(key, 1)
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
if (!hasOwn(target, key)) {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
delete target[key]
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const noop = () => {
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const fixEffectScope = (scope) => {
|
|
65
|
-
scope.pause = noop
|
|
66
|
-
scope.resume = noop
|
|
67
|
-
return scope
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
|
|
71
|
-
const getCurrentScope = () => fixEffectScope(getCurrentVueScope())
|
|
72
|
-
|
|
73
|
-
export {
|
|
74
|
-
// effectScope
|
|
75
|
-
effectScope,
|
|
76
|
-
getCurrentScope,
|
|
77
|
-
onScopeDispose
|
|
78
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
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, wrapMethodsWithErrorHandling } 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 if (key === 'methods') {
|
|
22
|
-
newOptions[key] = wrapMethodsWithErrorHandling(options[key])
|
|
23
|
-
} else {
|
|
24
|
-
newOptions[key] = options[key]
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
return newOptions
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function initProxy (context, rawOptions) {
|
|
31
|
-
if (!context.__mpxProxy) {
|
|
32
|
-
// 缓存options
|
|
33
|
-
context.$rawOptions = rawOptions
|
|
34
|
-
// 创建proxy对象
|
|
35
|
-
context.__mpxProxy = new MpxProxy(rawOptions, context)
|
|
36
|
-
// todo 待问题修复后需要还原
|
|
37
|
-
// context.__mpxProxy.callHook(CREATED, Hummer.pageInfo && Hummer.pageInfo.params && [Hummer.pageInfo.params])
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function getDefaultOptions ({type, rawOptions = {}, currentInject }) {
|
|
42
|
-
const rawSetup = rawOptions.setup
|
|
43
|
-
if (rawSetup) {
|
|
44
|
-
rawOptions.setup = (props) => {
|
|
45
|
-
const { proxy: instance } = getCurrentVueInstance()
|
|
46
|
-
initProxy(instance, rawOptions)
|
|
47
|
-
setCurrentInstance(instance.__mpxProxy)
|
|
48
|
-
const newContext = {
|
|
49
|
-
triggerEvent: (eventName, eventDetail) => {
|
|
50
|
-
return instance.$emit(eventName, {
|
|
51
|
-
type: eventName,
|
|
52
|
-
detail: eventDetail
|
|
53
|
-
})
|
|
54
|
-
},
|
|
55
|
-
get refs () { return instance.$refs },
|
|
56
|
-
forceUpdate: instance.$forceUpdate.bind(instance),
|
|
57
|
-
selectComponent: () => {
|
|
58
|
-
warn('selectComponent is not supported in Tenon')
|
|
59
|
-
},
|
|
60
|
-
selectAllComponents: () => {
|
|
61
|
-
warn('selectAllComponents is not supported in Tenon')
|
|
62
|
-
},
|
|
63
|
-
createSelectorQuery: () => {
|
|
64
|
-
warn('createSelectorQuery is not supported in Tenon')
|
|
65
|
-
},
|
|
66
|
-
createIntersectionObserver: () => {
|
|
67
|
-
warn('createIntersectionObserver is not supported in Tenon')
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const setupRes = rawSetup(props, newContext)
|
|
71
|
-
unsetCurrentInstance(instance.__mpxProxy)
|
|
72
|
-
return setupRes
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const hookNames = type === 'page' ? ['onLoad', 'onReady', 'onUnload'] : ['created', 'mounted', 'unmounted']
|
|
77
|
-
const rootMixins = [{
|
|
78
|
-
[hookNames[0]] (...params) {
|
|
79
|
-
if (!this.__mpxProxy) {
|
|
80
|
-
initProxy(this, rawOptions, currentInject, params)
|
|
81
|
-
}
|
|
82
|
-
// todo 待问题修复后需要移除,目前逻辑是已经创建实例的情况下依旧会重复执行
|
|
83
|
-
this.__mpxProxy.callHook(CREATED, Hummer.pageInfo && Hummer.pageInfo.params && [Hummer.pageInfo.params])
|
|
84
|
-
},
|
|
85
|
-
[hookNames[1]] () {
|
|
86
|
-
this.__mpxProxy && this.__mpxProxy.callHook(MOUNTED, Hummer.pageInfo && Hummer.pageInfo.params && [Hummer.pageInfo.params])
|
|
87
|
-
},
|
|
88
|
-
updated () {
|
|
89
|
-
this.__mpxProxy && this.__mpxProxy.callHook(UPDATED)
|
|
90
|
-
},
|
|
91
|
-
[hookNames[2]] () {
|
|
92
|
-
this.__mpxProxy && this.__mpxProxy.callHook(UNMOUNTED)
|
|
93
|
-
}
|
|
94
|
-
}]
|
|
95
|
-
// 为了在builtMixin中可以使用某些rootMixin实现的特性(如数据响应等),此处builtInMixin在rootMixin之后执行,但是当builtInMixin使用存在对应内建生命周期的目标平台声明周期写法时,可能会出现用户生命周期比builtInMixin中的生命周期先执行的情况,为了避免这种情况发生,builtInMixin应该尽可能使用内建生命周期来编写
|
|
96
|
-
rawOptions.mixins = rawOptions.mixins ? rootMixins.concat(rawOptions.mixins) : rootMixins
|
|
97
|
-
rawOptions = mergeOptions(rawOptions, type, false)
|
|
98
|
-
return filterOptions(rawOptions)
|
|
99
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
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
|
-
}
|
|
49
|
-
|
|
50
|
-
export const pageMode = ''
|
|
51
|
-
|
|
52
|
-
export const lifecycleProxyMap = {}
|
|
File without changes
|