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-rx-utils

v0.0.13

Published

Small angular library meant to take control of observables and track your subscriptions

Downloads

55

Readme

NgxRxUtils

Build status

What is this?

Small angular library meant to take control of observables and track your subscriptions

Why might you need it

Common problem of working with RxJS is debugging and proper tracking, which causes lot of aplications end up in poorly preforming state. By using abstract classes and providers from this library your angular aplication will provide better way to track all your subscribtions and debugg your complex observables.

This library will not only take advantage of rxjs-spy by bring its goods into the angular context, but also provide you with usefull abstract classes which will help you clean up subscribtions and tag track observables.

Install

Install using NPM:

npm install ngx-rx-utils --save

Import

Import it like any other npm library and register it in your AppModule (root)

import { NgxRxUtilsModule } from 'ngx-rx-utils';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, NgxRxUtilsModule],
  providers: [],
  bootstrap: [AppComponent],
})
export class AppModule {}

Use

Extend any component that might be subscribing to an observabble like this:

@Component({
  // ...
})
export class Sample1Component extends SubscriptionComponentBase {
  testObservable: Observable<number> = interval(1000);

  constructor() {
    super();

    this.subscribeTo(this.testObservable, 'my-observable', (num: number) => {});
  }
}

notice that there is this.subscribeTo function. It does 2 things. It will TAG provided observable with a string for tracking and it will also unsubscribe all subscriptions made in this component at the end of its lifecycle (ngOnDestroy)

subscribeTo(
  observable: Observable<any>,
  tagName: string,
  cb: (...args: any[]) => void
  ): void

if you already have ngOnDestroy defined, you can use it just make sure that at the end you call for a super.ngOnDestroy() like shown below

ngOnDestroy(): void {
  /// your code
  super.ngOnDestroy()
}

Or you if your architecture allow you could take a neater approach of tagging your observables on their very creation.

@Injectable({
  providedIn: 'root',
})
export class Sample1Service {
  readonly inter2 = interval(1500)
  .pipe(tag('my-interval-2'));
}

Benefit

Now when your observables are nicely taged, lets se how can we take advantaga of that.

By simply injecting another provider to your service or component you will be able to track each of observables you created.

import { RxUtils } from 'ngx-rx-utils';

@Component({
  // ...
})
export class Sample1Component extends SubscriptionComponentBase implements OnInit {

  constructor(private rxUtils: RxUtils) {
    super();
  }
}

.show

Will show you all known observables with provided tag name and all its subscribtions

@Component({
  // ...
})
export class Sample1Component extends SubscriptionComponentBase implements OnInit {
  testObservable: Observable<number> = interval(1000);

  constructor(private rxUtils: RxUtils) {
    super();
  }

  ngOnInit() {
    this.subscribeTo(this.testObservable, 'lib-sample1.MyInternal', (num: number) => {});

    this.rxUtils.show('lib-sample1.MyInternal');
  }
}

console output:

1 snapshot(s) matching /.+/
  Tag = lib-sample1.MyInternal
    Path = /observable/tag
      1 subscriber(s)
        Subscriber
          Value count = 0
          State = incomplete
          Root subscribe (4) [StackFrame, StackFrame, StackFrame, StackFrame]

.log

Will log live al responces of observable matching tag name

@Component({
  // ...
})
export class Sample1Component extends SubscriptionComponentBase implements OnInit {
  testObservable: Observable<number> = interval(1000);

  constructor(private rxUtils: RxUtils) {
    super();
  }

  ngOnInit() {
    this.subscribeTo(this.testObservable, 'lib-sample1.MyInternal', (num: number) => {});

    this.rxUtils.log('lib-sample1.MyInternal');
  }
}

console output

Tag = lib-sample1.MyInternal; notification = next; matching /.+/; value = 0
Tag = lib-sample1.MyInternal; notification = next; matching /.+/; value = 1
Tag = lib-sample1.MyInternal; notification = next; matching /.+/; value = 2
Tag = lib-sample1.MyInternal; notification = next; matching /.+/; value = 3
Tag = lib-sample1.MyInternal; notification = next; matching /.+/; value = 4
Tag = lib-sample1.MyInternal; notification = next; matching /.+/; value = 5