# promise-dom-events

> Listen to DOM events using ES2015 Promises and/or `async/await`

Latest version **1.0.2** (published 2019-01-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-dom-events
pnpm add promise-dom-events
yarn add promise-dom-events
bun add promise-dom-events
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-01-27 |
| First published | 2019-01-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jasper Lichte |
| Maintainers | jasper_lichte |
| Keywords | async, await, dom, user, events, promises |

## Links

- npm: https://www.npmjs.com/package/promise-dom-events
- Repository: https://github.com/JasperLichte/Promise-DOM-Events
- Homepage: https://github.com/JasperLichte/Promise-DOM-Events#readme
- Issues: https://github.com/JasperLichte/Promise-DOM-Events/issues
- npm.io page: https://npm.io/package/promise-dom-events

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-01-27
- 1.0.1 — 2019-01-26
- 1.0.0 — 2019-01-26

## README

# Promise-DOM-Events
>  Listen to DOM events using ES2015 Promises and/or `async/await`



## Installation

```
npm i promise-dom-events
```



## Usage

### Non-recurring events

Because of the nature of Promises, `Promise-DOM-Events` work best with events that are only supposed to happen once in the lifetime of the app. Such as a user clicking a button:

```javascript
const button = document.getElementById('btn')
const event = await promiseDomEvent(button)('click')
```

Or a keyboard event such as `keydown`

```javascript
const event = await promiseDomEvent(window)('keydown')
```

You do not need to bother unsubscribing from the event after it has emitted.

### Recurring events

`Promise-DOM-Events` does allow you to listen to recurring events as well. You will need to set up your own simple 'event loop' using `requestAnimationFrame` or other non blocking timing functions such as `setInterval` or `setTimeout` though:

```javascript
(async function loop() {  
  const event = await promiseDomEvent(window)('mousemove')
  console.log(event)
  requestAnimationFrame(loop)
})()
```

---
_Source: https://npm.io/package/promise-dom-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
