|
1 |
| -// skip type checking this file because we need to attach private properties |
2 |
| -// to elements |
| 1 | +/* @flow */ |
3 | 2 |
|
4 | 3 | import { updateListeners } from 'core/vdom/helpers/index'
|
5 | 4 |
|
6 |
| -function updateDOMListeners (oldVnode, vnode) { |
| 5 | +let target: HTMLElement |
| 6 | + |
| 7 | +function add (event: string, handler: Function, once: boolean, capture: boolean) { |
| 8 | + if (once) { |
| 9 | + const oldHandler = handler |
| 10 | + handler = function (ev) { |
| 11 | + remove(event, handler, capture) |
| 12 | + arguments.length === 1 |
| 13 | + ? oldHandler(ev) |
| 14 | + : oldHandler.apply(null, arguments) |
| 15 | + } |
| 16 | + } |
| 17 | + target.addEventListener(event, handler, capture) |
| 18 | +} |
| 19 | + |
| 20 | +function remove (event: string, handler: Function, capture: boolean) { |
| 21 | + target.removeEventListener(event, handler, capture) |
| 22 | +} |
| 23 | + |
| 24 | +function updateDOMListeners (oldVnode: VNodeWithData, vnode: VNodeWithData) { |
7 | 25 | if (!oldVnode.data.on && !vnode.data.on) {
|
8 | 26 | return
|
9 | 27 | }
|
10 | 28 | const on = vnode.data.on || {}
|
11 | 29 | const oldOn = oldVnode.data.on || {}
|
12 |
| - const add = vnode.elm._v_add || ( |
13 |
| - vnode.elm._v_add = (event, handler, once, capture) => { |
14 |
| - if (once) { |
15 |
| - const oldHandler = handler |
16 |
| - handler = function (ev) { |
17 |
| - remove(event, handler, capture) |
18 |
| - arguments.length === 1 |
19 |
| - ? oldHandler(ev) |
20 |
| - : oldHandler.apply(null, arguments) |
21 |
| - } |
22 |
| - } |
23 |
| - vnode.elm.addEventListener(event, handler, capture) |
24 |
| - } |
25 |
| - ) |
26 |
| - const remove = vnode.elm._v_remove || ( |
27 |
| - vnode.elm._v_remove = (event, handler, capture) => { |
28 |
| - vnode.elm.removeEventListener(event, handler, capture) |
29 |
| - } |
30 |
| - ) |
| 30 | + target = vnode.elm |
31 | 31 | updateListeners(on, oldOn, add, remove, vnode.context)
|
32 | 32 | }
|
33 | 33 |
|
|
0 commit comments