@@ -4,10 +4,19 @@ import { updateListeners } from 'core/vdom/helpers/update-listeners'
4
4
5
5
let target : any
6
6
7
+ function createOnceHandler ( event , handler , capture ) {
8
+ const _target = target // save current target element in closure
9
+ return function onceHandler ( ) {
10
+ const res = handler . apply ( null , arguments )
11
+ if ( res !== null ) {
12
+ remove ( event , onceHandler , capture , _target )
13
+ }
14
+ }
15
+ }
16
+
7
17
function add (
8
18
event : string ,
9
19
handler : Function ,
10
- once : boolean ,
11
20
capture : boolean ,
12
21
passive ?: boolean ,
13
22
params ?: Array < any >
@@ -16,18 +25,6 @@ function add (
16
25
console . log ( 'Weex do not support event in bubble phase.' )
17
26
return
18
27
}
19
- if ( once ) {
20
- const oldHandler = handler
21
- const _target = target // save current target element in closure
22
- handler = function ( ev ) {
23
- const res = arguments . length === 1
24
- ? oldHandler ( ev )
25
- : oldHandler . apply ( null , arguments )
26
- if ( res !== null ) {
27
- remove ( event , null , null , _target )
28
- }
29
- }
30
- }
31
28
target . addEvent ( event , handler , params )
32
29
}
33
30
@@ -47,7 +44,7 @@ function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) {
47
44
const on = vnode . data . on || { }
48
45
const oldOn = oldVnode . data . on || { }
49
46
target = vnode . elm
50
- updateListeners ( on , oldOn , add , remove , vnode . context )
47
+ updateListeners ( on , oldOn , add , remove , createOnceHandler , vnode . context )
51
48
target = undefined
52
49
}
53
50
0 commit comments