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

pubsub-distinct

v0.2.0

Published

PubSub service based on rx-pubsub with an additional publishDistinct() method

Downloads

36

Readme

PubSubDistinct

  1. Description
  2. Installation
  3. Usage
  4. Methods
  5. Git repository
  6. Version

1. Description

pubsub-distinct or PubSubDistinct is an extension of the rx-pubsub service. Additionally to the functionality of the rx-pubsub it has one more public method publishDistinct() which publishes only distinct data. It means, the same data will not be published on the same event twice in a row.

Example:

let eventName = 'testEvent';
  
console.log('register the subscriber to the event');
let sub1 = PubSubDistinct.subscribe(eventName, (data) => {
    console.log('subscriber receives data: ', data);
});  
  
console.log('publish data to the event');
PubSubDistinct.publishDistinct(eventName, {testProp: 'test Value'});

console.log('publish other data to the event');
PubSubDistinct.publishDistinct(eventName, {testProp: 'test Value 2'});

console.log('publish the same data as the previous one. the subscriber shouldn\'t be triggered!');
PubSubDistinct.publishDistinct(eventName, {testProp: 'test Value 2'});

console.log('publish new data');
PubSubDistinct.publishDistinct(eventName, {testProp: 'test Value 3'});

Output:

register the subscriber to the event  
  
publish data to the event  
subscriber receives data:  Object {testProp: "test Value"}  
  
publish other data to the event  
subscriber receives data:  Object {testProp: "test Value 2"}  
  
publish the same data as the previous one. the subscriber shouldn't be triggered!  
  
publish new data  
subscriber receives data:  Object {testProp: "test Value 3"}

This module is separated from the rx-pubsub because of its dependencies and the final size of the module. It is using object-hash module to generate the hash of the published data. As the result its size is 7 times bigger than rx-pubsub. So, if you don't need this feature, to publish only distinct data, please take a look at the module rx-pubsub.

2. Installation

Install the module into your application and save it as a dev dependency in your package.json file

npm install pubsub-distinct --save-dev

3. Usage

In order to use the PubSubDistinct you have to include/import it into your application:

import {PubSubDistinct} from "pubsub-distinct";

If you want to use it in a plain/vanilla Javascript project then you might just include the js file into your html/page application:

<script type="application/javascript" src="./node_modules/pubsub-distinct/dist/pubsub-distinct.min.js"></script>

Create new PubSubDistinct object and use it as it's shown in the above example.

4. Methods

The only difference of this module from the rx-pubsub is the method publishDistinct():

publishDistinct(eventName: string, data: any, previousMessagesNr: number = 1)

Publish only distinct data to an event. The same data will not be published two times in a row!

Parameters:
eventName - Event which should be fired
data - Data sent to all Subscribers of the event
previousMessagesNr - Maximum element count of the replay buffer

Return:
Method returns void.

The description of other methods can be found in the rx-pubsub documentation.

5. Git repository

https://github.com/t0w5a/pubsub-distinct

6. Version

0.2.0