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 🙏

© 2025 – Pkg Stats / Ryan Hefner

nti-event-bus-module

v0.1.0

Published

平台和原生事件通信的封装库

Readme

nti-event-bus-module

nti-event-bus-module 是一个轻量级的库,用于在Web环境中实现配置平台和原生模块的父子应用之间的通信。它允许您建立一个简单的基于事件的通信通道,实现不同模块之间的无缝数据交换。

安装

使用 npm 或 yarn 安装库:

npm install nti-event-bus-module
# 或
yarn add nti-event-bus-module

使用

初始化

要开始使用 ModuleEventBus,请使用表示您模块标识符的唯一 moduleId 实例化它:

import ModuleEventBus from 'nti-event-bus-module';

const myModuleId = 'myModule';
const eventBus = new ModuleEventBus(myModuleId);

事件订阅

使用 on 方法订阅特定事件。type 参数表示事件类型,callback 是触发事件时要执行的函数。

eventBus.on('customEvent', payload => {
  // 处理接收到的 payload
  console.log('接收到:', payload);
});

事件触发

使用 emit 方法向父应用触发事件。提供事件的 type 和相应的 payload

eventBus.emit('customEvent', { data: '你好,父应用!' });

事件取消订阅

使用 off 方法取消订阅特定事件。传递事件的 type 和原始的 callback

const myCallback = payload => {
  // 处理接收到的 payload
  console.log('接收到:', payload);
};

// 订阅
eventBus.on('customEvent', myCallback);

// 取消订阅
eventBus.off('customEvent', myCallback);

清理

当您的模块不再需要时,请使用 destroy 方法清理事件监听器,确保正确释放资源:

eventBus.destroy();

API

new ModuleEventBus(moduleId)

  • moduleId (String): 模块的唯一标识符。

创建 ModuleEventBus 的新实例。

on(type, callback)

  • type (String): 事件类型。
  • callback (Function): 当事件触发时要执行的回调函数。

订阅特定事件类型。

emit(type, payload)

  • type (String): 事件类型。
  • payload (Any): 要随事件发送的数据。

向父应用触发事件。

off(type, callback)

  • type (String): 事件类型。
  • callback (Function): 要取消订阅的回调函数。

取消订阅特定事件类型。

destroy()

清理事件监听器并释放与 ModuleEventBus 实例相关联的资源。

示例

import ModuleEventBus from 'nti-event-bus-module';

const myModuleId = 'myModule';
const eventBus = new ModuleEventBus(myModuleId);

// 订阅事件
eventBus.on('customEvent', payload => {
  console.log('接收到:', payload);
});

// 触发事件
eventBus.emit('customEvent', { data: '你好,父应用!' });

// 取消订阅事件
eventBus.off('customEvent');

// 当模块不再需要时清理资源
eventBus.destroy();

许可证

此库根据 NTI 许可证授权 - 有关详细信息,请参阅相关文件。