npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@gongxh/bit-event

v0.0.12

Published

bit-event

Downloads

446

Readme

bit-event

轻量级事件系统,提供全局事件管理和模块间通信。

简介

bit-event 是一个轻量级、高性能的事件系统,提供全局事件管理和模块间松耦合通信能力。支持事件的添加、移除、发送、批量管理等操作,适用于游戏各系统之间的解耦通信。

核心特性

  • 🚀 零依赖,轻量级实现
  • 📡 全局事件管理器
  • 🎯 支持按 ID、名称、目标对象移除事件
  • 🔥 支持一次性事件(addOnce)
  • 🎨 完整的 TypeScript 类型定义
  • ⚡ 高性能事件分发机制

安装

npm install @gongxh/bit-event

使用说明

全局事件 (GlobalEvent)

全局单例事件管理器,用于模块间通信。

添加事件

  • add(name, callback, target?) - 添加事件监听,返回事件 ID
  • addOnce(name, callback, target?) - 添加一次性事件监听(触发后自动移除)

发送事件

  • send(name, ...args) - 发送事件给所有监听者
  • sendToTarget(name, target, ...args) - 发送事件给指定目标

移除事件

  • remove(eventId) - 按 ID 移除事件
  • removeByName(name) - 移除指定名称的所有事件
  • removeByTarget(target) - 移除指定目标的所有事件
  • removeByNameAndTarget(name, target) - 移除指定名称和目标的事件
  • clearAll() - 清空所有事件

参数说明

  • name - 事件名称(建议使用常量管理)
  • callback - 回调函数 (...args: any[]) => void
  • target - 目标对象(用于批量移除)
  • eventId - 事件 ID(add 方法返回)

事件管理器 (EventManager)

可创建独立的事件管理器实例,用于特定模块或系统。

使用方式

  • new EventManager() - 创建独立的事件管理器
  • API 与 GlobalEvent 完全相同

适用场景

  • 需要隔离的事件系统
  • 模块内部事件管理
  • 可以整体清空的事件组

最佳实践

  1. 使用事件名称常量 - 避免字符串拼写错误

  2. 及时移除事件 - 在对象销毁时移除监听,避免内存泄漏

  3. 使用 target 参数 - 方便批量移除事件

  4. 避免事件循环 - 不要在事件 A 中触发事件 B,再在事件 B 中触发事件 A

  5. 事件分组管理 - 对于复杂系统,使用独立的 EventManager 实例

详细 API 请查看 bit-event.d.ts 类型定义文件。

依赖

无外部依赖

许可证

MIT License

作者

bit老宫 (gongxh)
邮箱: [email protected]

源码仓库