Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dictionary in combineLatest #5022

Closed
Akxe opened this issue Sep 17, 2019 · 8 comments
Closed

Support dictionary in combineLatest #5022

Akxe opened this issue Sep 17, 2019 · 8 comments
Labels
feature PRs and issues for features

Comments

@Akxe
Copy link

Akxe commented Sep 17, 2019

Feature Request

combineLatest should accept dictionary/object same as forkJoin. Implementation in forkJoin #4640

combineLatest({
  width: this.width$,
  height: this.height$,
}).pipe(
  tap(({width, height}) => console.log(`dimensions: ${width}x${height}`))
)

Reasoning

It is much easier to mess up when deconstructing array than deconstructiong object. Thus this change would enable developer to name their streams, reducing the potential for error.

@benlesh
Copy link
Member

benlesh commented Sep 19, 2019

This is something we're planning, but I'm not sure we can do until the deprecated versions of combineLatest are removed in version 8.

@benlesh benlesh added the feature PRs and issues for features label Sep 19, 2019
@intellix
Copy link

intellix commented Jan 9, 2020

This would be awesome in Angular. When transitioning to observable values the view can get real messy and pyramid like:

<ng-container *ngIf="(a$ | async) as a">
  <ng-container *ngIf="(b$ | async) as b">
    <ng-container *ngIf="(c$ | async) as c">
      {{ a }} {{ b }} {{ c }}
      {{ a }} {{ b }} {{ c }}
    </ng-container>
  </ng-container>  
</ng-container>

Would be nice to just use a single async pipe at the top and use values like they're not async. Ofc it's not to do with any frontend framework but it's one of the things that makes me groan about refactoring to use Rx

<ng-container *ngIf="(abc$ | async) as abc">
  {{ abc.a }} {{ abc.b }} {{ abc.c }}
  {{ abc.a }} {{ abc.b }} {{ abc.c }}
</ng-container>

@amakhrov
Copy link

Currently a workaround is to use array-based combineLatest followed by map():

const abc$ = combineLatest([a$, b$, c$]).pipe(
  map(([a, b, c]) => ({a, b, c}))
)

It's not too bad, but it results it repeating code (also error-prone, as @Akxe has pointed out)

Also it's probably not too hard to create a custom wrapper to implement that in your project.

@rraziel
Copy link
Contributor

rraziel commented Mar 22, 2020

Is there any plan on implementing this, or at least would a pull request be considered for merging?

@Goobles
Copy link

Goobles commented Apr 14, 2020

You can create your own operator function as a workaround:
https://gist.github.com/Goobles/45f0b3027d31884dba0b164ee2cc50ea

@Akxe
Copy link
Author

Akxe commented Jan 7, 2021

@rraziel I belive this can now be closed, right?

@rraziel
Copy link
Contributor

rraziel commented Jan 8, 2021

@Akxe this is available in rxjs 7 yes

@tmtron
Copy link

tmtron commented Aug 17, 2021

RxJs7 docs: Combine a dictionary of Observables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs and issues for features
Projects
None yet
Development

No branches or pull requests

7 participants