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

@seed-fe/event-channel

v1.0.0

Published

A powerful event channel for modern web development

Readme

@seed-fe/event-channel

一个基于 EventEmitter2 的事件通道实现,提供受保护事件机制,确保关键事件监听器不被意外移除。

安装

# 使用 npm
npm install @seed-fe/event-channel

# 使用 yarn
yarn add @seed-fe/event-channel

# 使用 pnpm (推荐)
pnpm add @seed-fe/event-channel

基本用法

创建事件通道

import { createEventChannel } from '@seed-fe/event-channel';

// 创建事件通道实例
const eventChannel = createEventChannel();

基本的事件监听和触发

import eventChannel from '@seed-fe/event-channel';

// 添加事件监听器
eventChannel.on('user-login', (userData) => {
  console.log('用户登录:', userData);
});

// 添加一次性事件监听器
eventChannel.once('app-init', () => {
  console.log('应用初始化完成,此监听器只会触发一次');
});

// 触发事件
eventChannel.emit('user-login', { id: 1, name: 'Alice' });

// 移除事件监听器
const handler = () => console.log('处理事件');
eventChannel.on('some-event', handler);
eventChannel.off('some-event', handler); // 移除特定监听器
eventChannel.off('some-event'); // 移除该事件的所有监听器

使用受保护事件

受保护事件使用 Symbol 作为键,确保关键事件监听器不会被意外移除。

import { registerProtectedEvent, unregisterProtectedEvent } from '@seed-fe/event-channel';

// 注册受保护事件
const myEvent = registerProtectedEvent('MY_EVENT', { // 将使用 Symbol('MY_EVENT') 作为键
  description: '重要系统事件'
});

// 添加监听器
eventChannel.on(myEvent, (data) => {
  console.log('处理受保护事件:', data);
});

// 尝试移除监听器 - 无效操作
eventChannel.off(myEvent); // 不会真正移除监听器

// 触发事件
eventChannel.emit(myEvent, { important: 'data' });

// 取消保护
unregisterProtectedEvent(myEvent);

// 现在可以移除监听器
eventChannel.off(myEvent); // 成功移除

API 参考

核心功能

  • createEventChannel(): 创建一个新的事件通道实例
  • default: 默认的事件通道实例

受保护事件管理

  • registerProtectedEvent(name: string, meta?: ProtectedEventMeta): 注册受保护事件
  • unregisterProtectedEvent(sym: symbol): 取消事件保护
  • isProtectedEvent(sym: symbol): 检查是否为受保护事件
  • getProtectedEventMeta(sym: symbol): 获取受保护事件的元数据
  • listProtectedEvents(): 获取所有受保护事件列表

许可证

MIT