Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

js-pubsub

stewie157093GPL-3.02.1.5TypeScript support: included

A simple Pub/Sub implementation for JavaScript that also contains an ask/tell paradigm.

pubsub, publish subscribe

readme

PubSub

Build Codecov npm version

A simple Pub/Sub implementation for JavaScript that also contains an ask/tell paradigm.

Here is some example usage from some of the tests:

import { Pubsub } from 'js-pubsub'

var pubsub = new Pubsub();

it("publish to same topic receives callback with correct argument", () => {
    //Arrange
    var argResult;
    pubsub.subscribe({ toTopic: "arg test", withCallback: result => argResult = result });

    //Act
    pubsub.publish({ toTopic: "arg test", withData: "it worked" });

    //Assert
    expect(argResult).to.equal("it worked");
});

it("should allow tellers to answer questions using parameters for context", () => {
    //Arrange
    //Act
    pubsub.answerFor("topic", p1 => `answer${p1}`);

    //Assert
    expect(pubsub.askFor("topic", 1)).to.equal("answer1");
});