# any-event

> 小巧的事件模型

Latest version **2.2.0** (published 2022-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install any-event
pnpm add any-event
yarn add any-event
bun add any-event
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.0 |
| Published | 2022-05-24 |
| First published | 2018-12-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | any86 |
| Maintainers | russell-ne |
| Keywords | event, emit |

## Links

- npm: https://www.npmjs.com/package/any-event
- Homepage: https://github.com/any86/any-event
- npm.io page: https://npm.io/package/any-event

## Dependencies (1)

- [tslib](https://npm.io/package/tslib.md) ^2.3.1

## Alternatives

- [async-exit-hook](https://npm.io/package/async-exit-hook.md) — 3.7M weekly downloads
- [evnty](https://npm.io/package/evnty.md) — 7.2K weekly downloads
- [eleventy-plugin-asciidoc](https://npm.io/package/eleventy-plugin-asciidoc.md) — 3.5K weekly downloads
- [@jswork/next-get2get](https://npm.io/package/@jswork/next-get2get.md) — 945 weekly downloads
- [@dashersw/axon](https://npm.io/package/@dashersw/axon.md) — 934 weekly downloads

## Recent versions

- 2.2.0 (latest) — 2022-05-24
- 2.0.3-alpha.0 (next) — 2022-01-18
- 2.1.3 — 2022-05-24
- 2.1.2 — 2022-04-28
- 2.1.1 — 2022-04-08
- 2.1.0 — 2022-04-02
- 2.0.3 — 2022-03-30
- 2.0.3-2.0.3-alpha.1.0 — 2022-03-30
- 2.0.2 — 2022-01-06
- 2.0.2-alpha.1 — 2022-01-06
- 2.0.2-alpha.0 — 2022-01-06
- 2.0.1 — 2021-12-29
- 2.0.1-alpha.0 — 2021-12-28
- 2.0.0 — 2021-12-28
- 2.0.0-alpha.4 — 2021-12-02
- … 72 more at https://npm.io/package/any-event/versions

## README

# any-event [![NPM Version][npm-image]][npm-url] [![npm bundle size (minified + gzip)][size-image]][size-url] [![codecov][codecov-image]][codecov-url] [![CircleCI][ci-image]][ci-url]

[npm-image]: https://img.shields.io/npm/v/any-event.svg
[npm-url]: https://npmjs.org/package/any-event
[downloads-url]: https://npmjs.org/package/any-event
[size-image]: https://img.shields.io/bundlephobia/minzip/any-event.svg
[size-url]: https://bundlephobia.com/result?p=any-event
[codecov-image]: https://codecov.io/gh/any86/any-event/branch/master/graph/badge.svg 
[codecov-url]: https://codecov.io/gh/any86/any-event
[ci-image]: https://circleci.com/gh/any86/any-event.svg?style=svg
[ci-url]: https://circleci.com/gh/any86/any-event

:cake: 不到1k, 一个mini的事件管理器,  希望能在您的代码中做一块砖.


## 安装

``` shell
npm i -S any-event
```

## 使用

``` javascript
import EventEmitter from  'any-event';
const emitter = new EventEmitter();
emitter.on('add', data=>{
    console.log(data) // 1
});
emitter.emit('add', 1);
```
## 方法


### on(eventName, listener)
绑定事件

|名称|类型|数据类型|是否必填|说明|
|---|---|---|---|---|
|eventName| 参数 |`String/Symbol`|是|事件名称|
|listener| 参数 |`Function`|是|对应的回调函数|
|emitter| 返回值 |`EventEmitter`|---|实例|

### off(eventName, listener)
解除绑定, 如果不填写`listener`, 那么`eventName`对应的`listener`都会被移除.

|名称|类型|数据类型|是否必填|说明|
|---|---|---|---|---|
|eventName| 参数 |`String/Symbol`|是|事件名称|
|listener| 参数 |`Function`|是|对应的回调函数|
|emitter| 返回值 |`EventEmitter`|---|实例|

``` javascript
const callback = data=>{
    alert(data)
};
emitter.on('add', callback);
// 解除绑定
emitter.off('add', callback);
// add事件不会触发
emitter.emit('add', 1);
```


### emit(eventName [, ...args])
触发事件, 支持任意数量参数

|名称|类型|数据类型|是否必填|说明|
|---|---|---|---|---|
|eventName| 参数 |`String/Symbol`|是|事件名称|
| args| 参数 |`Any`|是|数据|
|emitter| 返回值 |`Boolean`|---|实例|

``` javascript
const callback = (a,b,c,d)=>{
    console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
// add事件触发
emitter.emit('add', 1,2,3,4);
```


### destroy()
销毁实例

``` javascript
const callback = (a,b,c,d)=>{
    console(a,b,c,d); // 1,2,3,4
};
emitter.once('add', callback);
emitter.destroy();

// add事件不会触发
emitter.emit('add', 1,2,3,4);
```

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