Get started with MinPubSub CDN
MIT licensed
MinPubSub is a lightweight library for implementing publish-subscribe messaging patterns.
Tags:- publish
- subscribe
- pubsub
- observer
Stable version
Copied!
How to start using MinPubSub CDN
// Include MinPubSub library from CDN
const MinPubSub = require('https://cdn.cdnhub.io/MinPubSub/0.0.2/minpubsub.js');
// Create a new MinPubSub instance
const pubSub = new MinPubSub();
// Define topics
const topicA = 'topicA';
const topicB = 'topicB';
// Publish messages to a topic
pubSub.publish(topicA, 'Message A');
pubSub.publish(topicA, 'Message B');
// Subscribe to a topic and log messages
pubSub.subscribe(topicA, (message) => {
console.log(`Received message on topic ${topicA}: ${message}`);
});
// Publish a message to another topic
pubSub.publish(topicB, 'Message C');
// Subscribe to another topic and log messages
pubSub.subscribe(topicB, (message) => {
console.log(`Received message on topic ${topicB}: ${message}`);
});
Copied!
Copied!