@mpxjs/core 2.9.35 → 2.9.38

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.9.35",
3
+ "version": "2.9.38",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -19,7 +19,7 @@
19
19
  ],
20
20
  "main": "src/index.js",
21
21
  "dependencies": {
22
- "@mpxjs/utils": "^2.9.1",
22
+ "@mpxjs/utils": "^2.9.38",
23
23
  "lodash": "^4.1.1",
24
24
  "miniprogram-api-typings": "^3.10.0"
25
25
  },
@@ -47,5 +47,5 @@
47
47
  "url": "https://github.com/didi/mpx/issues"
48
48
  },
49
49
  "sideEffects": false,
50
- "gitHead": "eb9647625e82c7dc7058fa35f5d1fe2233d40142"
50
+ "gitHead": "5e2740e2091edda91eda9ffe775989c7fd9838df"
51
51
  }
@@ -1,21 +1,6 @@
1
- import { setByPath, error, hasOwn, dash2hump } from '@mpxjs/utils'
1
+ import { setByPath, error, dash2hump, collectDataset } from '@mpxjs/utils'
2
2
  import Mpx from '../../index'
3
3
 
4
- const datasetReg = /^data-(.+)$/
5
-
6
- function collectDataset (props) {
7
- const dataset = {}
8
- for (const key in props) {
9
- if (hasOwn(props, key)) {
10
- const matched = datasetReg.exec(key)
11
- if (matched) {
12
- dataset[matched[1]] = props[key]
13
- }
14
- }
15
- }
16
- return dataset
17
- }
18
-
19
4
  export default function proxyEventMixin () {
20
5
  const methods = {
21
6
  __invoke ($event) {
@@ -1,32 +1,17 @@
1
- import { BEFORECREATE, BEFOREUPDATE } from '../../core/innerLifecycle'
1
+ import { BEFORECREATE } from '../../core/innerLifecycle'
2
2
  import { noop, getEnvObj } from '@mpxjs/utils'
3
3
 
4
4
  const envObj = getEnvObj()
5
5
 
6
- const setNodeRef = function (target, ref) {
7
- Object.defineProperty(target.$refs, ref.key, {
8
- enumerable: true,
9
- configurable: true,
10
- get () {
11
- // for nodes, every time being accessed, returns as a new selector.
12
- return target.__getRefNode(ref)
13
- }
14
- })
15
- }
16
-
17
- const setComponentRef = function (target, ref, isAsync) {
6
+ const setRef = function (target, ref, isAsync) {
18
7
  const targetRefs = isAsync ? target.$asyncRefs : target.$refs
19
- const cacheMap = isAsync ? target.__asyncRefCacheMap : target.__refCacheMap
20
- const key = ref.key
21
- Object.defineProperty(targetRefs, key, {
8
+ Object.defineProperty(targetRefs, ref.key, {
22
9
  enumerable: true,
23
10
  configurable: true,
24
11
  get () {
25
- // wx由于分包异步化的存在,每次访问refs都需要重新执行selectComponent,避免一直拿到缓存中的placeholder
26
- if (__mpx_mode__ === 'wx' || !cacheMap.get(key)) {
27
- cacheMap.set(key, target.__getRefNode(ref, isAsync))
28
- }
29
- return cacheMap.get(key)
12
+ // 对于组件,由于分包异步化的存在,每次都需要重新执行selectComponent,避免一直获取到placeholder
13
+ // 对于节点,每次都需要获取全新的selectorQuery
14
+ return target.__getRefNode(ref, isAsync)
30
15
  }
31
16
  })
32
17
  }
@@ -36,8 +21,6 @@ export default function getRefsMixin () {
36
21
  [BEFORECREATE] () {
37
22
  this.$refs = {}
38
23
  this.$asyncRefs = {}
39
- this.__refCacheMap = new Map()
40
- this.__asyncRefCacheMap = new Map()
41
24
  this.__getRefs()
42
25
 
43
26
  if (__mpx_mode__ === 'ali') {
@@ -45,19 +28,14 @@ export default function getRefsMixin () {
45
28
  this.createSelectorQuery = this._createSelectorQuery
46
29
  }
47
30
  },
48
- [BEFOREUPDATE] () {
49
- this.__refCacheMap.clear()
50
- this.__asyncRefCacheMap.clear()
51
- },
52
31
  methods: {
53
32
  __getRefs () {
54
33
  if (this.__getRefsData) {
55
34
  const refs = this.__getRefsData()
56
35
  refs.forEach(ref => {
57
- const setRef = ref.type === 'node' ? setNodeRef : setComponentRef
58
36
  setRef(this, ref)
59
37
  if (__mpx_mode__ === 'tt' && ref.type === 'component') {
60
- setComponentRef(this, ref, true)
38
+ setRef(this, ref, true)
61
39
  }
62
40
  })
63
41
  }
package/src/vuePlugin.js CHANGED
@@ -1,4 +1,4 @@
1
- import { walkChildren, parseSelector, error, hasOwn } from '@mpxjs/utils'
1
+ import { walkChildren, parseSelector, error, hasOwn, collectDataset } from '@mpxjs/utils'
2
2
  import { createSelectorQuery, createIntersectionObserver } from '@mpxjs/api-proxy'
3
3
  import { EffectScope } from 'vue'
4
4
  import { PausedState } from './helper/const'
@@ -55,22 +55,25 @@ const hackEffectScope = () => {
55
55
  }
56
56
  }
57
57
 
58
- const datasetReg = /^data-(.+)$/
59
-
60
- function collectDataset (attrs) {
61
- const dataset = {}
62
- for (const key in attrs) {
63
- if (hasOwn(attrs, key)) {
64
- const matched = datasetReg.exec(key)
65
- if (matched) {
66
- dataset[matched[1]] = attrs[key]
58
+ export default function install (Vue) {
59
+ Object.defineProperties(Vue.prototype, {
60
+ data: {
61
+ get () {
62
+ return Object.assign({}, this.$props, this.$data)
63
+ }
64
+ },
65
+ dataset: {
66
+ get () {
67
+ return collectDataset(this.$attrs, true)
68
+ }
69
+ },
70
+ id: {
71
+ get () {
72
+ return this.$attrs.id || ''
67
73
  }
68
74
  }
69
- }
70
- return dataset
71
- }
75
+ })
72
76
 
73
- export default function install (Vue) {
74
77
  Vue.prototype.triggerEvent = function (eventName, eventDetail) {
75
78
  // 输出Web时自定义组件绑定click事件会和web原生事件冲突,组件内部triggerEvent时会导致事件执行两次,将click事件改为_click来规避此问题
76
79
  const escapeEvents = ['click']
@@ -78,8 +81,8 @@ export default function install (Vue) {
78
81
  eventName = '_' + eventName
79
82
  }
80
83
  let eventObj = {}
81
- const dataset = collectDataset(this.$attrs)
82
- const id = this.$attrs.id || ''
84
+ const dataset = this.dataset
85
+ const id = this.id
83
86
  const timeStamp = +new Date()
84
87
  eventObj = {
85
88
  type: eventName,