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

rxjs-bus

v0.2.0

Published

Wrapper on top of RXJs to propose a versatile and easy to use bus

Downloads

20

Readme

rxjs-bus

Wrapper on top of RXJs to propose a versatile and easy to use bus.

BusManager

Initialization

General

  import { BusManager } from "rxjs-bus";

  // Define bus we need
  BusManager.configure({
    bus: [
      {name: "global", options: { withLogs: true }},
      {name: "view1", options: { withLogs: false }}
    ]
  });

Ephemeral

  import { BusManager } from "rxjs-bus";
  
  BusManager.add("view_exchange_child", { withLogs: env.DEBUG !== undefined })
  
  /*** [Later] ***/
  
  BusManager.remove("view_exchange_child");

Use

Subscription

  import { BusManager } from "rxjs-bus";
  
  let bus = BusManager.get("global");
  let subscription = bus.on("my.beautiful.event", (event) => {
    console.log(event.data)
  });
  
  // You will receive events until you unsubscribe from 

Emit

  import { BusManager } from "rxjs-bus";
  
  let bus = BusManager.get("global");
  
  let data = "Hello !"; // could be anything
  bus.emit("my.beautiful.event", data);

Once

Once allow to automatically unsubscribe after receiving one event.

  import { BusManager } from "rxjs-bus";
  
  let bus = BusManager.get("global");
  bus.once("my.ephemeral.event", (event) => {
    console.log(event.data);
  });

Raw

Expose directly RxJS api to do even more awesome things with your events!

  import { BusManager } from "rxjs-bus";
  import { map, debounceTime, distinctUntilChanged } from 'rxjs/operators';
  
  let bus = BusManager.get("global");
  
  let subscription =
      bus.raw("my.complex.event")
        .pipe(
          distinctUntilChanged(),
          map((data) => data + data)
          debounceTime(100)
        )
     .subscribe(event => {
        console.log(event.data);
     });

Please consult RxJS documentation for more awesome event management!

Scheduling

It is possible to define how the event will be distributed. The possible values are :

  • null
  • asap
  • async
  • queue
  • animationFrame

Default value used is null, which represent a synchronous event delivery.

  import { BusManager } from "rxjs-bus";
  
  let bus = BusManager.get("global");
  bus.on("my.async.event", (event) => console.log(event.data), {
    scheduler: BusManager.scheduler.async
  });

For more information, please check RxJS 6 documentation.

Acknowledge

Sometimes, we want to have information back after sending an event... Ack is here to help you with that, without the hassle of creating a dedicated event id, or managing callback lifetime!

  import { BusManager } from "rxjs-bus";
  import Dispowser from "dispowser";
  
  let disposer = Dispowser.createDisposer();
  
  let bus = BusManager.get("global");
  let data = "Ping?";
  bus.emit("my.resource.asking.event", data, {
    ack: {
      name: "my.resource.event", // optional, if null or undefined, a guid will be generated
      callback: (event) => console.log(event.data), // Pong! 
      options: { scheduler: BusManager.scheduler.asap }
    }
  });
  
  /*** [Somewhere in the code...] ***/
  
  let bus = BusManager.get("global");
  bus.on("my.resource.asking.event", (event) => {
    let resource = fetchResource();
    if(event.ack) {
      console.log(`Ack ${event.ack.name} available !`);
      event.ack.callback(resource); // will fire an event on the same bus, callback will not work after firing the first event
    }
  });

Subscription management

I recommend to use Dispowser to help you manage your subscriptions. It allow to dispose easily without polluting your scope with annoying variables.

  import Dispowser from "dispowser";
  
  let disposer = Dispowser.createDisposer();
  disposer.register = bus.on("my.beautiful.event", (event) => console.log(event.data));
  disposer.register = bus.on("my.fantastic.event", (event) => console.log(event.data));
  disposer.register = bus.on("my.extraordinary.event", (event) => console.log(event.data));
  
  /*** [...] ***/

  disposer.dispose();
  // Events won't be received anymore

Without Dispowser, do as follow :)

    let subscription = bus.on("my.beautiful.event", (event) => console.log(event.data));
    
    /*** [...] ***/
      
    subscription.unsubscribe();

StateManager

WIP