New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

interesting

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interesting

Pub/Sub service

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

interesting

A cheap/lighweight Publish/Subscribe service

Installation

Install via npm

npm install interesting

Usage

Create Data bus

var eventbus = require("interesting")();

Subscribe and Publish

eventbus.subscribe("data-updates",
	function (message) {
    	console.log("called data updates ", message);
    });

// called after 5 seconds
setTimeout(function () {
        eventbus.publish("data-updates", ["a lot of data", "whatever"]);
    }, 5000);

API

EventBus.prototype.subscribe(name: String|RegExp, callback: Function): Function

Subscribes a topic to the event bus. Topic name can also accept regular expression for filtering topics.

parameters
  • name:String The topic name to subscribe.

  • callback:Function The callback to execute when topic published. callback arguments will be the same as 2nd publish parameters up to the last.

returns
  • stop:Function returned stop function will unsubscribe to the topic when called.

EventBus.prototype.publish(name: String, ... message: {Mixed}): EventBus

Publishes a topic and notifies all subscriptions that matches the topic.

parameters
  • name:String The topic name to publish.

  • ... message:Mixed The data/message to publish. They will be used as arguments to subscription callbacks.

returns
  • eventbus:EventBus returns the current eventbus instance for chaining method calls.

EventBus.prototype.purge(): EventBus

Removes all subscriptions.

  • eventbus:EventBus returns the current eventbus instance for chaining method calls.

Keywords

observer

FAQs

Package last updated on 12 Sep 2016

Related posts