Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
ng2-rx-collector
Advanced tools
Angular 2 garbage collector for RxJS subscriptions.
Benefits:
ngOnDestroy
for cancelling subscriptions anymore (but still you can use it if you want)Inspired by philipooo's beautiful answer.
npm install --save ng2-rx-collector
Import the Collected
decorator and CollectorEvent
data type (actually you can use any
instead of CollectorEvent
if this feels better) which will do all the magic.
import { Collected, CollectorEvent } from 'ng2-rx-collector';
Then create a property on your component which will represent the collector stopper event.
@Component({ ... })
export class MyComponent {
@Collected() private collected: CollectorEvent;
}
Subscribe to any observable / subject using the created property as a flag, so the observable will stop producing the output when the component is being destroyed:
public ngOnInit() {
myObservable.takeUntil(this.collected)
.subscribe(console.log.bind(console));
Observable.merge(myObservable1, myObservable2)
.takeUntil(this.collected)
.subscribe(console.log.bind(console));
}
That is pretty much it.
This is an example you may find in the app folder.
timer.ts (representing any RxJS source):
import { Observable } from 'rxjs';
export let timer = Observable.interval(1000);
testpage.component.ts:
import { Component } from '@angular/core';
import { Collected, CollectorEvent } from './src';
import { timer } from './timer';
@Component({
template: 'Ticking'
})
export class TestpageComponent {
@Collected() private collected: CollectorEvent;
public ngOnInit() {
timer.takeUntil(this.collected)
.subscribe(console.log.bind(console));
}
public ngOnDestroy() {
console.log('unnecessary destroy works, subscription is still killed');
}
}
MIT
FAQs
Angular 2 garbage collector for RxJS subscriptions
The npm package ng2-rx-collector receives a total of 2 weekly downloads. As such, ng2-rx-collector popularity was classified as not popular.
We found that ng2-rx-collector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.