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

ng-radio

v0.0.4

Published

RxJS-based Angular2 application message bus inspired by Backbone.Radio

Downloads

337

Readme

Ng-Radio

RxJS-based message bus service for Angular2 apps inspired by Backbone.Radio. Inject it in your application module and have fun.

There is nothing angular2-specific, though. It is possible to use it in any application.

Installation

npm install --save ng-radio

Usage

First, import it:

import { NgRadio } from 'ng-radio';

Then, if using Angular2, inject it as a service (do not forget about providers):

......
import { NgRadio } from 'ng-radio';
......

@NgModule({
    imports:[
		......
    ],
    providers: [
    	.......
        NgRadio,
        .......
    ],

constructor(private radio: NgRadio){...}

Or create an instance manually:

let radio = new NgRadio();

Since you have NgRadio instance in your app, you can use these methods for passing messages:

  • radio.cast(key, data) - send message to radio.

  • radio.on(pattern) - returns observable you can subscribe to listen events.

Patterns may contain multiple segments split by :. Use this feature to create namespaces for messages you cast. You can use * in pattern to subscribe to any matching segment, or use ** to subscribe to all segments, starting from particular position.

For example, you can use on('error:*') and subscribe to all errors, including something like error:http or error:internal and so on:

radio.cast('app:start',     'started');
radio.cast('message:greet', 'Hi!');
radio.cast('message:bye',   'Bye!');

radio.on('app:start').subscribe((message)=>{
	console.log(message); //will receive 'started' only
});

radio.on('message:greet').subscribe((message)=>{
	console.log(message); //will receive 'Hi!'
});

radio.on('message:bye').subscribe((message)=>{
	console.log(message); //will receive 'Bye!'
});

radio.on('message:*').subscribe((message)=>{
	console.log(message); //will receive both 'Hi!' and 'Bye!'
});

radio.on('**').subscribe((message)=>{
	console.log(message); //will receive all messages: 'started', 'Hi!' and 'Bye!'
});

Examples

These strings will match:

  • on('**' , callback) can subscribe to any message with any segments count

  • on('a' , callback) can subscribe to cast('a', ...)

  • on('a:b' , callback) can subscribe to cast('a:b', ...)

  • on('a:b:c' , callback) can subscribe to cast('a:b:c', ...)

  • on('a:**' , callback) can subscribe to cast('a:b:c', ...), cast('a:b:c:d:e:f', ...)

  • on('a:*:*' , callback) can subscribe to cast('a:b:c', ...), cast('a:f:g', ...), cast('a:n:m', ...)

  • on('a:b:*' , callback) can subscribe to cast('a:b:c', ...), cast('a:b:d', ...), but not cast('a:b', ...)

  • on('a:b:**', callback) can subscribe to cast('a:b:c',. ..)

  • on('*:b:*' , callback) can subscribe to cast('a:b:c', ...)

  • on('a:*:*' , callback) can subscribe to cast('a:b:c', ...)