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

Make valueChanges a ReplaySubject(1)? #72

Closed
Airblader opened this issue Feb 1, 2019 · 6 comments
Closed

Make valueChanges a ReplaySubject(1)? #72

Airblader opened this issue Feb 1, 2019 · 6 comments
Labels
Comp: Core Core functionality of ngqp Priority: Medium Users can work without this for now, but this should be fixed soon-ish Status: Accepted This issue has been approved and PRs will be accepted Type: Feature If you want to add something that doesn't exist yet

Comments

@Airblader
Copy link
Collaborator

Airblader commented Feb 1, 2019

What's your idea?

We should decide whether the valueChanges observables should be backed by plain Subjects (as-is) or by a ReplaySubject(1).

In the Forms API, it is backed by a Subject, but arguably the initial synchronization from the URL might justify treating it differently in ngqp.

@Airblader Airblader added Type: Feature If you want to add something that doesn't exist yet Status: Discussion We're not yet sure whether or how to implement this feature Comp: Core Core functionality of ngqp Priority: Medium Users can work without this for now, but this should be fixed soon-ish Status: Accepted This issue has been approved and PRs will be accepted and removed Status: Discussion We're not yet sure whether or how to implement this feature Status: Accepted This issue has been approved and PRs will be accepted labels Feb 1, 2019
@Airblader
Copy link
Collaborator Author

I really want to say we should do this because otherwise something reactive like

this.items$ = this.paramGroup.valueChanges.pipe(switchMap(…));

combined with the async pipe won't work with the initial sync. I think the benefit of supporting this outweighs the deviation from the Forms API.

@Airblader Airblader added Status: Accepted This issue has been approved and PRs will be accepted and removed Status: Discussion We're not yet sure whether or how to implement this feature labels Feb 1, 2019
@Airblader
Copy link
Collaborator Author

OK, maybe it's not as decisive quite yet. The deviation doesn't bother me as much as the semantics of the word "valueChanges". Perhaps having value$ as a separate observable backed by the ReplaySubject(1) would be more appropriate?

@Airblader
Copy link
Collaborator Author

Airblader commented Feb 2, 2019

This can be achieved using

Edit: this contained a mistake, please see the comment further down for the correct version.

It's not super pretty, but let's keep it like this for now.

@Airblader
Copy link
Collaborator Author

See angular/angular#15282

@osahner
Copy link

osahner commented Jun 15, 2020

This does not work (at least not with angular 9.1). stackblitz

@steinsag
Copy link

Just in case someone else stumbles upon this thread... The correct work-around is:

this.items$ = defer(() => this.paramGroup.valueChanges.pipe(startWith(this.paramGroup.value), switchMap(…)));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Comp: Core Core functionality of ngqp Priority: Medium Users can work without this for now, but this should be fixed soon-ish Status: Accepted This issue has been approved and PRs will be accepted Type: Feature If you want to add something that doesn't exist yet
Projects
None yet
Development

No branches or pull requests

3 participants