refactor: cleanup untracked in core (#60150)

Re-export untracked in core from primitives

PR Close #60150
This commit is contained in:
Taygan Caldwell 2025-03-05 18:32:14 -08:00 committed by Andrew Kushnir
parent 9657c7d699
commit bc95edf240

View file

@ -6,19 +6,12 @@
* found in the LICENSE file at https://angular.dev/license
*/
import {setActiveConsumer} from '@angular/core/primitives/signals';
import {untracked as untrackedPrimitive} from '@angular/core/primitives/signals';
/**
* Execute an arbitrary function in a non-reactive (non-tracking) context. The executed function
* can, optionally, return a value.
*/
export function untracked<T>(nonReactiveReadsFn: () => T): T {
const prevConsumer = setActiveConsumer(null);
// We are not trying to catch any particular errors here, just making sure that the consumers
// stack is restored in case of errors.
try {
return nonReactiveReadsFn();
} finally {
setActiveConsumer(prevConsumer);
}
return untrackedPrimitive(nonReactiveReadsFn);
}