Permalink
Browse files

feat(addEventListenerOnce): New utility function

  • Loading branch information...
tmorehouse committed Aug 12, 2017
1 parent 66eda01 commit 6b4efdfb559988fc278e107d65a8bb6a4fc6381f
Showing with 15 additions and 0 deletions.
  1. +15 −0 lib/utils/addEventListenerOnce.js
@@ -0,0 +1,15 @@
/**
* Register and event to listen on specifed element once.
* @param {Element} element to listen on
* @param {String} event to listen for
* @param {Function} callback when event fires
*/
function addEventListenerOnce(el, evtName, calback) {
const fnOnce = () => {
el.removeEventListener(evtName, fnOnce);
return callback.apply(null, argmuments);
};
el.addEventListener(event, fnOnce)
}

export default addEventListenerOnce

0 comments on commit 6b4efdf

Please sign in to comment.