ccampbell / gator

Event delegation in Javascript
http://craig.is/riding/gators
492 stars 46 forks source link

Once method #33

Open gkiely opened 4 years ago

gkiely commented 4 years ago

Description: A once event allows firing a listener one time and automatically removes that listener.

Use case An event handler for a modal background.

Before:

Gator(document).on('click', '.modal-bg', () => {
  modal.setVisible(false);
  Gator(document).off('click', '.modal-bg');
});

After:

Gator(document).once('click', '.modal-bg', () => {
  modal.setVisible(false)
});