You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
693 B
JavaScript
24 lines
693 B
JavaScript
var is = require('../is');
|
|
|
|
function arrInvoker(arr) {
|
|
return function() { arr[0](arr[1]); };
|
|
}
|
|
|
|
function updateEventListeners(oldVnode, vnode) {
|
|
var name, cur, old, elm = vnode.elm,
|
|
oldOn = oldVnode.data.on || {}, on = vnode.data.on;
|
|
if (!on) return;
|
|
for (name in on) {
|
|
cur = on[name];
|
|
old = oldOn[name];
|
|
if (old === undefined) {
|
|
elm.addEventListener(name, is.array(cur) ? arrInvoker(cur) : cur);
|
|
} else if (is.array(old)) {
|
|
old[0] = cur[0]; // Deliberately modify old array since it's
|
|
old[1] = cur[1]; // captured in closure created with `arrInvoker`
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = {create: updateEventListeners, update: updateEventListeners};
|