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

ngx-message-bus

v11.0.0

Published

Messaging system for angular 11.x application. It allows communication between components and modules. Direct messages, messages by types and broadcasting.

Downloads

1,295

Readme

ngx-message-bus

Message Bus for Angular 11+ for communication between components.

For Angular version 8.x, you need to choose 8.0.0 version. For Angular version 7.x, you need to choose 7.0.0 version. For Angular version 6.x, you need to choose 3.0.0 version. For Angular versions before 6, you need to choose a 1.x version of this module.

Provides:

  • creation of virtual hubs
  • communication within hubs across whole application
  • direct messaging within hubs
  • bulk messaging by type within hubs
  • broadcasting messages within hubs

Usage

Managing the connection

Open the connection

Opens the connection to hub and stores Connection object allowing listening, broadcasting and posting messages.


ngOnInit(){
    //initializes the connection to the hub with specific id. subscriberId is the unique id of entity making the connection
    this.myConnection = this.messageBus.connect(hubId, subscriberId);
}

Closing connection

Closes the connection. Remove the subscriber from hub and kills all listeners.

ngOnDestroy(){
    this.messageBus.disconnect(this.myConnection);
}

Listening for messages

Start listening for messages

To start listening for a specific type of message create a subscription object and pass it to 'on' method. Each time the message arrives to the group or to the subscriber the 'handleMessage' method will be called.

const subscription = {
    groupId: messageTypeId,
    callback: this.handleMessage.bind(this)
};
this.myConnection.on(subscription);

Stop listening to messages

 const subscription= {
    groupId: this.type,
    callback:  null
};
this.hubConnection.off(subscription);

Listen for broadcasts

Broadcast messages require only callback function to be passed

this.myConnection.onBroadcast(this.handleBroadcast.bind(this));

Stop listening for broadcasts

this.myConnection.offBroadcast();

Posting messages

Post message

To post a message, a Message object needs to be created.

 const message = {
            recipientIds: [1,2,3],
            payload: { //... some data },
            groupId: 'XYZ'
        };
        this.hubConnection.post(message);

All recipients with ids: 1,2,3 and listening to group 'XYZ' will receive the message. recipientIds and groupId is optional. If one is not defined then 'any' is assumed. For example:

 const message = {
    recipientIds: null,
    payload: { //... some data },
    groupId: 'XYZ'
};
this.myConnection.post(message);

Targets all listeners in 'XYZ' group within the hub.

Broadcasting message

To broadcast a message simple data needs to be passed

   this.myConnection.broadcast({//... some data});

Exception in listener's call back

By default message bus will catch the exception and print it into the console. There's a possibility to consume the exception with no action (None) or to rethrow the exception.

import  { MessageBus, ErrorHandlingEnum } from 'ngx-message-bus';

constructor(private messageBus: MessageBus){
        this.messageBus.setLogLevel(ErrorHandlingEnum.Throw);
}

When ErrorHandlingEnum is defined as

export declare enum ErrorHandlingEnum {
    None = 0,
    Throw = 1,
    Log = 2,
}

None = exception is consumed. Throw = rethrow the exception. Note: it may break your application. Log = print the excpetion into the console.