Skip to content

stewie1570/PubSub

Repository files navigation

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");
});

About

A small Pub/Sub implementation for JavaScript.

Resources

License

Stars

Watchers

Forks

Packages

No packages published