Skip to content

Instantly share code, notes, and snippets.

@imkrish
Last active June 16, 2019 10:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imkrish/fab8d96112badd84256a15b933b55cf6 to your computer and use it in GitHub Desktop.
Save imkrish/fab8d96112badd84256a15b933b55cf6 to your computer and use it in GitHub Desktop.
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Observable, Subscription } from 'rxjs';
export class RxJSUtil {
static unsubscribe = (subscriptions: Subscription[]) =>
subscriptions.forEach(subscription => subscription.unsubscribe());
}
@Component({
selector: 'nx-tutorial-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit, OnDestroy {
@Selector(CustomersState.SelectedCustomer)
private selectedCustomer$: Observable<Customer>;
@Selector(OrdersState.NewOrder)
private newOrder$: Observable<Order>;
private subscriptions: Subscription[];
constructor() {
this.subscriptions = [];
}
ngOnInit() {
this.subscriptions.push(
this.selectedCustomer$.subscribe(customer => {
// Do something
}),
this.newOrder$.subscribe(order => {
// Do something
})
);
}
ngOnDestroy() {
RxJSUtil.unsubscribe(this.subscriptions);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment