Browse Source

update weex events module

dev
Evan You 8 years ago
parent
commit
ef57aa250f
  1. 47
      src/platforms/weex/runtime/modules/events.js

47
src/platforms/weex/runtime/modules/events.js

@ -2,21 +2,50 @@
import { updateListeners } from 'core/vdom/helpers/update-listeners'
let target: any
function add (
event: string,
handler: Function,
once: boolean,
capture: boolean
) {
if (capture) {
console.log('Weex do not support event in bubble phase.')
return
}
if (once) {
const oldHandler = handler
const _target = target // save current target element in closure
handler = function (ev) {
const res = arguments.length === 1
? oldHandler(ev)
: oldHandler.apply(null, arguments)
if (res !== null) {
remove(event, null, null, _target)
}
}
}
target.addEvent(event, handler)
}
function remove (
event: string,
handler: any,
capture: any,
_target?: any
) {
(_target || target).removeEvent(event)
}
function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
if (!oldVnode.data.on && !vnode.data.on) {
return
}
const on = vnode.data.on || {}
const oldOn = oldVnode.data.on || {}
updateListeners(on, oldOn, (event, handler, capture) => {
if (capture) {
console.log('Weex do not support event in bubble phase.')
return
}
vnode.elm.addEvent(event, handler.bind(vnode.context))
}, (event) => {
vnode.elm.removeEvent(event)
}, vnode.context)
target = vnode.elm
updateListeners(on, oldOn, add, remove, vnode.context)
}
export default {

Loading…
Cancel
Save