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-debugger-2

v0.1.8

Published

an alternative way to keep track of opened subscriptions

Downloads

118

Readme

RxJS Debugger

Demo

The demo app in this repo is available in repo's GitHub pages.

What is it?

rxjs-debugger is an alternative and easy way to debug RxJS Observables and its subscriptions. Disclaimer: don't use this tool in production. This is a very experimental exercise.

Why might you need it?

The usual approach to debug RxJS-based code involves sprinkling do or custom operators. Then, logging is made available to notice an observable is subscribed and unsubscribed.

While debugging Angular applications with hundreds of observables, I found these methods very time-consuming, since we have to pipe every single observable we want to track. Badly-managed RxJS Subscriptions can affect application's performance widely and sail aimlessly can be very painfull.

You can find more info about this package in this Medium Post (https://medium.com/@filipemendes_73527/rxjs-debugger-an-alternative-way-to-debug-rxjs-observables-eb6d4b7fef6c)

I'm sure you also thinks the same, and this is a package you might need.

Install

Install the package using NPM:

npm install --save-dev rxjs-debugger

And add only the following code to main.ts,

import { Observable } from "rxjs";
import { RxJSDebugger } from "rxjs-debugger";
RxJSDebugger.init(Observable);

Or require the module to use with CommonJS bundler:

const { RxJSDebugger } = require("rxjs-debugger");
const { Observable } = require("rxjs");
RxJSDebugger.init(Observable);

Core concepts

rxjs-debugger adds logic to Observable's prototype subscribe method that allow us to monitorize the subscription and unsubscription calls of RxJS Observables and its extended classes (EventEmitter, Subject, BehaviorSubject...).

Module API

The exported RxJSDebugger object exposes the following API:

export declare type SubscriptionsMap = { [key: string]: string[] };
export declare type ClassName = string;
export declare type ObservableDef = typeof Observable;

export const RxJSDebugger: {
  valueChanges: Subject<SubscriptionsMap>;
  obSubscribed$: Subject<ClassName>,
  obUnsubscribed$: Subject<ClassName>,

  addOnSubscribeLogic: (fn: Function) => void,
  addOnUnsubscribeLogic: (fn: Function) => void,

  clearOnSubscribeLogic: () => void,
  clearOnUnsubscribeLogic: () => void,

  setTargettedClasses: (targettedClasses: ClassName[]) => void,

  subscriptionsMap: () => SubscriptionsMap,
  openedSubscriptionsCount: () => number,
  clearSubscriptionsMap: () => void,

  init: (
    observableDef: ObservableDef,
    targettedClasses?: ClassName[],
    onSubscribeFn?: () => void,
    onUnsubscribeFn?: () => void
  ) => void
}

Unlike other RxJS debugging libraries, this one doesn't force you to change every observable you want to monitorize. Calling .init() method is enough to trigger the debugging mode. After that, when an observable is subscribed, a new uuid is pushed to subscriber's class entry in subscriptionsMap. It allows us to know in realtime how many subscriptions exist in each class.

Window API

More than that, developer can access the tracked data via browser's console, using window.subscriptionsMap.