|
|
|
@ -4,6 +4,10 @@ function arrInvoker(arr) {
|
|
|
|
|
return function() { arr[0](arr[1]); };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fnInvoker(arr) {
|
|
|
|
|
return function(ev) { arr[0](ev); };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateEventListeners(oldVnode, vnode) {
|
|
|
|
|
var name, cur, old, elm = vnode.elm,
|
|
|
|
|
oldOn = oldVnode.data.on || {}, on = vnode.data.on;
|
|
|
|
@ -12,11 +16,20 @@ function updateEventListeners(oldVnode, vnode) {
|
|
|
|
|
cur = on[name];
|
|
|
|
|
old = oldOn[name];
|
|
|
|
|
if (old === undefined) {
|
|
|
|
|
elm.addEventListener(name, is.array(cur) ? arrInvoker(cur) : cur);
|
|
|
|
|
} else if (is.array(old)) {
|
|
|
|
|
if (is.array(cur)) {
|
|
|
|
|
elm.addEventListener(name, arrInvoker(cur));
|
|
|
|
|
} else {
|
|
|
|
|
cur = [cur];
|
|
|
|
|
on[name] = cur;
|
|
|
|
|
elm.addEventListener(name, fnInvoker(cur));
|
|
|
|
|
}
|
|
|
|
|
} else if (old.length === 2) {
|
|
|
|
|
old[0] = cur[0]; // Deliberately modify old array since it's
|
|
|
|
|
old[1] = cur[1]; // captured in closure created with `arrInvoker`
|
|
|
|
|
on[name] = old;
|
|
|
|
|
} else {
|
|
|
|
|
old[0] = cur;
|
|
|
|
|
on[name] = old;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|