Skip to content

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

@RaederDev

Description

@RaederDev

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions