Angular-Async-Data
Angular-Async-Data copied to clipboard
Avoid subscribe() while interacting with outputs
Is it possible to avoid subscriptions while reacting to an event and emitting an event from it?
combineLatest([this.selectionChangedAction$,this.activeResults$])
.pipe(
tap(([selectedRows, activeResults]) => {
const getSelected = this.getSelected(activeResults, selectedRows);
** NOTE: This is an @Output to parent component**
this.onAccessInclusionChange.emit(accessInclusionList);
})
).subscribe(); --> Can this be avoided?
I have not seen this case in your talks and I am trying to avoid subscriptions
If what is to the left of combineLatest()
is bound with an async pipe, you can avoid the subscribe. If you can do a short stackblitz example of what you are trying to achieve, I can take a look.
https://stackblitz.com/github/alfredoperez/angular-async-data?file=src%2Fapp%2Fproducts%2Fproduct-list%2Fproduct-list-asyncPipe.component.ts
Added two examples of things I don't know how to avoid the subscription. Try clicking the checkbox and resizing the windows
- Emitting an event as a consequence of an action
- Executing a method from an observable created by a HostListener.
combineLatest([this.selectionChangedAction$, this.products$ ])
.pipe(
tap(([selected, allProducts]) => {
if (selected !== null) {
const target = allProducts.find(item => selected.id === item.id);
this.productsSelectedChange.emit(target);
}
}
)
)
.subscribe();
this.resize$.pipe(debounceTime(300))
.subscribe(() => {
this.resizingLabel = `resizing action... E.g. resize grid base on size. width: ${window.outerWidth} height: ${window.outerHeight}`;
});
Thanks =)
Also, is there a way to avoid subscription on:
- Events from HosListener, like subscribing to a window resize event
-
valueChanges
from a form. E.g.this.customerForm.valueChanges.subscirbe( ()=>{ this.store.dispatch(markSectionAsDirty) });