Skip to content

Instantly share code, notes, and snippets.

@imkrish
Created June 16, 2019 10:10
Show Gist options
  • Save imkrish/3efa9d20a582eddb79e839dbd57f7ac7 to your computer and use it in GitHub Desktop.
Save imkrish/3efa9d20a582eddb79e839dbd57f7ac7 to your computer and use it in GitHub Desktop.
export class AppComponent implements OnInit, OnDestroy {
@Selector(CustomersState.SelectedCustomer)
private selectedCustomer$: Observable<Customer>;
@Selector(OrdersState.NewOrder)
private newOrder$: Observable<Order>;
private onComponentDestroy$: Subject<void>;
constructor() {
this.onComponentDestroy$ = new Subject();
}
ngOnInit() {
this.selectedCustomer$
.pipe(takeUntil(this.onComponentDestroy$))
.subscribe(customer => {
// Do something
});
this.newOrder$
.pipe(takeUntil(this.onComponentDestroy$))
.subscribe(order => {
// Do something
});
}
ngOnDestroy() {
this.onComponentDestroy$.next();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment