# @wxwzl/eventemitter

> typescript Event Emitter

Latest version **1.0.1** (published 2022-01-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @wxwzl/eventemitter
pnpm add @wxwzl/eventemitter
yarn add @wxwzl/eventemitter
bun add @wxwzl/eventemitter
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2022-01-09 |
| First published | 2021-09-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 53 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | wxwzl |
| Maintainers | wxwzl |
| Keywords | eventemitter, typescript |

## Links

- npm: https://www.npmjs.com/package/@wxwzl/eventemitter
- Repository: https://gitee.com/wxwzl/eventemitter
- npm.io page: https://npm.io/package/@wxwzl/eventemitter

## 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

- 1.0.1 (latest) — 2022-01-09
- 1.0.0 — 2022-01-09
- 0.0.4 — 2021-09-10
- 0.0.3 — 2021-09-10
- 0.0.2 — 2021-09-10
- 0.0.1 — 2021-09-10

## README

# @wxwzl/eventemitter

typescript 版 EventEmitter

## 安装

` npm i @wxwzl/eventemitter -S`

## 使用

```
  import EventEmitter from "@wxwzl/eventemitter";

  let  emitter = new EventEmitter();
  //监听一次
  emitter.once("test",(data)=>{
    console.log("test",data);
  });
  //持续监听
  let testCallBack = (data)=>{
    console.log("testCallBack",data);
  }

  //阻止后续添加的事件对emit、emitOneCopy 发出的事件的处理,通过事件处理函数返回true
  let stopCallBack = (data)=>{
    console.log("stopCallBack",data);
    return true;
  }
  emitter.on("testCallBack",testCallBack);
  
  //同时监听多个事件
  emitter.on(["testCallBack","test"],testCallBack);

  //监听固定次数
  let testTimeCallBack = ()=>{
    console.log("testCallBack",data);
  }
  emitter.on("testTimeCallBack",testTimeCallBack,undefined,3);

  //移除某个事件的监听
  emitter.off("testTimeCallBack");

  //移除某个事件的某个处理函数
  emitter.off("testTimeCallBack",testTimeCallBack);
  
   //移除所有监听函数
  emitter.clear();

  // 同时支持链式调用

  emitter.on("test",()=>{}).off("test).clear();
  

  // 为每一个事件监听函数派发事件，事件监听函数收到的事件参数将是发送事件参数的一份拷贝
  emitter.emitOneCopy("testCallBack",{a:1});
  
  //广播事件，确保让所有事件处理函数都执行，让某些事件处理函数不会受到在它之前添加的事件处理函数返回true而没有收到事件的影响
  emitter.broadCast("testCallBack",{a:1});

  //广播事件，确保让所有事件处理函数都执行，让某些事件处理函数不会受到在它之前添加的事件处理函数返回true而没有收到事件的影响
  //事件监听函数收到的事件参数将是发送事件参数的一份拷贝
  emitter.broadCastOneCopy("testCallBack",{a:1});

```


## 文档

[Documentation generated from source files by Typedoc](./docs/index.html).

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