-
Notifications
You must be signed in to change notification settings - Fork 27.1k
Open
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecross-cutting: signalsfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues
Milestone
Description
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
Current Signal reads always pull. In Angular, reading a Signal (even via untracked) forces a recomputation if the producer is "dirty." This makes it impossible to observe a Signal without potentially triggering expensive work or side effects (e.g., httpResource fetching).
Proposed solution
Introduce a passiveRead(signal) utility.
- Behaviour: It returns a wrapper object (e.g., { hasValue: true, value: T } | { hasValue: false, value: undefined }).
- Reactive Graph: If used inside an effect or computed, it adds the caller to the dependency graph (so the effect re-runs when the signal changes), but it never triggers a re-computation of the source signal if it is currently dirty.
- Return Value: It will return the signal's current value unless the value has not yet been computed
Use Case: Conditional Observer Syncing
In complex scenarios, offent including external libraries, the developer need to sync data and options to the library, but it would be beneficial if it could be done in a way that would not make all of the options/data computed unless the resulting values is actually needed.
Use Case: toLazyObservable
This would provide a solution to #55337
effect(() => {
const result = passiveRead(myResource.value);
if (!result.hasValue) {
// If result.hasValue is false, no computation was forced.
return;
}
// result.hasValue is true only if the signal is being also observed by some other non-passive observers
console.log('Passive Update:', result.value);
});Alternatives considered
I do not think there is a workaround.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecross-cutting: signalsfeatureLabel used to distinguish feature request from other issuesLabel used to distinguish feature request from other issues