Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

c-pubsub

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

c-pubsub

simple publish/subscribe mode

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

c-pubsub

simple publish/subscribe mode. 一套发布订阅模式,可快速的订阅及发布事件。

Insatll

npm i -S c-pubsub

Usage

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 的回调函数都被卸载了。

Keywords

FAQs

Package last updated on 01 Feb 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc