Socket
Socket
Sign inDemoInstall

angular-rxjs-automatic-unsubscribe

Package Overview
Dependencies
4
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    angular-rxjs-automatic-unsubscribe

An angular component mixin and a pipe operator to automatically unsubscribe when your component is destroyed. Written in Typescript.


Version published
Weekly downloads
5
Maintainers
1
Install size
12.3 kB
Created
Weekly downloads
 

Readme

Source

angular-rxjs-automatic-unsubscribe

Build Status

A utility package to automatically unsubscribe from rxjs streams when an angular component is disposed of.

Features

  • Component mixin implements the angular OnDestroy interface with an ngOnDestroy function - no need to specify or implement yourself
  • if you have implemented ngOnDestroy it is still called by the mixin as super.ngOnDestroy().
  • Observable unsubscribe pipe operator means that no rxjs classes are altered or augmented
  • unsubscribe operator unsubscribes from observable source when compnent is destroyed.
  • code fully unit tested and example app demonstrates usage

Usage

npm install angular-rxjs-automatic-unsubscribe

Sample Component


import { ApplyDestroyMixin, unsubscribe } from 'angular-rxjs-automatic-unsubscribe';

class ComponentBase {

    constructor(){
        interval(500).pipe(
            unsubscribe(this.destroyStream),
        )
        .subscribe();
    }
    
    public readonly destroyStream!: Observable<boolean>; // set by mixin. Use ! to avoid strict property initialisation errors.
}

@Component({
    selector: 'sample-component',
    templateUrl: './sample-component.html',
    styleUrls: ['./sample-component.scss']
})
export class SampleComponent extends ApplyDestroyMixin(ComponentBase) {}

Example App

To run the example app:

git clone https://github.com/Roaders/angular-automatic-unsubscribe.git
cd angular-automatic-unsubscribe
npm install
npm start

Tests

To run unit tests:

git clone https://github.com/Roaders/angular-automatic-unsubscribe.git
cd angular-automatic-unsubscribe
npm install
npm test

Keywords

FAQs

Last updated on 07 Jun 2019

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc