mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor: cleanup untracked in core (#60150)
Re-export untracked in core from primitives PR Close #60150
This commit is contained in:
committed by
Andrew Kushnir
parent
9657c7d699
commit
bc95edf240
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user