
Security News
Deno 2.4 Brings Back deno bundle, Improves Dependency Management and Observability
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
simple publish/subscribe mode. 一套发布订阅模式,可快速的订阅及发布事件。
npm i -S c-pubsub
pubsub.on
订阅事件, pubsub.emit
发布事件
import pubsub from 'c-pubsub';
// 订阅事件
pubsub.on('event', (arg) => {
console.log(arg);
});
// 发布事件
pubsub.emit('event', 'Hello');
// Hello
pubsub.one
也可以订阅一次性事件,监听到一次事件后就会自动卸载事件。
pubsub.one('event', (arg) => {
console.log(arg);
});
pubsub.emit('event', 'Hello'); // Hello
pubsub.emit('event', 'Hello'); // 已经自动卸载过事件了,所不会有反应。
pubsub.off
可以卸载事件,会卸载该事件下的所有回调。
pubsub.on('event', (arg) => {
console.log('1', arg);
});
pubsub.on('event', (arg) => {
console.log('2', arg);
});
pubsub.one('event', (arg) => {
console.log('3', arg);
});
pubsub.off('event'); // 卸载了 event 事件
pubsub.emit('event', 'Hello'); // 不会有任何反应,因为所有监听 event 的回调函数都被卸载了。
FAQs
simple publish/subscribe mode
The npm package c-pubsub receives a total of 0 weekly downloads. As such, c-pubsub popularity was classified as not popular.
We found that c-pubsub demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.