Skip to content

Commit 1713061

Browse files
committed
fix(v-on): revert component root data.on/data.nativeOn behavior for
weex-vue-render compat close #6109
1 parent 06b9b0b commit 1713061

File tree

4 files changed

+13
-15
lines changed

4 files changed

+13
-15
lines changed

Diff for: src/core/instance/render.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ export function initRender (vm: Component) {
5454
defineReactive(vm, '$attrs', parentData && parentData.attrs, () => {
5555
!isUpdatingChildComponent && warn(`$attrs is readonly.`, vm)
5656
}, true)
57-
defineReactive(vm, '$listeners', parentData && parentData.on, () => {
57+
defineReactive(vm, '$listeners', vm.$options._parentListeners, () => {
5858
!isUpdatingChildComponent && warn(`$listeners is readonly.`, vm)
5959
}, true)
6060
} else {
6161
defineReactive(vm, '$attrs', parentData && parentData.attrs, null, true)
62-
defineReactive(vm, '$listeners', parentData && parentData.on, null, true)
62+
defineReactive(vm, '$listeners', vm.$options._parentListeners, null, true)
6363
}
6464
}
6565

Diff for: src/core/vdom/create-component.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ export function createComponent (
161161
return createFunctionalComponent(Ctor, propsData, data, context, children)
162162
}
163163

164-
// keep listeners
164+
// extract listeners, since these needs to be treated as
165+
// child component listeners instead of DOM listeners
165166
const listeners = data.on
167+
// replace with listeners with .native modifier
168+
// so it gets processed during parent component patch.
169+
data.on = data.nativeOn
166170

167171
if (isTrue(Ctor.options.abstract)) {
168172
// abstract components do not keep anything

Diff for: src/platforms/web/runtime/modules/events.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,11 @@ function remove (
6666
}
6767

6868
function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
69-
const isComponentRoot = isDef(vnode.componentOptions)
70-
let oldOn = isComponentRoot ? oldVnode.data.nativeOn : oldVnode.data.on
71-
let on = isComponentRoot ? vnode.data.nativeOn : vnode.data.on
72-
if (isUndef(oldOn) && isUndef(on)) {
69+
if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) {
7370
return
7471
}
75-
on = on || {}
76-
oldOn = oldOn || {}
72+
const on = vnode.data.on || {}
73+
const oldOn = oldVnode.data.on || {}
7774
target = vnode.elm
7875
normalizeEvents(on)
7976
updateListeners(on, oldOn, add, remove, vnode.context)

Diff for: src/platforms/weex/runtime/modules/events.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,11 @@ function remove (
3939
}
4040

4141
function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
42-
const isComponentRoot = !!vnode.componentOptions
43-
let oldOn = isComponentRoot ? oldVnode.data.nativeOn : oldVnode.data.on
44-
let on = isComponentRoot ? vnode.data.nativeOn : vnode.data.on
45-
if (!oldOn && !on) {
42+
if (!oldVnode.data.on && !vnode.data.on) {
4643
return
4744
}
48-
on = on || {}
49-
oldOn = oldOn || {}
45+
const on = vnode.data.on || {}
46+
const oldOn = oldVnode.data.on || {}
5047
target = vnode.elm
5148
updateListeners(on, oldOn, add, remove, vnode.context)
5249
}

0 commit comments

Comments
 (0)