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

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.3",
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": "a4acf4b86fc634513b77614453d28027f2b37762"
53
53
  }
@@ -0,0 +1,51 @@
1
+ import {
2
+ effectScope as vueEffectScope,
3
+ getCurrentScope as getCurrentVueScope,
4
+ onScopeDispose
5
+ } from '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 '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,6 +1,7 @@
1
1
  import builtInKeysMap from '../builtInKeysMap'
2
2
  import mergeOptions from '../../../core/mergeOptions'
3
- import MPXProxy from '../../../core/proxy'
3
+ import { getCurrentInstance as getCurrentVueInstance } from '../../export/index'
4
+ import MpxProxy, { setCurrentInstance, unsetCurrentInstance } from '../../../core/proxy'
4
5
  import { diffAndCloneA } from '@mpxjs/utils'
5
6
  import { UPDATED, CREATED, MOUNTED, UNMOUNTED } from '../../../core/innerLifecycle'
6
7
 
@@ -28,11 +29,32 @@ 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 instance = getCurrentVueInstance().proxy
41
+ initProxy(instance, rawOptions)
42
+ setCurrentInstance(instance.__mpxProxy)
43
+ const newContext = {
44
+ triggerEvent: instance.triggerEvent.bind(instance),
45
+ refs: instance.$refs,
46
+ forceUpdate: instance.$forceUpdate.bind(instance),
47
+ selectComponent: instance.selectComponent.bind(instance),
48
+ selectAllComponents: instance.selectAllComponents.bind(instance),
49
+ createSelectorQuery: instance.createSelectorQuery.bind(instance),
50
+ createIntersectionObserver: instance.createIntersectionObserver.bind(instance)
51
+ }
52
+ const setupRes = rawSetup(props, newContext)
53
+ unsetCurrentInstance(instance.__mpxProxy)
54
+ return setupRes
55
+ }
56
+ }
57
+
36
58
  const hookNames = type === 'page' ? ['onLoad', 'onReady', 'onUnload'] : ['created', 'mounted', 'unmounted']
37
59
  const rootMixins = [{
38
60
  [hookNames[0]] (...params) {