j-component 1.4.8 → 1.4.10

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": "j-component",
3
- "version": "1.4.8",
3
+ "version": "1.4.10",
4
4
  "description": "miniprogram custom component framework",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -128,6 +128,15 @@ class ComponentManager {
128
128
  const exparserNodes = this.shadowRoot.querySelectorAll(selector)
129
129
  return exparserNodes.map(item => getSelectComponentResult(item))
130
130
  }
131
+ caller.selectOwnerComponent = () => {
132
+ const ownerShadowRoot = this.ownerShadowRoot
133
+ if (!(ownerShadowRoot instanceof exparser.ShadowRoot)) return null
134
+
135
+ const exparserNode = ownerShadowRoot.getHostNode()
136
+ if (!exparserNode) return null
137
+
138
+ return getSelectComponentResult(exparserNode)
139
+ }
131
140
  caller.createSelectorQuery = () => new SelectorQuery(caller)
132
141
  caller.createIntersectionObserver = options => new IntersectionObserver(caller, options)
133
142
  caller.setData = (data, callback) => {
@@ -60,10 +60,10 @@ function exparserTreeToJSON(node) {
60
60
  let children = array
61
61
  const vt = node._vt
62
62
 
63
- if (vt) {
64
- if (vt.type === CONSTANT.TYPE_TEXT) {
65
- array.push(vt.content)
66
- } else if (vt.type === CONSTANT.TYPE_NATIVE || vt.type === CONSTANT.TYPE_COMPONENT) {
63
+ if (node instanceof exparser.TextNode) {
64
+ array.push(node.textContent)
65
+ } else if (node instanceof exparser.Element) {
66
+ if (!node.__virtual) {
67
67
  children = []
68
68
  const child = {
69
69
  tagName: _.getTagName(vt.componentId || vt.tagName) || vt.tagName,
@@ -78,10 +78,9 @@ function exparserTreeToJSON(node) {
78
78
  })
79
79
  array.push(child)
80
80
  }
81
+ (node.__wxSlotChildren || []).forEach(child => _inner(child, children))
81
82
  }
82
83
 
83
- (node.__wxSlotChildren || []).forEach(child => _inner(child, children))
84
-
85
84
  return array
86
85
  }
87
86
 
@@ -43,12 +43,16 @@ function diffVt(oldVt, newVt) {
43
43
  }
44
44
 
45
45
  // 检查事件
46
- Object.keys(oldVt.event).forEach(key => {
47
- const {name, isCapture, id} = oldVt.event[key]
46
+ if (isSameEvent(oldVt.event, newVt.event)) {
47
+ newVt.event = oldVt.event
48
+ } else {
49
+ Object.keys(oldVt.event).forEach(key => {
50
+ const {name, isCapture, id} = oldVt.event[key]
48
51
 
49
- exparser.removeListenerFromElement(node, name, id, {capture: isCapture})
50
- })
51
- render.updateEvent(node, newVt.event)
52
+ exparser.removeListenerFromElement(node, name, id, {capture: isCapture})
53
+ })
54
+ render.updateEvent(node, newVt.event)
55
+ }
52
56
 
53
57
  // 检查子节点
54
58
  const oldChildren = oldVt.children
@@ -122,6 +126,28 @@ function diffAttrs(oldAttrs, newAttrs) {
122
126
  return isChange ? retAttrs : false
123
127
  }
124
128
 
129
+ /**
130
+ * diff 事件绑定
131
+ */
132
+ function isSameEvent(oldEvent, newEvent) {
133
+ const oldKeys = Object.keys(oldEvent)
134
+ const newKeys = Object.keys(newEvent)
135
+
136
+ if (oldKeys.length !== newKeys.length) return false
137
+
138
+ return oldKeys.every(key => {
139
+ const oldItem = oldEvent[key]
140
+ const newItem = newEvent[key]
141
+
142
+ return newItem &&
143
+ oldItem.name === newItem.name &&
144
+ oldItem.isCapture === newItem.isCapture &&
145
+ oldItem.isMutated === newItem.isMutated &&
146
+ oldItem.isCatch === newItem.isCatch &&
147
+ oldItem.handler === newItem.handler
148
+ })
149
+ }
150
+
125
151
  /**
126
152
  * diff 列表
127
153
  */