Skip to content

Commit

Permalink
feat($event): support binding parameters on event handler within weex…
Browse files Browse the repository at this point in the history
… recycle-list
  • Loading branch information
Hanks10100 authored and yyx990803 committed Dec 19, 2017
1 parent 2a1ce0d commit acdc3c4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/core/vdom/helpers/update-listeners.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/* @flow */

import { warn } from 'core/util/index'
import { cached, isUndef } from 'shared/util'
import { cached, isUndef, isPlainObject } from 'shared/util'

const normalizeEvent = cached((name: string): {
name: string,
once: boolean,
capture: boolean,
passive: boolean
passive: boolean,
handler?: Function,
params?: Array<any>
} => {
const passive = name.charAt(0) === '&'
name = passive ? name.slice(1) : name
Expand Down Expand Up @@ -47,11 +49,15 @@ export function updateListeners (
remove: Function,
vm: Component
) {
let name, cur, old, event
let name, def, cur, old, event
for (name in on) {
cur = on[name]
def = cur = on[name]
old = oldOn[name]
event = normalizeEvent(name)
if (isPlainObject(def)) {
cur = def.handler
event.params = def.params
}
if (isUndef(cur)) {
process.env.NODE_ENV !== 'production' && warn(
`Invalid handler for event "${event.name}": got ` + String(cur),
Expand All @@ -61,7 +67,7 @@ export function updateListeners (
if (isUndef(cur.fns)) {
cur = on[name] = createFnInvoker(cur)
}
add(event.name, cur, event.once, event.capture, event.passive)
add(event.name, cur, event.once, event.capture, event.passive, event.params)
} else if (cur !== old) {
old.fns = cur
on[name] = old
Expand Down
4 changes: 2 additions & 2 deletions src/platforms/weex/entry-framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ const jsHandlers = {
}
}

function fireEvent (instance, nodeId, type, e, domChanges) {
function fireEvent (instance, nodeId, type, e, domChanges, params) {
const el = instance.document.getRef(nodeId)
if (el) {
return instance.document.fireEvent(el, type, e, domChanges)
return instance.document.fireEvent(el, type, e, domChanges, params)
}
return new Error(`invalid element reference "${nodeId}"`)
}
Expand Down
6 changes: 4 additions & 2 deletions src/platforms/weex/runtime/modules/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ function add (
event: string,
handler: Function,
once: boolean,
capture: boolean
capture: boolean,
passive?: boolean,
params?: Array<any>
) {
if (capture) {
console.log('Weex do not support event in bubble phase.')
Expand All @@ -26,7 +28,7 @@ function add (
}
}
}
target.addEvent(event, handler)
target.addEvent(event, handler, params)
}

function remove (
Expand Down

0 comments on commit acdc3c4

Please sign in to comment.