npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@qphi/publisher-subscriber

v1.2.1

Published

A library to implements messages patterns and manage data flow between objects

Downloads

165

Readme

About The Project

@qphi/publisher-subscriber is a module built with Typescript as UMD module. It aims to implement most event / messaging patterns in your js or ts projects.

This module provides two main interfaces:PublisherInterface and SubscriberInterface that describe how your vanilla object could share notification in order be reactive and work together.

👉 Note that it is not an academical pubsub pattern.

Getting Started 🚀

Prerequisites

  • Adding the module to your project
    npm install @qphi/publisher-subscriber --save

That's it! Now you can start to play with the notification system!

Send your first notification

import {Publisher, Subscriber} from "@qphi/publisher-subscriber";

const publisher = new Publisher('publisher-id');
const subscriber = new Subscriber('subscriber-id');

subscriber.subscribe(publisher, 'notification-string-example', () => {
    console.log("Hello world! I'm a happy handler!");
});

publisher.publish('notification-string-example');
// => "Hello world! I'm a happy handler!"

// clear your component properly
publisher.destroy();
subscriber.destroy();

Send parameters on publish

import {Publisher, Subscriber} from "@qphi/publisher-subscriber";

const publisher = new Publisher('Paul');
const subscriber = new Subscriber('bar');

subscriber.subscribe(publisher, 'hi', name => {
    console.log(`Hi, my name is ${name}! Nice to meet you!`);
});

publisher.publish('hi', publisher.getId());
// => "Hi, my name is Paul! Nice to meet you!"

// clear your component properly
publisher.destroy();
subscriber.destroy();

Combine Publisher and Subscriber roles

An instance of PublisherSubscriber implements PublisherInterface and SubscriberInterface. That means it can subscribe to some notifications and also publish.

This kind of instance is helpful when you have to manage several components or implement a workflow.

import { PublisherSubscriber } from "@qphi/publisher-subscriber";

const worker = new PublisherSubscriber('worker');
const manager = new PublisherSubscriber('manager');

worker.subscribe(manager, 'new-mission-available', jobId => {
   console.log(`${worker.getId()}: "${manager.getId()}" asks somebody to do the job "${jobId}".`);
   // some business logic here
   console.log(`${worker.getId()}: job "${jobId}" is done.`);
   worker.publish('job-done', jobId); 
});

manager.subscribe(worker, 'job-done', jobId => {
    // some business logic here
    console.log(`${manager.getId()}: "${worker.getId()}" notices me that job "${jobId}" was done.`);
});


manager.publish('new-mission-available', 'foo');
// => worker: "manager" asks somebody to do the job "foo".
// => worker: job "foo" id done.
// => manager: "worker" notices me that job "foo" was done.

// clear your component properly
manager.destroy();
worker.destroy();

Documentation

https://qphi.github.io/publisher-subscriber/

Roadmap

See the roadmap section for a full list features already planed. See the issues section for a full list of proposed features (and known issues).

License

Distributed under the GPL License. See LICENSE.txt for more information.

Contact

Quentin Philippot - [email protected]

Project Link: https://github.com/qphi/publisher-subscriber