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

toSignal does not change if new published value passes equality check and there is no way to modify that #55573

Open
RaederDev opened this issue Apr 28, 2024 · 2 comments
Labels
area: core Issues related to the framework runtime cross-cutting: signals feature Issue that requests a new feature
Milestone

Comments

@RaederDev
Copy link

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

Apologies if this is an oversight on my end but I think this would be a good change to make.
I have a service that create a BehaviourSubject that returns emits an array, I then consume the Observable like this:

public connections = toSignal<Array<Connection>>(
  this.connectionManagerService.connections,
  { requireSync: true },
);

The issue is once that service pushes a new value it just modifies the existing array so the default signal equality check of "===" passes. In my case I was able to just modify the service that it create a new copy of the array every time it publishes a new value but that doesn't work for 3rd party libraries that may have the same behaviour.

Proposed solution

Allow specifying a custom signal equality function {equal: () => {}} like you can already do for normal signals.
I dug through the code a bit and found that toSignal just uses a signal under the hood:
https://github.com/angular/angular/blob/main/packages/core/rxjs-interop/src/to_signal.ts#L125

I don't know much about Angular internals but would it be possible to just pass through a user defined function to that signal to allow for that?

Alternatives considered

I don't know what else would be a good solution for this use-case.

@JoostK
Copy link
Member

JoostK commented Apr 29, 2024

This has been discussed in #52176

@pkozlowski-opensource pkozlowski-opensource added the area: core Issues related to the framework runtime label Apr 29, 2024
@ngbot ngbot bot added this to the needsTriage milestone Apr 29, 2024
@alxhub alxhub added the feature Issue that requests a new feature label Apr 29, 2024
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Apr 29, 2024
@alxhub
Copy link
Member

alxhub commented Apr 29, 2024

I think we should do this. Since the prior discussion, we've allowed equality checks on signals to decide that x != x (basically, any new value should be treated as a change). It makes sense to extend this to toSignal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: core Issues related to the framework runtime cross-cutting: signals feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

4 participants