@mpxjs/core 2.9.66 → 2.9.69-beta.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/global.d.ts +2 -0
- package/@types/index.d.ts +18 -2
- package/package.json +19 -7
- package/src/convertor/convertor.js +11 -32
- package/src/convertor/wxToAli.js +3 -3
- package/src/convertor/wxToReact.js +1 -1
- package/src/convertor/wxToSwan.js +3 -3
- package/src/convertor/wxToWeb.js +3 -3
- package/src/core/mergeOptions.js +1 -1
- package/src/core/proxy.js +86 -12
- package/src/dynamic/dynamicRenderMixin.js +2 -2
- package/src/index.js +3 -14
- package/src/observer/reactive.js +5 -4
- package/src/observer/ref.js +3 -2
- package/src/observer/scheduler.js +4 -0
- package/src/observer/watch.js +5 -4
- package/src/platform/builtInMixins/directiveHelperMixin.ios.js +4 -1
- package/src/platform/builtInMixins/styleHelperMixin.ios.js +28 -25
- package/src/platform/createApp.ios.js +110 -42
- package/src/platform/createApp.js +8 -8
- package/src/platform/env/event.js +108 -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 +1 -1
- package/src/platform/export/index.js +5 -0
- package/src/platform/export/index.web.js +3 -1
- package/src/platform/export/inject.js +68 -0
- package/src/platform/export/inject.web.js +1 -0
- package/src/platform/patch/builtInKeysMap.js +2 -0
- package/src/platform/patch/{ali/getDefaultOptions.js → getDefaultOptions.ali.js} +19 -6
- package/src/platform/patch/{react/getDefaultOptions.ios.js → getDefaultOptions.ios.js} +286 -200
- package/src/platform/patch/{wx/getDefaultOptions.js → getDefaultOptions.js} +20 -11
- package/src/platform/patch/{web/getDefaultOptions.js → getDefaultOptions.web.js} +9 -7
- package/src/platform/patch/index.js +4 -21
- package/src/platform/patch/{ali/lifecycle.js → lifecycle/index.ali.js} +2 -0
- package/src/platform/patch/lifecycle/index.js +1 -0
- package/src/platform/patch/{swan/lifecycle.js → lifecycle/index.swan.js} +2 -0
- package/src/platform/patch/{web/lifecycle.js → lifecycle/index.web.js} +4 -0
- package/src/platform/patch/{wx/lifecycle.js → lifecycle/index.wx.js} +2 -0
- package/src/runtime/createFactory.js +3 -0
- package/LICENSE +0 -433
- package/src/external/vue.js +0 -1
- package/src/external/vue.web.js +0 -6
- package/src/platform/builtInMixins/directiveHelperMixin.android.js +0 -2
- package/src/platform/builtInMixins/proxyEventMixin.android.js +0 -2
- package/src/platform/builtInMixins/refsMixin.android.js +0 -2
- package/src/platform/builtInMixins/styleHelperMixin.android.js +0 -2
- package/src/platform/createApp.android.js +0 -2
- package/src/platform/patch/react/getDefaultOptions.android.js +0 -1
- package/src/platform/patch/react/getDefaultOptions.js +0 -1
- package/src/platform/patch/swan/getDefaultOptions.js +0 -34
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { callWithErrorHandling, isFunction, isObject, warn } from '@mpxjs/utils'
|
|
2
|
+
import { currentInstance } from '../../core/proxy'
|
|
3
|
+
|
|
4
|
+
const providesMap = {
|
|
5
|
+
/** 全局 scope */
|
|
6
|
+
__app: Object.create(null),
|
|
7
|
+
/** 页面 scope */
|
|
8
|
+
__pages: Object.create(null)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
global.__mpxProvidesMap = providesMap
|
|
12
|
+
|
|
13
|
+
/** @internal createApp() 初始化应用层 scope provide */
|
|
14
|
+
export function initAppProvides (appOptions) {
|
|
15
|
+
const provideOpt = appOptions.provide
|
|
16
|
+
if (provideOpt) {
|
|
17
|
+
const provided = isFunction(provideOpt)
|
|
18
|
+
? callWithErrorHandling(provideOpt.bind(appOptions), appOptions, 'createApp provide function')
|
|
19
|
+
: provideOpt
|
|
20
|
+
if (isObject(provided)) {
|
|
21
|
+
providesMap.__app = provided
|
|
22
|
+
} else {
|
|
23
|
+
warn('App provides must be an object or a function that returns an object.')
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function resolvePageId (context) {
|
|
29
|
+
if (context && isFunction(context.getPageId)) {
|
|
30
|
+
return context.getPageId()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function resolvePageProvides (context) {
|
|
35
|
+
const pageId = resolvePageId(context)
|
|
36
|
+
return providesMap.__pages[pageId] || (providesMap.__pages[pageId] = Object.create(null))
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function provide (key, value) {
|
|
40
|
+
const instance = currentInstance
|
|
41
|
+
if (!instance) {
|
|
42
|
+
warn('provide() can only be used inside setup().')
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
// 小程序无法实现组件父级引用,所以 provide scope 设置为组件所在页面
|
|
46
|
+
const provides = resolvePageProvides(instance.target)
|
|
47
|
+
provides[key] = value
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function inject (key, defaultValue, treatDefaultAsFactory = false) {
|
|
51
|
+
const instance = currentInstance
|
|
52
|
+
if (!instance) {
|
|
53
|
+
warn('inject() can only be used inside setup()')
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
const provides = resolvePageProvides(instance.target)
|
|
57
|
+
if (key in provides) {
|
|
58
|
+
return provides[key]
|
|
59
|
+
} else if (key in providesMap.__app) {
|
|
60
|
+
return providesMap.__app[key]
|
|
61
|
+
} else if (arguments.length > 1) {
|
|
62
|
+
return treatDefaultAsFactory && isFunction(defaultValue)
|
|
63
|
+
? defaultValue.call(instance && instance.target)
|
|
64
|
+
: defaultValue
|
|
65
|
+
} else {
|
|
66
|
+
warn(`injection "${String(key)}" not found.`)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { provide, inject } from 'vue'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import MpxProxy from '
|
|
2
|
-
import builtInKeysMap from '
|
|
3
|
-
import mergeOptions from '
|
|
4
|
-
import { error, diffAndCloneA, hasOwn, noop } from '@mpxjs/utils'
|
|
1
|
+
import MpxProxy from '../../core/proxy'
|
|
2
|
+
import builtInKeysMap from './builtInKeysMap'
|
|
3
|
+
import mergeOptions from '../../core/mergeOptions'
|
|
4
|
+
import { error, diffAndCloneA, hasOwn, noop, wrapMethodsWithErrorHandling } from '@mpxjs/utils'
|
|
5
5
|
|
|
6
6
|
function transformApiForProxy (context, currentInject) {
|
|
7
7
|
const rawSetData = context.setData.bind(context)
|
|
@@ -100,12 +100,25 @@ function filterOptions (options, type) {
|
|
|
100
100
|
if (!hasOwn(newOptions, 'props')) {
|
|
101
101
|
newOptions.props = Object.assign({}, options.props, options.properties)
|
|
102
102
|
}
|
|
103
|
-
} else if (key === 'methods'
|
|
104
|
-
|
|
103
|
+
} else if (key === 'methods') {
|
|
104
|
+
const newMethods = wrapMethodsWithErrorHandling(options[key])
|
|
105
|
+
if (type === 'page') {
|
|
106
|
+
// 构造器为Page时抽取所有methods方法到顶层
|
|
107
|
+
Object.assign(newOptions, newMethods)
|
|
108
|
+
} else {
|
|
109
|
+
newOptions[key] = newMethods
|
|
110
|
+
}
|
|
111
|
+
} else if (key === 'behaviors') {
|
|
112
|
+
newOptions.mixins = options[key]
|
|
105
113
|
} else {
|
|
106
114
|
newOptions[key] = options[key]
|
|
107
115
|
}
|
|
108
116
|
})
|
|
117
|
+
if (newOptions.relations) {
|
|
118
|
+
// ali relations 需要设置 options.relations = true
|
|
119
|
+
newOptions.options = newOptions.options || {}
|
|
120
|
+
newOptions.options.relations = true
|
|
121
|
+
}
|
|
109
122
|
return newOptions
|
|
110
123
|
}
|
|
111
124
|
|