# @guanghechen/event-bus

> A simple event bus.

Latest version **7.0.0** (published 2026-02-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install @guanghechen/event-bus
pnpm add @guanghechen/event-bus
yarn add @guanghechen/event-bus
bun add @guanghechen/event-bus
```

## Health

**Score 60/100 (C)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 7.0.0 |
| Published | 2026-02-04 |
| First published | 2021-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 18.0.0 |
| Dependencies | 0 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | guanghechen |
| Maintainers | lemonclown |
| Keywords | event bus |

## Links

- npm: https://www.npmjs.com/package/@guanghechen/event-bus
- Repository: https://github.com/guanghechen/sora.git#@guanghechen
- Homepage: https://github.com/guanghechen/sora/tree/@guanghechen/event-bus@6.0.4/packages/event-bus#readme
- Issues: https://github.com/guanghechen/sora/issues
- npm.io page: https://npm.io/package/@guanghechen/event-bus

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

- 7.0.0 (latest) — 2026-02-04
- 6.0.4 — 2024-10-03
- 6.0.3 — 2024-09-28
- 6.0.2 — 2024-09-25
- 6.0.1 — 2024-09-20
- 6.0.0-alpha.1 — 2023-12-04
- 6.0.0-alpha.0 — 2023-11-18
- 5.0.9 — 2023-10-18
- 5.0.8 — 2023-10-04
- 5.0.7 — 2023-09-07
- 5.0.6 — 2023-08-27
- 5.0.5 — 2023-08-19
- 5.0.4 — 2023-08-08
- 5.0.3 — 2023-07-25
- 5.0.2 — 2023-07-15
- … 82 more at https://npm.io/package/@guanghechen/event-bus/versions

## README

<header>
  <h1 align="center">
    <a href="https://github.com/guanghechen/sora/tree/@guanghechen/event-bus@7.0.0/packages/event-bus#readme">@guanghechen/event-bus</a>
  </h1>
  <div align="center">
    <a href="https://www.npmjs.com/package/@guanghechen/event-bus">
      <img
        alt="Npm Version"
        src="https://img.shields.io/npm/v/@guanghechen/event-bus.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@guanghechen/event-bus">
      <img
        alt="Npm Download"
        src="https://img.shields.io/npm/dm/@guanghechen/event-bus.svg"
      />
    </a>
    <a href="https://www.npmjs.com/package/@guanghechen/event-bus">
      <img
        alt="Npm License"
        src="https://img.shields.io/npm/l/@guanghechen/event-bus.svg"
      />
    </a>
    <a href="#install">
      <img
        alt="Module Formats: cjs, esm"
        src="https://img.shields.io/badge/module_formats-cjs%2C%20esm-green.svg"
      />
    </a>
    <a href="https://github.com/nodejs/node">
      <img
        alt="Node.js Version"
        src="https://img.shields.io/node/v/@guanghechen/event-bus"
      />
    </a>
    <a href="https://github.com/facebook/jest">
      <img
        alt="Tested with Jest"
        src="https://img.shields.io/badge/tested_with-jest-9c465e.svg"
      />
    </a>
    <a href="https://github.com/prettier/prettier">
      <img
        alt="Code Style: prettier"
        src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square"
      />
    </a>
  </div>
</header>
<br/>

A simple event bus.

## Install

- npm

  ```bash
  npm install --save @guanghechen/event-bus
  ```

- yarn

  ```bash
  yarn add @guanghechen/event-bus
  ```


## Usage

- Basic

  ```typescript
  import type { IEvent, IEventHandler } from '@guanghechen/event-bus'
  import { EventBus } from '@guanghechen/event-bus'

  enum EventTypes {
    INIT = 'INIT',
    EXIT = 'EXIT',
  }

  const eventBus = new EventBus<EventTypes>()

  const handle: IEventHandler<EventTypes> = (evt: IEvent<EventTypes>) => {
    console.log('evt:', evt)
  }

  // Listen for specific event
  eventBus.on(EventTypes.INIT, handle)

  // Listen for specific event, and only need to be called once
  eventBus.once(EventTypes.INIT, handle)

  // Listen for all events
  eventBus.subscribe(handle, true)

  // Remove listener
  eventBus.removeListener(EventTypes.INIT, handle)

  // Remove subscriber
  eventBus.unsubscribe(handle)
  ```


[homepage]: https://github.com/guanghechen/sora/tree/@guanghechen/event-bus@7.0.0/packages/event-bus#readme

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