@mpxjs/core 2.8.25-alpha → 2.8.25-alpha.4

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/core",
3
- "version": "2.8.25-alpha",
3
+ "version": "2.8.25-alpha.4",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -49,5 +49,5 @@
49
49
  "url": "https://github.com/didi/mpx/issues"
50
50
  },
51
51
  "sideEffects": false,
52
- "gitHead": "345dc10820535a06d9aee8d2a1e6cc735ba08882"
52
+ "gitHead": "9684484c1b348bcb8d8325df75a114ba9611811e"
53
53
  }
@@ -0,0 +1,51 @@
1
+ import {
2
+ effectScope as vueEffectScope,
3
+ getCurrentScope as getCurrentVueScope,
4
+ onScopeDispose
5
+ } from '@hummer/tenon-vue'
6
+
7
+ export {
8
+ // watch
9
+ watchEffect,
10
+ watchSyncEffect,
11
+ watchPostEffect,
12
+ watch,
13
+ // reactive
14
+ reactive,
15
+ isReactive,
16
+ shallowReactive,
17
+ set,
18
+ del,
19
+ markRaw,
20
+ // ref
21
+ ref,
22
+ unref,
23
+ toRef,
24
+ toRefs,
25
+ isRef,
26
+ customRef,
27
+ shallowRef,
28
+ triggerRef,
29
+ // computed
30
+ computed,
31
+ // instance
32
+ getCurrentInstance
33
+ } from '@hummer/tenon-vue'
34
+
35
+ const noop = () => {
36
+ }
37
+
38
+ const fixEffectScope = (scope) => {
39
+ scope.pause = noop
40
+ scope.resume = noop
41
+ }
42
+
43
+ const effectScope = (detached) => fixEffectScope(vueEffectScope(detached))
44
+ const getCurrentScope = () => fixEffectScope(getCurrentVueScope())
45
+
46
+ export {
47
+ // effectScope
48
+ effectScope,
49
+ getCurrentScope,
50
+ onScopeDispose
51
+ }
@@ -1,7 +1,8 @@
1
1
  import builtInKeysMap from '../builtInKeysMap'
2
2
  import mergeOptions from '../../../core/mergeOptions'
3
- import MPXProxy from '../../../core/proxy'
4
- import { diffAndCloneA } from '@mpxjs/utils'
3
+ import { getCurrentInstance as getCurrentVueInstance } from '../../export/index'
4
+ import MpxProxy, { setCurrentInstance, unsetCurrentInstance } from '../../../core/proxy'
5
+ import { diffAndCloneA, warn } from '@mpxjs/utils'
5
6
  import { UPDATED, CREATED, MOUNTED, UNMOUNTED } from '../../../core/innerLifecycle'
6
7
 
7
8
  function filterOptions (options) {
@@ -28,11 +29,45 @@ function initProxy (context, rawOptions) {
28
29
  // 缓存options
29
30
  context.$rawOptions = rawOptions
30
31
  // 创建proxy对象
31
- context.__mpxProxy = new MPXProxy(rawOptions, context)
32
+ context.__mpxProxy = new MpxProxy(rawOptions, context)
32
33
  context.__mpxProxy.callHook(CREATED, Hummer.pageInfo && Hummer.pageInfo.params && [Hummer.pageInfo.params])
33
34
  }
34
35
 
35
36
  export function getDefaultOptions (type, { rawOptions = {}, currentInject }) {
37
+ const rawSetup = rawOptions.setup
38
+ if (rawSetup) {
39
+ rawOptions.setup = (props) => {
40
+ const { proxy: instance } = getCurrentVueInstance()
41
+ initProxy(instance, rawOptions)
42
+ setCurrentInstance(instance.__mpxProxy)
43
+ const newContext = {
44
+ triggerEvent: (eventName, eventDetail) => {
45
+ return instance.$emit(eventName, {
46
+ type: eventName,
47
+ detail: eventDetail
48
+ })
49
+ },
50
+ get refs () { return instance.$refs },
51
+ forceUpdate: instance.$forceUpdate.bind(instance),
52
+ selectComponent: () => {
53
+ warn('selectComponent is not supported in Tenon')
54
+ },
55
+ selectAllComponents: () => {
56
+ warn('selectAllComponents is not supported in Tenon')
57
+ },
58
+ createSelectorQuery: () => {
59
+ warn('createSelectorQuery is not supported in Tenon')
60
+ },
61
+ createIntersectionObserver: () => {
62
+ warn('createIntersectionObserver is not supported in Tenon')
63
+ }
64
+ }
65
+ const setupRes = rawSetup(props, newContext)
66
+ unsetCurrentInstance(instance.__mpxProxy)
67
+ return setupRes
68
+ }
69
+ }
70
+
36
71
  const hookNames = type === 'page' ? ['onLoad', 'onReady', 'onUnload'] : ['created', 'mounted', 'unmounted']
37
72
  const rootMixins = [{
38
73
  [hookNames[0]] (...params) {