Skip to content

Commit

Permalink
fix(v-on): revert component root data.on/data.nativeOn behavior for
Browse files Browse the repository at this point in the history
weex-vue-render compat

close #6109
  • Loading branch information
yyx990803 committed Jul 19, 2017
1 parent 06b9b0b commit 1713061
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/core/instance/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ export function initRender (vm: Component) {
defineReactive(vm, '$attrs', parentData && parentData.attrs, () => {
!isUpdatingChildComponent && warn(`$attrs is readonly.`, vm)
}, true)
defineReactive(vm, '$listeners', parentData && parentData.on, () => {
defineReactive(vm, '$listeners', vm.$options._parentListeners, () => {
!isUpdatingChildComponent && warn(`$listeners is readonly.`, vm)
}, true)
} else {
defineReactive(vm, '$attrs', parentData && parentData.attrs, null, true)
defineReactive(vm, '$listeners', parentData && parentData.on, null, true)
defineReactive(vm, '$listeners', vm.$options._parentListeners, null, true)
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/core/vdom/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,12 @@ export function createComponent (
return createFunctionalComponent(Ctor, propsData, data, context, children)
}
// keep listeners
// extract listeners, since these needs to be treated as
// child component listeners instead of DOM listeners
const listeners = data.on
// replace with listeners with .native modifier
// so it gets processed during parent component patch.
data.on = data.nativeOn
if (isTrue(Ctor.options.abstract)) {
// abstract components do not keep anything
Expand Down
9 changes: 3 additions & 6 deletions src/platforms/web/runtime/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@ function remove (
}

function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
const isComponentRoot = isDef(vnode.componentOptions)
let oldOn = isComponentRoot ? oldVnode.data.nativeOn : oldVnode.data.on
let on = isComponentRoot ? vnode.data.nativeOn : vnode.data.on
if (isUndef(oldOn) && isUndef(on)) {
if (isUndef(oldVnode.data.on) && isUndef(vnode.data.on)) {
return
}
on = on || {}
oldOn = oldOn || {}
const on = vnode.data.on || {}
const oldOn = oldVnode.data.on || {}
target = vnode.elm
normalizeEvents(on)
updateListeners(on, oldOn, add, remove, vnode.context)
Expand Down
9 changes: 3 additions & 6 deletions src/platforms/weex/runtime/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@ function remove (
}

function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
const isComponentRoot = !!vnode.componentOptions
let oldOn = isComponentRoot ? oldVnode.data.nativeOn : oldVnode.data.on
let on = isComponentRoot ? vnode.data.nativeOn : vnode.data.on
if (!oldOn && !on) {
if (!oldVnode.data.on && !vnode.data.on) {
return
}
on = on || {}
oldOn = oldOn || {}
const on = vnode.data.on || {}
const oldOn = oldVnode.data.on || {}
target = vnode.elm
updateListeners(on, oldOn, add, remove, vnode.context)
}
Expand Down

0 comments on commit 1713061

Please sign in to comment.