All files / lib/directives _target.js

100% Statements 11/11
87.5% Branches 7/8
100% Functions 4/4
100% Lines 11/11
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  18x       77x 77x   77x 11x     77x 3x     77x 231x 77x         77x    
import { keys } from '../utils/object';
const all_listen_types = {hover: true, click: true, focus: true};
 
export default function targets (vnode, binding, listen_types, fn) {
 
    const targets = keys(binding.modifiers || {})
        .filter(t => !all_listen_types[t]);
 
    if (binding.value) {
        targets.push(binding.value);
    }
 
    const listener = () => {
        fn({targets, vnode});
    };
 
    keys(all_listen_types).forEach(type => {
        if (listen_types[type] || binding.modifiers[type]) {
            vnode.elm.addEventListener(type, listener);
        }
    });
 
    // Return the list of targets
    return targets;
}