Git Product home page Git Product logo

ngx-until-destroy's Introduction

ngx-until-destroy

Reduce your boilerplate code and unsubscribe your RxJS observables with ease - within your Angular components.

Getting started

  1. npm i ngx-until-destroy
  2. Decorate your component with @WithDestroy$()
  3. Use .pipe(untilDestroy$(this)) before .subscribe(...)

And voilà, you don't have to take care of unsubscribing anymore. Your subscription exists as long as your component exists.

Example

@WithDestroy$()
@Component({...})
export class ExampleComponent {
  ...
  someObservable$.pipe(untilDestroy$(this)).subscribe(...)
}

How it works

What happens in the background is pretty simple.

@WithDestroy$() decorates your component in a way, that it will have a class variable named $destroy, it's a simple RxJS Subject, which emits a new value, when the component is destroyed - by extending ngOnDestroy().

untilDestroy$(this) is simply returning takeUntil(this.destroy$), so your subscription is going to be active just until your component is destroyed. No need for extra boilerplate code or unsubscribing manually.

Contributing

This project was generated with Angular CLI version 14.0.1.

Feel free to clone the project, have a look at it, make changes and / or open a Pull Request.

In case you have any questions, problems or feature requests, feel free to open an issue on GitHub.

ngx-until-destroy's People

Contributors

marcellkiss avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.