@mpxjs/core 2.9.17 → 2.9.21

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.17",
3
+ "version": "2.9.21",
4
4
  "description": "mpx runtime core",
5
5
  "keywords": [
6
6
  "miniprogram",
@@ -47,5 +47,5 @@
47
47
  "url": "https://github.com/didi/mpx/issues"
48
48
  },
49
49
  "sideEffects": false,
50
- "gitHead": "80dd826352ab7178952f6ac1f2d7dbcf610fe6cf"
50
+ "gitHead": "0ed5fa50016bd13a170c38619cfa9cbcc352ba23"
51
51
  }
@@ -18,6 +18,12 @@ export default function proxyEventMixin () {
18
18
  const originValue = valuePath.reduce((acc, cur) => acc[cur], $event.detail)
19
19
  const value = filterMethod ? (innerFilter[filterMethod] ? innerFilter[filterMethod](originValue) : typeof this[filterMethod] === 'function' && this[filterMethod]) : originValue
20
20
  setByPath(this, expr, value)
21
+ },
22
+ __invokeHandler (eventName, $event) {
23
+ const handler = this[eventName]
24
+ if (handler && typeof handler === 'function') {
25
+ handler.call(this, $event)
26
+ }
21
27
  }
22
28
  }
23
29
  }
@@ -1,5 +1,5 @@
1
1
  import { isObject } from '@mpxjs/utils'
2
- import { CREATED, MOUNTED, BEFOREUNMOUNT } from '../../core/innerLifecycle'
2
+ import { BEFORECREATE, MOUNTED, BEFOREUNMOUNT } from '../../core/innerLifecycle'
3
3
 
4
4
  const targets = []
5
5
  let curTarget = null
@@ -177,8 +177,9 @@ export default function relationsMixin (mixinType) {
177
177
  }
178
178
  } else if (__mpx_mode__ === 'web' && mixinType === 'component') {
179
179
  return {
180
- [CREATED] () {
180
+ [BEFORECREATE] () {
181
181
  this.__mpxRelations = {}
182
+ this.__mpxRelationNodesMap = {} // 用于getRelationNodes关系查询
182
183
  },
183
184
  [MOUNTED] () {
184
185
  this.__mpxCollectRelations()
@@ -186,8 +187,14 @@ export default function relationsMixin (mixinType) {
186
187
  },
187
188
  [BEFOREUNMOUNT] () {
188
189
  this.__mpxExecRelations('unlinked')
190
+ // 重置缓存数据
191
+ this.__mpxRelations = {}
192
+ this.__mpxRelationNodesMap = {}
189
193
  },
190
194
  methods: {
195
+ getRelationNodes (path) {
196
+ return this.__mpxRelationNodesMap[path] || null
197
+ },
191
198
  __mpxCollectRelations () {
192
199
  const relations = this.__mpxProxy.options.relations
193
200
  if (!relations) return
@@ -221,6 +228,7 @@ export default function relationsMixin (mixinType) {
221
228
  targetRelation,
222
229
  relation
223
230
  }
231
+ this.__mpxRelationNodesMap[path] = [target] // 子级绑定父级
224
232
  } else if (type === 'ancestor') {
225
233
  // 当前匹配失败,但type为ancestor时,继续向上查找
226
234
  return this.__mpxCheckParent(target, relation, path)
@@ -230,6 +238,12 @@ export default function relationsMixin (mixinType) {
230
238
  __mpxExecRelations (type) {
231
239
  Object.keys(this.__mpxRelations).forEach(path => {
232
240
  const { target, targetRelation, relation } = this.__mpxRelations[path]
241
+ const currentPath = this.$options.componentPath
242
+ if (type === 'linked') {
243
+ this.__mpxLinkRelationNodes(target, currentPath)
244
+ } else if (type === 'unlinked') {
245
+ this.__mpxRemoveRelationNodes(target, currentPath)
246
+ }
233
247
  if (typeof targetRelation[type] === 'function') {
234
248
  targetRelation[type].call(target, this)
235
249
  }
@@ -237,6 +251,15 @@ export default function relationsMixin (mixinType) {
237
251
  relation[type].call(this, target)
238
252
  }
239
253
  })
254
+ },
255
+ __mpxLinkRelationNodes (target, path) {
256
+ target.__mpxRelationNodesMap[path] = target.__mpxRelationNodesMap[path] || [] // 父级绑定子级
257
+ target.__mpxRelationNodesMap[path].push(this)
258
+ },
259
+ __mpxRemoveRelationNodes (target, path) {
260
+ const arr = target.__mpxRelationNodesMap[path] || []
261
+ const index = arr.indexOf(this)
262
+ if (index !== -1) arr.splice(index, 1)
240
263
  }
241
264
  }
242
265
  }