import d3 from 'd3';
const DOUBLE_CLICK_TIMEOUT = 300;
export default function multiClicker(handlers) { let timer = null; const singleClick = handlers[0]; const doubleClick = handlers[1]; let clickEvent = null;
return function inner() { clearTimeout(timer); const args = Array.prototype.slice.call(arguments, 0); if (timer === null) { clickEvent = d3.event; timer = setTimeout(() => { timer = null; d3.event = clickEvent; singleClick.apply(this, args); }, DOUBLE_CLICK_TIMEOUT); } else { timer = null; doubleClick.apply(this, args); } }; }
|