4.2.0 • Published 4 months ago

one-event v4.2.0

Weekly downloads
1,074
License
MIT
Repository
github
Last release
4 months ago

one-event

Listen to one event via addEventListener, then resolve a Promise

Note: This module is based on the once option of addEventListener. Before v2 it was a replacement for it.

Install

npm install one-event
// This module is only offered as a ES Module
import oneEvent from 'one-event';

Usage

async function init() {
	await oneEvent(document.body, 'click', false);
	console.log('You clicked my body. Don’t do it again.');
}

init();

API

oneEvent(target, type, options)

target, type, and options are the same as what you supply to target.addEventListener(type, listener, options)

Alternatives

Related

  • one-mutation - Observe one mutation via MutationObserver, then resolve a Promise.
  • select-dom - Lightweight querySelector/All wrapper that outputs an Array.
  • doma - Parse an HTML string into DocumentFragment or one Element, in a few bytes.
  • Refined GitHub - Uses this module.

License

MIT © Federico Brigante

4.1.0

4 months ago

4.2.0

4 months ago

4.0.0

4 months ago

3.1.0

1 year ago

3.0.0

3 years ago

2.0.0

3 years ago

1.2.0

8 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.0

9 years ago

0.5.0

9 years ago