| 1 | import type { DevModeChecks } from '../types'
|
|---|
| 2 |
|
|---|
| 3 | /**
|
|---|
| 4 | * Global configuration for development mode checks. This specifies the default
|
|---|
| 5 | * frequency at which each development mode check should be performed.
|
|---|
| 6 | *
|
|---|
| 7 | * @since 5.0.0
|
|---|
| 8 | * @internal
|
|---|
| 9 | */
|
|---|
| 10 | export const globalDevModeChecks: DevModeChecks = {
|
|---|
| 11 | inputStabilityCheck: 'once',
|
|---|
| 12 | identityFunctionCheck: 'once'
|
|---|
| 13 | }
|
|---|
| 14 |
|
|---|
| 15 | /**
|
|---|
| 16 | * Overrides the development mode checks settings for all selectors.
|
|---|
| 17 | *
|
|---|
| 18 | * Reselect performs additional checks in development mode to help identify and
|
|---|
| 19 | * warn about potential issues in selector behavior. This function allows you to
|
|---|
| 20 | * customize the behavior of these checks across all selectors in your application.
|
|---|
| 21 | *
|
|---|
| 22 | * **Note**: This setting can still be overridden per selector inside `createSelector`'s `options` object.
|
|---|
| 23 | * See {@link https://github.com/reduxjs/reselect#2-per-selector-by-passing-an-identityfunctioncheck-option-directly-to-createselector per-selector-configuration}
|
|---|
| 24 | * and {@linkcode CreateSelectorOptions.identityFunctionCheck identityFunctionCheck} for more details.
|
|---|
| 25 | *
|
|---|
| 26 | * _The development mode checks do not run in production builds._
|
|---|
| 27 | *
|
|---|
| 28 | * @param devModeChecks - An object specifying the desired settings for development mode checks. You can provide partial overrides. Unspecified settings will retain their current values.
|
|---|
| 29 | *
|
|---|
| 30 | * @example
|
|---|
| 31 | * ```ts
|
|---|
| 32 | * import { setGlobalDevModeChecks } from 'reselect'
|
|---|
| 33 | * import { DevModeChecks } from '../types'
|
|---|
| 34 | *
|
|---|
| 35 | * // Run only the first time the selector is called. (default)
|
|---|
| 36 | * setGlobalDevModeChecks({ inputStabilityCheck: 'once' })
|
|---|
| 37 | *
|
|---|
| 38 | * // Run every time the selector is called.
|
|---|
| 39 | * setGlobalDevModeChecks({ inputStabilityCheck: 'always' })
|
|---|
| 40 | *
|
|---|
| 41 | * // Never run the input stability check.
|
|---|
| 42 | * setGlobalDevModeChecks({ inputStabilityCheck: 'never' })
|
|---|
| 43 | *
|
|---|
| 44 | * // Run only the first time the selector is called. (default)
|
|---|
| 45 | * setGlobalDevModeChecks({ identityFunctionCheck: 'once' })
|
|---|
| 46 | *
|
|---|
| 47 | * // Run every time the selector is called.
|
|---|
| 48 | * setGlobalDevModeChecks({ identityFunctionCheck: 'always' })
|
|---|
| 49 | *
|
|---|
| 50 | * // Never run the identity function check.
|
|---|
| 51 | * setGlobalDevModeChecks({ identityFunctionCheck: 'never' })
|
|---|
| 52 | * ```
|
|---|
| 53 | * @see {@link https://reselect.js.org/api/development-only-stability-checks Development-Only Stability Checks}
|
|---|
| 54 | * @see {@link https://reselect.js.org/api/development-only-stability-checks#1-globally-through-setglobaldevmodechecks global-configuration}
|
|---|
| 55 | *
|
|---|
| 56 | * @since 5.0.0
|
|---|
| 57 | * @public
|
|---|
| 58 | */
|
|---|
| 59 | export const setGlobalDevModeChecks = (
|
|---|
| 60 | devModeChecks: Partial<DevModeChecks>
|
|---|
| 61 | ) => {
|
|---|
| 62 | Object.assign(globalDevModeChecks, devModeChecks)
|
|---|
| 63 | }
|
|---|