Open ymajoros opened 3 weeks ago
Alternatively, toObservable
could be relaxed to take () => T
instead of Signal<T>
- there's no technical reason why it needs to be a single signal...
Alternatively,
toObservable
could be relaxed to take() => T
instead ofSignal<T>
- there's no technical reason why it needs to be a single signal...
Yes, but I'm not sure I understand how it solves the problem. I do like the computed() semantics, but it happens that the typical (e.g. http) internal result is an Observable.
I added some explanation about usage. Here is an example:
this.productPage = computedFromObservable(() => this.productService.find$(this.productSearch(), this.pagination()));
... replacing this more complicated construct:
const productParams: Signal<[ProductSearch, Pagination]> = computed(() => [this.preparationSearch(), this.pagination()]);
const productPageObservable = toObservable(productParams).pipe(
switchMap(([productSearch, pagination]) => this.productService.find$(productSearch, pagination))
);
this.productPage = toSignal(productPageObservable);
+1 on this
Which @angular/* package(s) are relevant/related to the feature request?
@angular/core
Description
I propose some function to run some computation that returns an Observable, and convert it to a signal.
Typical workflow:
Proposed solution
which can be used this way:
... replacing this more complicated construct:
Alternatives considered
Originally, I something like this, but it lacked the power of
computed()
(single signal as input often requiring to create an additional computed() signal anyway, not as lazy, ...):