-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Add "equal" field to ToSignalOptions #52176
Comments
We could, although I wonder if it is not better handled at the Observable chain level. |
At that level, you can control if an observable should emit, but you'll need to create a copy of the produced value if you want to "force" a signal to emit a notification. map((obj) => {
if (obj == null) {
return obj;
}
if (typeof obj === 'object') {
if (Array.isArray(obj)) {
return obj.slice();
}
if (obj instanceof Map) {
return new Map(obj);
}
if (obj instanceof Set) {
return new Set(obj);
}
return { ...obj };
}
return obj;
}), (this code is just an illustration, it's not tested or optimized) Also, there are some objects that can not be cloned (even using |
I don't think custom equality solves this problem. In particular, custom equality can decide that two referentially unequal values are still "equal" and block the notification, but it cannot decide that a single value has changed if its object identity is the same. That is, This makes me wonder if we should circumvent custom equality entirely when the value is referentially equivalent... |
Of course it can. Map remains the same object when you modify one of its keys. DOM node remains the same when you modify children. And these are examples of structures that are pretty valid in the role of mutable structures. Immutability has performance costs, and there are cases when you want to say to signal “Yes, it is the same object, but it was updated - I know it for sure”.
That would make signals unusable for mutable data structures. |
There is another case (that is most important for me): you want the signal to send a notification every time observable emits a new value, even if this value (accidentally) is the same object. |
We removed Suppose you have a <sink-cmp [sink]="source()" /> If sink.set(source())` The problem is that mutability gets lost here - change detection will only set |
But signals are not only for change detection. There might be layers and layers of computed signals before the result is consumed by the change detection logic. I’ll quote my tweet:
If you convert signals into a Change Detection Reactivity Primitive, they will only be used as the “async” pipe - users will convert observables into signals only at the last step when they go to the template. Maybe it's exactly what you want, I don't know. |
This request has no sense after #52465 ;) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
Consider adding "equal" field to the
ToSignalOptions
interface, to let users override the equality check function of the created signal.Proposed solution
ToSignalOptions
withequal
Alternatives considered
Can't find any.
The text was updated successfully, but these errors were encountered: