mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
refactor: cleanup untracked in core (#60150)
Re-export untracked in core from primitives PR Close #60150
This commit is contained in:
parent
9657c7d699
commit
bc95edf240
1 changed files with 2 additions and 9 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue