js-pubsub
v2.1.5
Published
A simple Pub/Sub implementation for JavaScript that also contains an ask/tell paradigm.
Downloads
22
Readme
PubSub
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");
});