-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_delete.js
More file actions
36 lines (30 loc) · 805 Bytes
/
_delete.js
File metadata and controls
36 lines (30 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* 删除 DOM 元素缓存的 _listeners 数据
* ========================================================================
* @method _delete
* @param {HTMLElement} el - 要删除 listener 的 DOM 元素
* @param {String} type - 事件类型(名称)
* @param {Function} [fn] - 事件处理器回调函数
*/
const _delete = function (el, type, fn) {
const listeners = el._listeners
let index = -1
if (listeners.length < 1) {
return false
}
// 移除缓存的 _listeners 数据
listeners.forEach((listener, i) => {
const handler = listener.fn
if (type === listener.type) {
index = i
if (handler === fn) {
index = i
}
}
})
/* istanbul ignore else */
if (index > -1) {
listeners.splice(index, 1)
}
}
export default _delete