# @smoovy/listener

> Helpers for listening when it gets too verbose to hear

Latest version **1.0.2** (published 2023-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install @smoovy/listener
pnpm add @smoovy/listener
yarn add @smoovy/listener
bun add @smoovy/listener
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-04-13 |
| First published | 2022-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 86 |
| Author | Davide Perozzi |
| Maintainers | davideperozzi |
| Keywords | smoovy, event, listener, helpers, dom |

## Links

- npm: https://www.npmjs.com/package/@smoovy/listener
- Repository: https://github.com/davideperozzi/smoovy
- Issues: https://github.com/davideperozzi/smoovy/issues
- npm.io page: https://npm.io/package/@smoovy/listener

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-04-13
- 1.0.1 — 2022-12-28
- 1.0.0 — 2022-12-23

## README

# @smoovy/listener
[![Version](https://flat.badgen.net/npm/v/@smoovy/listener)](https://www.npmjs.com/package/@smoovy/listener) ![Size](https://flat.badgen.net/bundlephobia/minzip/@smoovy/listener)

Very simple subscribe/unsubscribe system.

## Installation
```sh
yarn add @smoovy/listener
```
or
```
npm install --save @smoovy/listener
```

## Usage
Listen to elements

```js
import { listen } from '@smoovy/listener';

// single type
listen(window, 'mousemove', event => console.log(event));

// multi type
listen(document.body, ['mouseup', 'mousecancel'], event => console.log(event));
```

Unlistening from events

```js
const unlisten = listen(window, 'mousemove', event => console.log(event));

// to unlisten from window mousemove simply call the unlisten function
unlisten();
```

In case you have many listeners and want to unsubscribe/unlisten from all at once,
you can use the `listenCompose` helper function:

```js
import { listen, listenCompose } from '@smoovy/listener';

const unlisten = listenCompose(
  listen(window, 'mousemove', event => console.log(event)),
  listen(window, 'click', event => console.log(event)),

  // custom callback on unlisten
  () => console.log('all listeners are now inactive')
);

unlisten();
```

## License
See the [LICENSE](../../LICENSE) file for license rights and limitations (MIT).

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