rx-angular / rx-angular

Reactive Extensions for Angular.
https://www.rx-angular.io/
MIT License
1.9k stars 195 forks source link

rxLet with Multiple Observables #1108

Open mikerentmeister opened 2 years ago

mikerentmeister commented 2 years ago

Description

This is more of a question than a bug report. Using the ngIf hack you can do this sort of in your component templates to be able to use 2+ observables in multiple places within your template.

<ng-container
  *ngIf="{
    hasSelections: (screenManager.hasSelections$ | async),
    isSaving: (screenManager.isSaving$ | async)
  } as vm"
>
    ... code here
</ng-container>

Questions:

  1. Are you able to use @rx-angular/template to do something like this, with all of the performance gains of the library still in tact? Keeping in mind that there are some pages where I have 8+ observables, I don't want to have to do an *ngLet for each one.
  2. If yes, how would you structure it?
BioPhoton commented 2 years ago

We have this operator:

https://github.com/rx-angular/rx-angular/blob/master/libs/cdk/state/src/lib/accumulateObservables.ts#L31

Would you be interested in creating docs for it?

BioPhoton commented 2 years ago

related to #1175

malua commented 1 year ago

Hey, I just wanted what the correct way to this now would be. Is it still the accumulateObservables operator? I was wondering, because it is in the internales/core package. If this cart template which needs promotions, prices and allocations:

<ng-container
        *ngIf="{
          promotions: promotions$ | async,
          prices: prices$ | async,
          allocations: allocations$ | async
        } as data"
      >

Can I still do that in the template with rxLet or should I combine that in the class with accumulateObservables?

Thanks!