forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): create function to assert not running inside reactive con…
…text (angular#52049) Some functions or code should never run inside reactive contexts. A function to assert that will help putting guard rails in place. PR Close angular#52049
- Loading branch information
1 parent
2b216bb
commit 81db497
Showing
7 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {RuntimeError, RuntimeErrorCode} from '../../errors'; | ||
import {getActiveConsumer} from '../../signals'; | ||
|
||
/** | ||
* Asserts that the current stack frame is not within a reactive context. Useful | ||
* to disallow certain code from running inside a reactive context (see {@link toSignal}). | ||
* | ||
* @param debugFn a reference to the function making the assertion (used for the error message). | ||
* | ||
* @publicApi | ||
*/ | ||
export function assertNotInReactiveContext(debugFn: Function, extraContext?: string): void { | ||
// Taking a `Function` instead of a string name here prevents the unminified name of the function | ||
// from being retained in the bundle regardless of minification. | ||
if (getActiveConsumer() !== null) { | ||
throw new RuntimeError( | ||
RuntimeErrorCode.ASSERTION_NOT_INSIDE_REACTIVE_CONTEXT, | ||
ngDevMode && | ||
`${debugFn.name}() cannot be called from within a reactive context.${ | ||
extraContext ? ` ${extraContext}` : ''}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters