@wordpress/data 10.43.1-next.v.202604091042.0 → 10.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/use-select/index.cjs.map +2 -2
- package/build/types.cjs.map +1 -1
- package/build-module/components/use-select/index.mjs.map +2 -2
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/types.d.ts +8 -3
- package/build-types/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/components/use-select/index.ts +6 -0
- package/src/components/use-select/test/index.js +6 -1
- package/src/types.ts +14 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/use-select/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\nimport type {\n\tMapSelect,\n\tSelectFunction,\n\tStoreDescriptor,\n\tAnyConfig,\n\tUseSelectReturn,\n\tDataRegistry,\n} from '../../types';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference(\n\ta: Record< string, unknown >,\n\tb: Record< string, unknown >\n): void {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\ninterface StoreSubscriber {\n\tsubscribe: ( listener: () => void ) => () => void;\n\tupdateStores: ( newStores: string[] ) => void;\n}\n\nfunction Store( registry: DataRegistry, suspense: boolean ) {\n\tconst select = ( suspense\n\t\t? registry.suspendSelect\n\t\t: registry.select ) as unknown as SelectFunction;\n\tconst queueContext = {};\n\tlet lastMapSelect: MapSelect | undefined;\n\tlet lastMapResult: unknown;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync: boolean | undefined;\n\tlet subscriber: StoreSubscriber | undefined;\n\tlet didWarnUnstableReference: boolean | undefined;\n\tconst storeStatesOnMount = new Map< string, unknown >();\n\n\tfunction getStoreState( name: string ): unknown {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores: string[] ): StoreSubscriber => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set< ( storeName: string ) => void >();\n\n\t\tfunction subscribe( listener: () => void ): () => void {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs: Array< VoidFunction > = [];\n\t\t\tfunction subscribeStore( storeName: string ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores: string[] ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect: MapSelect, isAsync: boolean ) => {\n\t\tfunction updateValue(): void {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null as string[] | null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( ( globalThis as any ).SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current! ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current! );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current! );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber!.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName: StoreDescriptor< AnyConfig > | string ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect(\n\tsuspense: boolean,\n\tmapSelect: MapSelect,\n\tdeps: unknown[]\n) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @param mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return The selected data or store selectors.\n */\nexport default function useSelect<\n\tT extends MapSelect | StoreDescriptor< AnyConfig >,\n>( mapSelect: T, deps?: unknown[] ): UseSelectReturn< T > {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\n\treturn (\n\t\tstaticSelectMode\n\t\t\t? _useStaticSelect( mapSelect as StoreDescriptor< AnyConfig > )\n\t\t\t: _useMappingSelect( false, mapSelect as MapSelect, deps! )\n\t) as UseSelectReturn< T >;\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @param mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect< T extends MapSelect >(\n\tmapSelect: T,\n\tdeps: unknown[]\n): ReturnType< T > {\n\treturn _useMappingSelect( true, mapSelect, deps ) as ReturnType< T >;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["// useSelect is a low-level hook that intentionally breaks rules-of-hooks\n// in its internal helpers (_useStaticSelect, _useMappingSelect) where\n// hooks are called inside non-hook functions and conditionally dispatched.\n/* eslint-disable react-hooks/rules-of-hooks, react-compiler/react-compiler */\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\nimport type {\n\tMapSelect,\n\tSelectFunction,\n\tStoreDescriptor,\n\tAnyConfig,\n\tUseSelectReturn,\n\tDataRegistry,\n} from '../../types';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference(\n\ta: Record< string, unknown >,\n\tb: Record< string, unknown >\n): void {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\ninterface StoreSubscriber {\n\tsubscribe: ( listener: () => void ) => () => void;\n\tupdateStores: ( newStores: string[] ) => void;\n}\n\nfunction Store( registry: DataRegistry, suspense: boolean ) {\n\tconst select = ( suspense\n\t\t? registry.suspendSelect\n\t\t: registry.select ) as unknown as SelectFunction;\n\tconst queueContext = {};\n\tlet lastMapSelect: MapSelect | undefined;\n\tlet lastMapResult: unknown;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync: boolean | undefined;\n\tlet subscriber: StoreSubscriber | undefined;\n\tlet didWarnUnstableReference: boolean | undefined;\n\tconst storeStatesOnMount = new Map< string, unknown >();\n\n\tfunction getStoreState( name: string ): unknown {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores: string[] ): StoreSubscriber => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set< ( storeName: string ) => void >();\n\n\t\tfunction subscribe( listener: () => void ): () => void {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs: Array< VoidFunction > = [];\n\t\t\tfunction subscribeStore( storeName: string ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores: string[] ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect: MapSelect, isAsync: boolean ) => {\n\t\tfunction updateValue(): void {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null as string[] | null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( ( globalThis as any ).SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current! ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current! );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current! );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber!.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName: StoreDescriptor< AnyConfig > | string ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect(\n\tsuspense: boolean,\n\tmapSelect: MapSelect,\n\tdeps: unknown[]\n) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @param mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return The selected data or store selectors.\n */\nexport default function useSelect<\n\tT extends MapSelect | StoreDescriptor< AnyConfig >,\n>( mapSelect: T, deps?: unknown[] ): UseSelectReturn< T > {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\n\treturn (\n\t\tstaticSelectMode\n\t\t\t? _useStaticSelect( mapSelect as StoreDescriptor< AnyConfig > )\n\t\t\t: _useMappingSelect( false, mapSelect as MapSelect, deps! )\n\t) as UseSelectReturn< T >;\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @param mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect< T extends MapSelect >(\n\tmapSelect: T,\n\tdeps: unknown[]\n): ReturnType< T > {\n\treturn _useMappingSelect( true, mapSelect, deps ) as ReturnType< T >;\n}\n/* eslint-enable react-hooks/rules-of-hooks, react-compiler/react-compiler */\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,4BAA4B;AAC5B,qBAMO;AACP,8BAA+B;AAK/B,0BAAwB;AACxB,4BAAyB;AAUzB,IAAM,kBAAc,mCAAY;AAEhC,SAAS,wBACR,GACA,GACO;AACP,MAAK,CAAE,KAAK,CAAE,GAAI;AACjB;AAAA,EACD;AAEA,QAAM,OACL,OAAO,MA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": ["/**\n * External dependencies\n */\n\nimport type {\n\t// eslint-disable-next-line no-restricted-imports\n\tcombineReducers as reduxCombineReducers,\n\tStore as ReduxStore,\n} from 'redux';\n\n/**\n * Internal dependencies\n */\nimport type { DataEmitter } from './utils/emitter';\nimport type {\n\tMetadataSelectors,\n\tMetadataActions,\n} from './redux-store/metadata/types';\n\ntype MapOf< T > = { [ name: string ]: T };\n\nexport type ActionCreator = ( ...args: any[] ) => any | Generator;\nexport type Resolver = Function | Generator;\nexport type Selector = Function;\n\nexport type AnyConfig = ReduxStoreConfig< any, any, any >;\n\nexport interface StoreInstance< Config extends AnyConfig > {\n\tgetSelectors: () => SelectorsOf< Config >;\n\tgetActions: () => ActionCreatorsOf< Config >;\n\tsubscribe: ( listener: () => void ) => () => void;\n}\n\nexport interface StoreDescriptor< Config extends AnyConfig = AnyConfig > {\n\t/**\n\t * Store Name\n\t */\n\tname: string;\n\n\t/**\n\t * Creates a store instance\n\t */\n\tinstantiate: ( registry: DataRegistry ) => StoreInstance< Config >;\n}\n\nexport interface ReduxStoreConfig< State, ActionCreators, Selectors > {\n\tinitialState?: State;\n\treducer: ( state: any, action: any ) => any;\n\tactions?: ActionCreators;\n\tresolvers?: MapOf< Resolver >;\n\tselectors?: Selectors;\n\tcontrols?: MapOf< Function >;\n}\n\n// Return type for the useSelect() hook.\nexport type UseSelectReturn< F extends MapSelect | StoreDescriptor< any > > =\n\tF extends MapSelect\n\t\t? ReturnType< F >\n\t\t: F extends StoreDescriptor< any >\n\t\t? CurriedSelectorsOf< F >\n\t\t: never;\n\n// Return type for the useDispatch() hook.\nexport type UseDispatchReturn< StoreNameOrDescriptor > =\n\tStoreNameOrDescriptor extends StoreDescriptor< any >\n\t\t? ActionCreatorsOf< StoreNameOrDescriptor >\n\t\t: StoreNameOrDescriptor extends undefined\n\t\t? DispatchFunction\n\t\t: any;\n\nexport type DispatchFunction = < StoreNameOrDescriptor >(\n\tstore: StoreNameOrDescriptor\n) => DispatchReturn< StoreNameOrDescriptor >;\n\nexport type DispatchReturn< StoreNameOrDescriptor > =\n\tStoreNameOrDescriptor extends StoreDescriptor< any >\n\t\t? ActionCreatorsOf< StoreNameOrDescriptor >\n\t\t: unknown;\n\nexport type MapSelect = (\n\tselect: SelectFunction,\n\tregistry: DataRegistry\n) => any;\n\nexport type SelectFunction = < S >( store: S ) => CurriedSelectorsOf< S >;\n\n/**\n * Callback for store's `subscribe()` method that\n * runs when the store data has changed.\n */\nexport type ListenerFunction = () => void;\n\nexport type CurriedSelectorsOf< S > = S extends StoreDescriptor<\n\tReduxStoreConfig< any, any, infer Selectors >\n>\n\t? {\n\t\t\t[ key in keyof Selectors ]: CurriedState< Selectors[ key ] >;\n\t } & MetadataSelectors< S >\n\t: never;\n\n/**\n * Like CurriedState but wraps the return type in a Promise.\n * Used for resolveSelect where selectors return promises.\n *\n * For generic selectors that define PromiseCurriedSignature, that signature\n * is used directly to preserve generic type parameters (which would otherwise\n * be lost when using `infer`).\n */\ntype CurriedStateWithPromise< F > =\n\tF extends SelectorWithCustomCurrySignature & {\n\t\tPromiseCurriedSignature: infer S;\n\t}\n\t\t? S\n\t\t: F extends SelectorWithCustomCurrySignature & {\n\t\t\t\tCurriedSignature: ( ...args: infer P ) => infer R;\n\t\t }\n\t\t? ( ...args: P ) => Promise< R >\n\t\t: F extends ( state: any, ...args: infer P ) => infer R\n\t\t? ( ...args: P ) => Promise< R >\n\t\t: F;\n\n/**\n * Like CurriedSelectorsOf but each selector returns a Promise.\n * Used for resolveSelect.\n */\nexport type CurriedSelectorsResolveOf< S > = S extends StoreDescriptor<\n\tReduxStoreConfig< any, any, infer Selectors >\n>\n\t? {\n\t\t\t[ key in keyof Selectors ]: CurriedStateWithPromise<\n\t\t\t\tSelectors[ key ]\n\t\t\t>;\n\t }\n\t: never;\n\n/**\n * Removes the first argument from a function.\n *\n * By default, it removes the `state` parameter from\n * registered selectors since that argument is supplied\n * by the editor when calling `select(\u2026)`.\n *\n * For functions with no arguments, which some selectors\n * are free to define, returns the original function.\n *\n * It is possible to manually provide a custom curried signature\n * and avoid the automatic inference. When the\n * F generic argument passed to this helper extends the\n * SelectorWithCustomCurrySignature type, the F['CurriedSignature']\n * property is used verbatim.\n *\n * This is useful because TypeScript does not correctly remove\n * arguments from complex function signatures constrained by\n * interdependent generic parameters.\n * For more context, see https://github.com/WordPress/gutenberg/pull/41578\n */\ntype CurriedState< F > = F extends SelectorWithCustomCurrySignature\n\t? F[ 'CurriedSignature' ]\n\t: F extends ( state: any, ...args: infer P ) => infer R\n\t? ( ...args: P ) => R\n\t: F;\n\n/**\n * Utility to manually specify curried selector signatures.\n *\n * It comes handy when TypeScript can't automatically produce the\n * correct curried function signature. For example:\n *\n * ```ts\n * type BadlyInferredSignature = CurriedState<\n * <K extends string | number>(\n * state: any,\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ) => K\n * >\n * // BadlyInferredSignature evaluates to:\n * // (kind: string number, key: false \"one value\") => string number\n * ```\n *\n * With SelectorWithCustomCurrySignature, we can provide a custom\n * signature and avoid relying on TypeScript inference:\n * ```ts\n * interface MySelectorSignature extends SelectorWithCustomCurrySignature {\n * <K extends string | number>(\n * state: any,\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ): K;\n *\n * CurriedSignature: <K extends string | number>(\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ): K;\n * }\n * type CorrectlyInferredSignature = CurriedState<MySelectorSignature>\n * // <K extends string | number>(kind: K, key: K extends string ? 'one value' : false): K;\n *\n * For even more context, see https://github.com/WordPress/gutenberg/pull/41578\n * ```\n */\nexport interface SelectorWithCustomCurrySignature {\n\tCurriedSignature: Function;\n\tPromiseCurriedSignature?: Function;\n}\n\n/**\n * A store name or store descriptor, used throughout the API.\n */\nexport type StoreNameOrDescriptor = string | StoreDescriptor;\n\n/**\n * An isolated orchestrator of store registrations.\n *\n * Returned by `createRegistry`. Provides methods to register stores,\n * select data, dispatch actions, and subscribe to changes.\n */\nexport interface DataRegistry {\n\tbatch: ( callback: () => void ) => void;\n\tstores: Record< string, InternalStoreInstance >;\n\tnamespaces: Record< string, InternalStoreInstance >;\n\tsubscribe: (\n\t\tlistener: ListenerFunction,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t) => () => void;\n\tselect: {\n\t\t< S extends StoreDescriptor< any > >(\n\t\t\tstore: S\n\t\t): CurriedSelectorsOf< S >;\n\t\t(\n\t\t\tstore: StoreNameOrDescriptor\n\t\t): Record< string, ( ...args: any[] ) => any >;\n\t};\n\tresolveSelect: {\n\t\t< S extends StoreDescriptor< any > >(\n\t\t\tstore: S\n\t\t): CurriedSelectorsResolveOf< S >;\n\t\t(\n\t\t\tstore: StoreNameOrDescriptor\n\t\t): Record< string, ( ...args: any[] ) => Promise< any > >;\n\t};\n\tsuspendSelect: {\n\t\t< S extends StoreDescriptor< any > >(\n\t\t\tstore: S\n\t\t): CurriedSelectorsOf< S >;\n\t\t(\n\t\t\tstore: StoreNameOrDescriptor\n\t\t): Record< string, ( ...args: any[] ) => any >;\n\t};\n\tdispatch: {\n\t\t< S extends StoreDescriptor< any > >( store: S ): ActionCreatorsOf< S >;\n\t\t(\n\t\t\tstore: StoreNameOrDescriptor\n\t\t): Record< string, ( ...args: any[] ) => any >;\n\t};\n\tuse: (\n\t\tplugin: DataPlugin,\n\t\toptions?: Record< string, unknown >\n\t) => DataRegistry;\n\tregister: ( store: StoreDescriptor< any > ) => void;\n\tregisterGenericStore: (\n\t\tname: string,\n\t\tstore: StoreInstance< AnyConfig >\n\t) => void;\n\tregisterStore: (\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) => ReduxStore;\n\t__unstableMarkListeningStores: < T >(\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t) => T;\n}\n\n/**\n * The plugin function signature.\n */\nexport type DataPlugin = (\n\tregistry: DataRegistry,\n\toptions?: Record< string, unknown >\n) => Partial< DataRegistry >;\n\n/**\n * Status of a selector resolution.\n */\nexport type ResolutionStatus = 'resolving' | 'finished' | 'error';\n\n/**\n * State value for a single resolution.\n */\nexport type ResolutionState =\n\t| { status: 'resolving' }\n\t| { status: 'finished' }\n\t| { status: 'error'; error: Error | unknown };\n\n/**\n * A normalized resolver with a `fulfill` method and optional `isFulfilled`.\n */\nexport interface NormalizedResolver {\n\t/**\n\t * The function to call to fulfill the resolver.\n\t */\n\tfulfill: ( ...args: any[] ) => any;\n\t/**\n\t * Optional function to check if the resolver is already fulfilled.\n\t */\n\tisFulfilled?: ( state: any, ...args: any[] ) => boolean;\n\t/**\n\t * Optional function to check if the resolver should be invalidated.\n\t */\n\tshouldInvalidate?: ( action: any, ...args: any[] ) => boolean;\n}\n\n/**\n * A bound selector with optional resolver metadata.\n */\nexport interface BoundSelector {\n\t( ...args: any[] ): any;\n\t/**\n\t * Whether this selector has a resolver attached.\n\t */\n\thasResolver: boolean;\n\t/**\n\t * Optional function to normalize the arguments.\n\t */\n\t__unstableNormalizeArgs?: ( args: any[] ) => any[];\n\t/**\n\t * Whether this selector is a registry selector.\n\t */\n\tisRegistrySelector?: boolean;\n\t/**\n\t * The registry instance this selector is bound to.\n\t */\n\tregistry?: DataRegistry;\n}\n\n/**\n * The shape of a store instance as seen internally by the registry.\n * Extends the public StoreInstance with additional internal properties.\n */\nexport interface InternalStoreInstance< Config extends AnyConfig = AnyConfig >\n\textends StoreInstance< Config > {\n\t/**\n\t * The Redux store instance (only for Redux-based stores).\n\t */\n\tstore?: ReduxStore;\n\t/**\n\t * The internal emitter for pause/resume batching.\n\t */\n\temitter: DataEmitter;\n\t/**\n\t * The combined reducer.\n\t */\n\treducer?: ( state: any, action: any ) => any;\n\t/**\n\t * Bound actions object.\n\t */\n\tactions?: Record< string, ActionCreator >;\n\t/**\n\t * Bound selectors object.\n\t */\n\tselectors?: Record< string, Selector >;\n\t/**\n\t * Resolver definitions.\n\t */\n\tresolvers?: Record< string, NormalizedResolver >;\n\t/**\n\t * Returns resolve-wrapped selectors.\n\t */\n\tgetResolveSelectors?: () => Record<\n\t\tstring,\n\t\t( ...args: any[] ) => Promise< any >\n\t>;\n\t/**\n\t * Returns suspense-wrapped selectors.\n\t */\n\tgetSuspendSelectors?: () => Record< string, ( ...args: any[] ) => any >;\n}\n\n/**\n * Control descriptor for the controls system.\n */\nexport interface ControlDescriptor {\n\t/**\n\t * The type of the control action.\n\t */\n\ttype: string;\n\t/**\n\t * The store key to target.\n\t */\n\tstoreKey: string;\n\t/**\n\t * The name of the selector (for select/resolveSelect controls).\n\t */\n\tselectorName?: string;\n\t/**\n\t * The name of the action (for dispatch controls).\n\t */\n\tactionName?: string;\n\t/**\n\t * Arguments for the selector or action.\n\t */\n\targs: any[];\n}\n\n/**\n * Storage interface (Web Storage API subset).\n */\nexport interface StorageInterface {\n\tgetItem: ( key: string ) => string | null;\n\tsetItem: ( key: string, value: string ) => void;\n\tremoveItem?: ( key: string ) => void;\n\tclear?: VoidFunction;\n}\n\n// Type Helpers.\n\nexport type ConfigOf< S > = S extends StoreDescriptor< infer C > ? C : never;\n\nexport type ActionCreatorsOf< T > = T extends StoreDescriptor<\n\tReduxStoreConfig< any, infer ActionCreators, any >\n>\n\t? PromisifiedActionCreators< ActionCreators > & MetadataActions< T >\n\t: T extends ReduxStoreConfig< any, infer ActionCreators, any >\n\t? PromisifiedActionCreators< ActionCreators >\n\t: never;\n\n// Takes an object containing all action creators for a store and updates the\n// return type of each action creator to account for internal registry details --\n// for example, dispatched actions are wrapped with a Promise.\nexport type PromisifiedActionCreators< ActionCreators > = {\n\t[ Action in keyof ActionCreators ]: ActionCreators[ Action ] extends ActionCreator\n\t\t? PromisifyActionCreator< ActionCreators[ Action ] >\n\t\t: ActionCreators[ Action ];\n};\n\n// Wraps action creator return types with a Promise and handles thunks and generators.\nexport type PromisifyActionCreator< Action extends ActionCreator > = (\n\t...args: Parameters< Action >\n) => Promise<\n\tReturnType< Action > extends ( ..._args: any[] ) => any\n\t\t? ThunkReturnType< Action >\n\t\t: ReturnType< Action > extends Generator< any, infer TReturn, any >\n\t\t? TReturn\n\t\t: ReturnType< Action >\n>;\n\n// A thunk is an action creator which returns a function, which can optionally\n// return a Promise. The double ReturnType unwraps the innermost function's\n// return type, and Awaited gets the type the Promise resolves to. If the return\n// type is not a Promise, Awaited returns that original type.\nexport type ThunkReturnType< Action extends ActionCreator > = Awaited<\n\tReturnType< ReturnType< Action > >\n>;\n\ntype SelectorsOf< Config extends AnyConfig > = Config extends ReduxStoreConfig<\n\tany,\n\tany,\n\tinfer Selectors\n>\n\t? { [ name in keyof Selectors ]: Function }\n\t: never;\n\n/**\n * The argument object passed to every thunk function. When parameterized with\n * a store descriptor, `dispatch`, `select`, and `resolveSelect` are fully\n * typed against that store's actions and selectors.\n *\n * @example\n * ```ts\n * const myAction =\n * ( id: number ) =>\n * async ( { dispatch, select }: ThunkArgs< typeof myStore > ) => {\n * const record = select.getRecord( id );\n * dispatch.setLoading( true );\n * };\n * ```\n */\nexport interface ThunkArgs< S extends StoreDescriptor = StoreDescriptor > {\n\tdispatch: ActionCreatorsOf< S > &\n\t\t( ( action: Record< string, unknown > | Function ) => unknown );\n\tselect: CurriedSelectorsOf< S >;\n\tresolveSelect: CurriedSelectorsResolveOf< S >;\n\tregistry: DataRegistry;\n}\n\nexport type combineReducers = typeof reduxCombineReducers;\n"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n\nimport type {\n\t// eslint-disable-next-line no-restricted-imports\n\tcombineReducers as reduxCombineReducers,\n\tStore as ReduxStore,\n} from 'redux';\n\n/**\n * Internal dependencies\n */\nimport type { DataEmitter } from './utils/emitter';\nimport type {\n\tMetadataSelectors,\n\tMetadataActions,\n} from './redux-store/metadata/types';\n\ntype MapOf< T > = { [ name: string ]: T };\n\nexport type ActionCreator = ( ...args: any[] ) => any | Generator;\nexport type Resolver = Function | Generator;\nexport type Selector = Function;\n\nexport type AnyConfig = ReduxStoreConfig< any, any, any >;\n\nexport interface StoreInstance< Config extends AnyConfig > {\n\tgetSelectors: () => SelectorsOf< Config >;\n\tgetActions: () => ActionCreatorsOf< Config >;\n\tsubscribe: ( listener: () => void ) => () => void;\n}\n\nexport interface StoreDescriptor< Config extends AnyConfig = AnyConfig > {\n\t/**\n\t * Store Name\n\t */\n\tname: string;\n\n\t/**\n\t * Creates a store instance\n\t */\n\tinstantiate: ( registry: DataRegistry ) => StoreInstance< Config >;\n}\n\nexport interface ReduxStoreConfig< State, ActionCreators, Selectors > {\n\tinitialState?: State;\n\treducer: ( state: any, action: any ) => any;\n\tactions?: ActionCreators;\n\tresolvers?: MapOf< Resolver >;\n\tselectors?: Selectors;\n\tcontrols?: MapOf< Function >;\n}\n\n// Return type for the useSelect() hook.\nexport type UseSelectReturn< F extends MapSelect | StoreDescriptor< any > > =\n\tF extends MapSelect\n\t\t? ReturnType< F >\n\t\t: F extends StoreDescriptor< any >\n\t\t? CurriedSelectorsOf< F >\n\t\t: never;\n\n// Return type for the useDispatch() hook.\nexport type UseDispatchReturn< StoreNameOrDescriptor > =\n\tStoreNameOrDescriptor extends StoreDescriptor< any >\n\t\t? ActionCreatorsOf< StoreNameOrDescriptor >\n\t\t: StoreNameOrDescriptor extends undefined\n\t\t? DispatchFunction\n\t\t: any;\n\nexport type DispatchFunction = < StoreNameOrDescriptor >(\n\tstore: StoreNameOrDescriptor\n) => DispatchReturn< StoreNameOrDescriptor >;\n\nexport type DispatchReturn< StoreNameOrDescriptor > =\n\tStoreNameOrDescriptor extends StoreDescriptor< any >\n\t\t? ActionCreatorsOf< StoreNameOrDescriptor >\n\t\t: unknown;\n\nexport type MapSelect = (\n\tselect: SelectFunction,\n\tregistry: DataRegistry\n) => any;\n\nexport type SelectFunction = < S >( store: S ) => CurriedSelectorsOf< S >;\n\n/**\n * Callback for store's `subscribe()` method that\n * runs when the store data has changed.\n */\nexport type ListenerFunction = () => void;\n\nexport type CurriedSelectorsOf< S > = S extends StoreDescriptor<\n\tReduxStoreConfig< any, any, infer Selectors >\n>\n\t? {\n\t\t\t[ key in keyof Selectors ]: CurriedState< Selectors[ key ] >;\n\t } & MetadataSelectors< S >\n\t: never;\n\n/**\n * Like CurriedState but wraps the return type in a Promise.\n * Used for resolveSelect where selectors return promises.\n *\n * For generic selectors that define PromiseCurriedSignature, that signature\n * is used directly to preserve generic type parameters (which would otherwise\n * be lost when using `infer`).\n */\ntype CurriedStateWithPromise< F > =\n\tF extends SelectorWithCustomCurrySignature & {\n\t\tPromiseCurriedSignature: infer S;\n\t}\n\t\t? S\n\t\t: F extends SelectorWithCustomCurrySignature & {\n\t\t\t\tCurriedSignature: ( ...args: infer P ) => infer R;\n\t\t }\n\t\t? ( ...args: P ) => Promise< R >\n\t\t: F extends ( state: any, ...args: infer P ) => infer R\n\t\t? ( ...args: P ) => Promise< R >\n\t\t: F;\n\n/**\n * Like CurriedSelectorsOf but each selector returns a Promise.\n * Used for resolveSelect.\n */\nexport type CurriedSelectorsResolveOf< S > = S extends StoreDescriptor<\n\tReduxStoreConfig< any, any, infer Selectors >\n>\n\t? {\n\t\t\t[ key in keyof Selectors ]: CurriedStateWithPromise<\n\t\t\t\tSelectors[ key ]\n\t\t\t>;\n\t }\n\t: never;\n\n/**\n * Removes the first argument from a function.\n *\n * By default, it removes the `state` parameter from\n * registered selectors since that argument is supplied\n * by the editor when calling `select(\u2026)`.\n *\n * For functions with no arguments, which some selectors\n * are free to define, returns the original function.\n *\n * It is possible to manually provide a custom curried signature\n * and avoid the automatic inference. When the\n * F generic argument passed to this helper extends the\n * SelectorWithCustomCurrySignature type, the F['CurriedSignature']\n * property is used verbatim.\n *\n * This is useful because TypeScript does not correctly remove\n * arguments from complex function signatures constrained by\n * interdependent generic parameters.\n * For more context, see https://github.com/WordPress/gutenberg/pull/41578\n */\ntype CurriedState< F > = F extends SelectorWithCustomCurrySignature\n\t? F[ 'CurriedSignature' ]\n\t: F extends ( state: any, ...args: infer P ) => infer R\n\t? ( ...args: P ) => R\n\t: F;\n\n/**\n * Utility to manually specify curried selector signatures.\n *\n * It comes handy when TypeScript can't automatically produce the\n * correct curried function signature. For example:\n *\n * ```ts\n * type BadlyInferredSignature = CurriedState<\n * <K extends string | number>(\n * state: any,\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ) => K\n * >\n * // BadlyInferredSignature evaluates to:\n * // (kind: string number, key: false \"one value\") => string number\n * ```\n *\n * With SelectorWithCustomCurrySignature, we can provide a custom\n * signature and avoid relying on TypeScript inference:\n * ```ts\n * interface MySelectorSignature extends SelectorWithCustomCurrySignature {\n * <K extends string | number>(\n * state: any,\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ): K;\n *\n * CurriedSignature: <K extends string | number>(\n * kind: K,\n * key: K extends string ? 'one value' : false\n * ): K;\n * }\n * type CorrectlyInferredSignature = CurriedState<MySelectorSignature>\n * // <K extends string | number>(kind: K, key: K extends string ? 'one value' : false): K;\n *\n * For even more context, see https://github.com/WordPress/gutenberg/pull/41578\n * ```\n */\nexport interface SelectorWithCustomCurrySignature {\n\tCurriedSignature: Function;\n\tPromiseCurriedSignature?: Function;\n}\n\n/**\n * A store name or store descriptor, used throughout the API.\n */\nexport type StoreNameOrDescriptor = string | StoreDescriptor;\n\n/**\n * An isolated orchestrator of store registrations.\n *\n * Returned by `createRegistry`. Provides methods to register stores,\n * select data, dispatch actions, and subscribe to changes.\n */\nexport interface DataRegistry {\n\tbatch: ( callback: () => void ) => void;\n\tstores: Record< string, InternalStoreInstance >;\n\tnamespaces: Record< string, InternalStoreInstance >;\n\tsubscribe: (\n\t\tlistener: ListenerFunction,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t) => () => void;\n\tselect: {\n\t\t< S extends StoreDescriptor< any > >(\n\t\t\tstore: S\n\t\t): CurriedSelectorsOf< S >;\n\t\t(\n\t\t\tstore: StoreNameOrDescriptor\n\t\t): Record< string, ( ...args: any[] ) => any >;\n\t};\n\tresolveSelect: {\n\t\t< S extends StoreDescriptor< any > >(\n\t\t\tstore: S\n\t\t): CurriedSelectorsResolveOf< S >;\n\t\t(\n\t\t\tstore: StoreNameOrDescriptor\n\t\t): Record< string, ( ...args: any[] ) => Promise< any > >;\n\t};\n\tsuspendSelect: {\n\t\t< S extends StoreDescriptor< any > >(\n\t\t\tstore: S\n\t\t): CurriedSelectorsOf< S >;\n\t\t(\n\t\t\tstore: StoreNameOrDescriptor\n\t\t): Record< string, ( ...args: any[] ) => any >;\n\t};\n\tdispatch: {\n\t\t< S extends StoreDescriptor< any > >( store: S ): ActionCreatorsOf< S >;\n\t\t(\n\t\t\tstore: StoreNameOrDescriptor\n\t\t): Record< string, ( ...args: any[] ) => any >;\n\t};\n\tuse: (\n\t\tplugin: DataPlugin,\n\t\toptions?: Record< string, unknown >\n\t) => DataRegistry;\n\tregister: ( store: StoreDescriptor< any > ) => void;\n\tregisterGenericStore: (\n\t\tname: string,\n\t\tstore: StoreInstance< AnyConfig >\n\t) => void;\n\tregisterStore: (\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) => ReduxStore;\n\t__unstableMarkListeningStores: < T >(\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t) => T;\n}\n\n/**\n * The plugin function signature.\n */\nexport type DataPlugin = (\n\tregistry: DataRegistry,\n\toptions?: Record< string, unknown >\n) => Partial< DataRegistry >;\n\n/**\n * Status of a selector resolution.\n */\nexport type ResolutionStatus = 'resolving' | 'finished' | 'error';\n\n/**\n * State value for a single resolution.\n */\nexport type ResolutionState =\n\t| { status: 'resolving' }\n\t| { status: 'finished' }\n\t| { status: 'error'; error: Error | unknown };\n\n/**\n * A normalized resolver with a `fulfill` method and optional `isFulfilled`.\n */\nexport interface NormalizedResolver {\n\t/**\n\t * The function to call to fulfill the resolver.\n\t */\n\tfulfill: ( ...args: any[] ) => any;\n\t/**\n\t * Optional function to check if the resolver is already fulfilled.\n\t */\n\tisFulfilled?: ( state: any, ...args: any[] ) => boolean;\n\t/**\n\t * Optional function to check if the resolver should be invalidated.\n\t */\n\tshouldInvalidate?: ( action: any, ...args: any[] ) => boolean;\n}\n\n/**\n * A bound selector with optional resolver metadata.\n */\nexport interface BoundSelector {\n\t( ...args: any[] ): any;\n\t/**\n\t * Whether this selector has a resolver attached.\n\t */\n\thasResolver: boolean;\n\t/**\n\t * Optional function to normalize the arguments.\n\t */\n\t__unstableNormalizeArgs?: ( args: any[] ) => any[];\n\t/**\n\t * Whether this selector is a registry selector.\n\t */\n\tisRegistrySelector?: boolean;\n\t/**\n\t * The registry instance this selector is bound to.\n\t */\n\tregistry?: DataRegistry;\n}\n\n/**\n * The shape of a store instance as seen internally by the registry.\n * Extends the public StoreInstance with additional internal properties.\n */\nexport interface InternalStoreInstance< Config extends AnyConfig = AnyConfig >\n\textends StoreInstance< Config > {\n\t/**\n\t * The Redux store instance (only for Redux-based stores).\n\t */\n\tstore?: ReduxStore;\n\t/**\n\t * The internal emitter for pause/resume batching.\n\t */\n\temitter: DataEmitter;\n\t/**\n\t * The combined reducer.\n\t */\n\treducer?: ( state: any, action: any ) => any;\n\t/**\n\t * Bound actions object.\n\t */\n\tactions?: Record< string, ActionCreator >;\n\t/**\n\t * Bound selectors object.\n\t */\n\tselectors?: Record< string, Selector >;\n\t/**\n\t * Resolver definitions.\n\t */\n\tresolvers?: Record< string, NormalizedResolver >;\n\t/**\n\t * Returns resolve-wrapped selectors.\n\t */\n\tgetResolveSelectors?: () => Record<\n\t\tstring,\n\t\t( ...args: any[] ) => Promise< any >\n\t>;\n\t/**\n\t * Returns suspense-wrapped selectors.\n\t */\n\tgetSuspendSelectors?: () => Record< string, ( ...args: any[] ) => any >;\n}\n\n/**\n * Control descriptor for the controls system.\n */\nexport interface ControlDescriptor {\n\t/**\n\t * The type of the control action.\n\t */\n\ttype: string;\n\t/**\n\t * The store key to target.\n\t */\n\tstoreKey: string;\n\t/**\n\t * The name of the selector (for select/resolveSelect controls).\n\t */\n\tselectorName?: string;\n\t/**\n\t * The name of the action (for dispatch controls).\n\t */\n\tactionName?: string;\n\t/**\n\t * Arguments for the selector or action.\n\t */\n\targs: any[];\n}\n\n/**\n * Storage interface (Web Storage API subset).\n */\nexport interface StorageInterface {\n\tgetItem: ( key: string ) => string | null;\n\tsetItem: ( key: string, value: string ) => void;\n\tremoveItem?: ( key: string ) => void;\n\tclear?: VoidFunction;\n}\n\n// Type Helpers.\n\nexport type ConfigOf< S > = S extends StoreDescriptor< infer C > ? C : never;\n\nexport type ActionCreatorsOf< T > = T extends StoreDescriptor<\n\tReduxStoreConfig< any, infer ActionCreators, any >\n>\n\t? PromisifiedActionCreators< ActionCreators > & MetadataActions< T >\n\t: T extends ReduxStoreConfig< any, infer ActionCreators, any >\n\t? PromisifiedActionCreators< ActionCreators >\n\t: never;\n\n// Takes an object containing all action creators for a store and updates the\n// return type of each action creator to account for internal registry details --\n// for example, dispatched actions are wrapped with a Promise.\nexport type PromisifiedActionCreators< ActionCreators > = {\n\t[ Action in keyof ActionCreators ]: ActionCreators[ Action ] extends ActionCreator\n\t\t? PromisifyActionCreator< ActionCreators[ Action ] >\n\t\t: ActionCreators[ Action ];\n};\n\n// Wraps action creator return types with a Promise and handles thunks and generators.\nexport type PromisifyActionCreator< Action extends ActionCreator > = (\n\t...args: Parameters< Action >\n) => Promise<\n\tReturnType< Action > extends ( ..._args: any[] ) => any\n\t\t? ThunkReturnType< Action >\n\t\t: ReturnType< Action > extends Generator< any, infer TReturn, any >\n\t\t? TReturn\n\t\t: ReturnType< Action >\n>;\n\n// A thunk is an action creator which returns a function, which can optionally\n// return a Promise. The double ReturnType unwraps the innermost function's\n// return type, and Awaited gets the type the Promise resolves to. If the return\n// type is not a Promise, Awaited returns that original type.\nexport type ThunkReturnType< Action extends ActionCreator > = Awaited<\n\tReturnType< ReturnType< Action > >\n>;\n\ntype SelectorsOf< Config extends AnyConfig > = Config extends ReduxStoreConfig<\n\tany,\n\tany,\n\tinfer Selectors\n>\n\t? { [ name in keyof Selectors ]: Function }\n\t: never;\n\n/**\n * The argument object passed to every thunk function. When parameterized with\n * a store descriptor, `dispatch`, `select`, and `resolveSelect` are fully\n * typed against that store's actions and selectors.\n *\n * @example\n * ```ts\n * const myAction =\n * ( id: number ) =>\n * async ( { dispatch, select }: ThunkArgs< typeof myStore > ) => {\n * const record = select.getRecord( id );\n * dispatch.setLoading( true );\n * };\n * ```\n */\nexport interface ThunkArgs<\n\tS extends StoreDescriptor = StoreDescriptor,\n\tPrivateSelectors extends Record< string, Function > = {},\n\tPrivateActions extends Record< string, ActionCreator > = {},\n> {\n\tdispatch: ActionCreatorsOf< S > &\n\t\tPromisifiedActionCreators< PrivateActions > & {\n\t\t\t< R >( thunk: ( ...args: any[] ) => R ): R;\n\t\t\t( action: Record< string, unknown > ): unknown;\n\t\t};\n\tselect: CurriedSelectorsOf< S > & {\n\t\t[ key in keyof PrivateSelectors ]: CurriedState<\n\t\t\tPrivateSelectors[ key ]\n\t\t>;\n\t};\n\tresolveSelect: CurriedSelectorsResolveOf< S >;\n\tregistry: DataRegistry;\n}\n\nexport type combineReducers = typeof reduxCombineReducers;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/use-select/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\nimport type {\n\tMapSelect,\n\tSelectFunction,\n\tStoreDescriptor,\n\tAnyConfig,\n\tUseSelectReturn,\n\tDataRegistry,\n} from '../../types';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference(\n\ta: Record< string, unknown >,\n\tb: Record< string, unknown >\n): void {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\ninterface StoreSubscriber {\n\tsubscribe: ( listener: () => void ) => () => void;\n\tupdateStores: ( newStores: string[] ) => void;\n}\n\nfunction Store( registry: DataRegistry, suspense: boolean ) {\n\tconst select = ( suspense\n\t\t? registry.suspendSelect\n\t\t: registry.select ) as unknown as SelectFunction;\n\tconst queueContext = {};\n\tlet lastMapSelect: MapSelect | undefined;\n\tlet lastMapResult: unknown;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync: boolean | undefined;\n\tlet subscriber: StoreSubscriber | undefined;\n\tlet didWarnUnstableReference: boolean | undefined;\n\tconst storeStatesOnMount = new Map< string, unknown >();\n\n\tfunction getStoreState( name: string ): unknown {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores: string[] ): StoreSubscriber => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set< ( storeName: string ) => void >();\n\n\t\tfunction subscribe( listener: () => void ): () => void {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs: Array< VoidFunction > = [];\n\t\t\tfunction subscribeStore( storeName: string ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores: string[] ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect: MapSelect, isAsync: boolean ) => {\n\t\tfunction updateValue(): void {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null as string[] | null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( ( globalThis as any ).SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current! ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current! );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current! );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber!.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName: StoreDescriptor< AnyConfig > | string ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect(\n\tsuspense: boolean,\n\tmapSelect: MapSelect,\n\tdeps: unknown[]\n) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @param mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return The selected data or store selectors.\n */\nexport default function useSelect<\n\tT extends MapSelect | StoreDescriptor< AnyConfig >,\n>( mapSelect: T, deps?: unknown[] ): UseSelectReturn< T > {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\n\treturn (\n\t\tstaticSelectMode\n\t\t\t? _useStaticSelect( mapSelect as StoreDescriptor< AnyConfig > )\n\t\t\t: _useMappingSelect( false, mapSelect as MapSelect, deps! )\n\t) as UseSelectReturn< T >;\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @param mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect< T extends MapSelect >(\n\tmapSelect: T,\n\tdeps: unknown[]\n): ReturnType< T > {\n\treturn _useMappingSelect( true, mapSelect, deps ) as ReturnType< T >;\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["// useSelect is a low-level hook that intentionally breaks rules-of-hooks\n// in its internal helpers (_useStaticSelect, _useMappingSelect) where\n// hooks are called inside non-hook functions and conditionally dispatched.\n/* eslint-disable react-hooks/rules-of-hooks, react-compiler/react-compiler */\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\nimport type {\n\tMapSelect,\n\tSelectFunction,\n\tStoreDescriptor,\n\tAnyConfig,\n\tUseSelectReturn,\n\tDataRegistry,\n} from '../../types';\n\nconst renderQueue = createQueue();\n\nfunction warnOnUnstableReference(\n\ta: Record< string, unknown >,\n\tb: Record< string, unknown >\n): void {\n\tif ( ! a || ! b ) {\n\t\treturn;\n\t}\n\n\tconst keys =\n\t\ttypeof a === 'object' && typeof b === 'object'\n\t\t\t? Object.keys( a ).filter( ( k ) => a[ k ] !== b[ k ] )\n\t\t\t: [];\n\n\t// eslint-disable-next-line no-console\n\tconsole.warn(\n\t\t'The `useSelect` hook returns different values when called with the same state and parameters.\\n' +\n\t\t\t'This can lead to unnecessary re-renders and performance issues if not fixed.\\n\\n' +\n\t\t\t'Non-equal value keys: %s\\n\\n',\n\t\tkeys.join( ', ' )\n\t);\n}\n\ninterface StoreSubscriber {\n\tsubscribe: ( listener: () => void ) => () => void;\n\tupdateStores: ( newStores: string[] ) => void;\n}\n\nfunction Store( registry: DataRegistry, suspense: boolean ) {\n\tconst select = ( suspense\n\t\t? registry.suspendSelect\n\t\t: registry.select ) as unknown as SelectFunction;\n\tconst queueContext = {};\n\tlet lastMapSelect: MapSelect | undefined;\n\tlet lastMapResult: unknown;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync: boolean | undefined;\n\tlet subscriber: StoreSubscriber | undefined;\n\tlet didWarnUnstableReference: boolean | undefined;\n\tconst storeStatesOnMount = new Map< string, unknown >();\n\n\tfunction getStoreState( name: string ): unknown {\n\t\t// If there's no store property (custom generic store), return an empty\n\t\t// object. When comparing the state, the empty objects will cause the\n\t\t// equality check to fail, setting `lastMapResultValid` to false.\n\t\treturn registry.stores[ name ]?.store?.getState?.() ?? {};\n\t}\n\n\tconst createSubscriber = ( stores: string[] ): StoreSubscriber => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set< ( storeName: string ) => void >();\n\n\t\tfunction subscribe( listener: () => void ): () => void {\n\t\t\t// Maybe invalidate the value right after subscription was created.\n\t\t\t// React will call `getValue` after subscribing, to detect store\n\t\t\t// updates that happened in the interval between the `getValue` call\n\t\t\t// during render and creating the subscription, which is slightly\n\t\t\t// delayed. We need to ensure that this second `getValue` call will\n\t\t\t// compute a fresh value only if any of the store states have\n\t\t\t// changed in the meantime.\n\t\t\tif ( lastMapResultValid ) {\n\t\t\t\tfor ( const name of activeStores ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tstoreStatesOnMount.get( name ) !== getStoreState( name )\n\t\t\t\t\t) {\n\t\t\t\t\t\tlastMapResultValid = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tstoreStatesOnMount.clear();\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs: Array< VoidFunction > = [];\n\t\t\tfunction subscribeStore( storeName: string ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores: string[] ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect: MapSelect, isAsync: boolean ) => {\n\t\tfunction updateValue(): void {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null as string[] | null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( ( globalThis as any ).SCRIPT_DEBUG ) {\n\t\t\t\tif ( ! didWarnUnstableReference ) {\n\t\t\t\t\tconst secondMapResult = mapSelect( select, registry );\n\t\t\t\t\tif ( ! isShallowEqual( mapResult, secondMapResult ) ) {\n\t\t\t\t\t\twarnOnUnstableReference( mapResult, secondMapResult );\n\t\t\t\t\t\tdidWarnUnstableReference = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tfor ( const name of listeningStores.current! ) {\n\t\t\t\t\tstoreStatesOnMount.set( name, getStoreState( name ) );\n\t\t\t\t}\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current! );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current! );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber!.subscribe, getValue };\n\t};\n}\n\nfunction _useStaticSelect( storeName: StoreDescriptor< AnyConfig > | string ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction _useMappingSelect(\n\tsuspense: boolean,\n\tmapSelect: MapSelect,\n\tdeps: unknown[]\n) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo(\n\t\t() => Store( registry, suspense ),\n\t\t[ registry, suspense ]\n\t);\n\n\t// These are \"pass-through\" dependencies from the parent hook,\n\t// and the parent should catch any hook rule violations.\n\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).\n *\n * @param mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return The selected data or store selectors.\n */\nexport default function useSelect<\n\tT extends MapSelect | StoreDescriptor< AnyConfig >,\n>( mapSelect: T, deps?: unknown[] ): UseSelectReturn< T > {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\n\treturn (\n\t\tstaticSelectMode\n\t\t\t? _useStaticSelect( mapSelect as StoreDescriptor< AnyConfig > )\n\t\t\t: _useMappingSelect( false, mapSelect as MapSelect, deps! )\n\t) as UseSelectReturn< T >;\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but is a compatible\n * Suspense-enabled data source.\n *\n * @param mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @throws A suspense Promise that is thrown if any of the called\n * selectors is in an unresolved state.\n *\n * @return Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect< T extends MapSelect >(\n\tmapSelect: T,\n\tdeps: unknown[]\n): ReturnType< T > {\n\treturn _useMappingSelect( true, mapSelect, deps ) as ReturnType< T >;\n}\n/* eslint-enable react-hooks/rules-of-hooks, react-compiler/react-compiler */\n"],
|
|
5
|
+
"mappings": ";AAQA,SAAS,mBAAmB;AAC5B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,E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
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/use-select/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/use-select/index.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EACX,SAAS,EAET,eAAe,EACf,SAAS,EACT,eAAe,EAEf,MAAM,aAAa,CAAC;AAsOrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAChC,CAAC,SAAS,SAAS,GAAG,eAAe,CAAE,SAAS,CAAE,EAChD,SAAS,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO,EAAE,GAAI,eAAe,CAAE,CAAC,CAAE,CAsBxD;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,iBAAiB,CAAE,CAAC,SAAS,SAAS,EACrD,SAAS,EAAE,CAAC,EACZ,IAAI,EAAE,OAAO,EAAE,GACb,UAAU,CAAE,CAAC,CAAE,CAEjB"}
|
package/build-types/types.d.ts
CHANGED
|
@@ -330,9 +330,14 @@ type SelectorsOf<Config extends AnyConfig> = Config extends ReduxStoreConfig<any
|
|
|
330
330
|
* };
|
|
331
331
|
* ```
|
|
332
332
|
*/
|
|
333
|
-
export interface ThunkArgs<S extends StoreDescriptor = StoreDescriptor> {
|
|
334
|
-
dispatch: ActionCreatorsOf<S> &
|
|
335
|
-
|
|
333
|
+
export interface ThunkArgs<S extends StoreDescriptor = StoreDescriptor, PrivateSelectors extends Record<string, Function> = {}, PrivateActions extends Record<string, ActionCreator> = {}> {
|
|
334
|
+
dispatch: ActionCreatorsOf<S> & PromisifiedActionCreators<PrivateActions> & {
|
|
335
|
+
<R>(thunk: (...args: any[]) => R): R;
|
|
336
|
+
(action: Record<string, unknown>): unknown;
|
|
337
|
+
};
|
|
338
|
+
select: CurriedSelectorsOf<S> & {
|
|
339
|
+
[key in keyof PrivateSelectors]: CurriedState<PrivateSelectors[key]>;
|
|
340
|
+
};
|
|
336
341
|
resolveSelect: CurriedSelectorsResolveOf<S>;
|
|
337
342
|
registry: DataRegistry;
|
|
338
343
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAEX,eAAe,IAAI,oBAAoB,EACvC,KAAK,IAAI,UAAU,EACnB,MAAM,OAAO,CAAC;AAEf;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EACX,iBAAiB,EACjB,eAAe,EACf,MAAM,8BAA8B,CAAC;AAEtC,KAAK,KAAK,CAAE,CAAC,IAAK;IAAE,CAAE,IAAI,EAAE,MAAM,GAAI,CAAC,CAAA;CAAE,CAAC;AAE1C,MAAM,MAAM,aAAa,GAAG,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAM,GAAG,GAAG,SAAS,CAAC;AAClE,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC5C,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAEhC,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAE,CAAC;AAE1D,MAAM,WAAW,aAAa,CAAE,MAAM,SAAS,SAAS;IACvD,YAAY,EAAE,MAAM,WAAW,CAAE,MAAM,CAAE,CAAC;IAC1C,UAAU,EAAE,MAAM,gBAAgB,CAAE,MAAM,CAAE,CAAC;IAC7C,SAAS,EAAE,CAAE,QAAQ,EAAE,MAAM,IAAI,KAAM,MAAM,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,eAAe,CAAE,MAAM,SAAS,SAAS,GAAG,SAAS;IACrE;;OAE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"Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"types": "build-types",
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@wordpress/compose": "^7.
|
|
49
|
-
"@wordpress/deprecated": "^4.
|
|
50
|
-
"@wordpress/element": "^6.44.
|
|
51
|
-
"@wordpress/is-shallow-equal": "^5.
|
|
52
|
-
"@wordpress/priority-queue": "^3.
|
|
53
|
-
"@wordpress/private-apis": "^1.
|
|
54
|
-
"@wordpress/redux-routine": "^5.
|
|
48
|
+
"@wordpress/compose": "^7.44.0",
|
|
49
|
+
"@wordpress/deprecated": "^4.44.0",
|
|
50
|
+
"@wordpress/element": "^6.44.0",
|
|
51
|
+
"@wordpress/is-shallow-equal": "^5.44.0",
|
|
52
|
+
"@wordpress/priority-queue": "^3.44.0",
|
|
53
|
+
"@wordpress/private-apis": "^1.44.0",
|
|
54
|
+
"@wordpress/redux-routine": "^5.44.0",
|
|
55
55
|
"deepmerge": "^4.3.0",
|
|
56
56
|
"equivalent-key-map": "^0.2.2",
|
|
57
57
|
"is-plain-object": "^5.0.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "b862d8c84121a47bbeff882f6c87e61681ce2e0d"
|
|
73
73
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// useSelect is a low-level hook that intentionally breaks rules-of-hooks
|
|
2
|
+
// in its internal helpers (_useStaticSelect, _useMappingSelect) where
|
|
3
|
+
// hooks are called inside non-hook functions and conditionally dispatched.
|
|
4
|
+
/* eslint-disable react-hooks/rules-of-hooks, react-compiler/react-compiler */
|
|
5
|
+
|
|
1
6
|
/**
|
|
2
7
|
* WordPress dependencies
|
|
3
8
|
*/
|
|
@@ -367,3 +372,4 @@ export function useSuspenseSelect< T extends MapSelect >(
|
|
|
367
372
|
): ReturnType< T > {
|
|
368
373
|
return _useMappingSelect( true, mapSelect, deps ) as ReturnType< T >;
|
|
369
374
|
}
|
|
375
|
+
/* eslint-enable react-hooks/rules-of-hooks, react-compiler/react-compiler */
|
|
@@ -705,7 +705,12 @@ describe( 'useSelect', () => {
|
|
|
705
705
|
'count2:0'
|
|
706
706
|
);
|
|
707
707
|
|
|
708
|
-
act( () =>
|
|
708
|
+
act( () =>
|
|
709
|
+
screen
|
|
710
|
+
.getByText( 'Open' )
|
|
711
|
+
// eslint-disable-next-line testing-library/no-node-access
|
|
712
|
+
.click()
|
|
713
|
+
);
|
|
709
714
|
|
|
710
715
|
expect( selectCount1 ).toHaveBeenCalledTimes( 1 );
|
|
711
716
|
expect( selectCount2 ).toHaveBeenCalledTimes( 1 );
|
package/src/types.ts
CHANGED
|
@@ -476,10 +476,21 @@ type SelectorsOf< Config extends AnyConfig > = Config extends ReduxStoreConfig<
|
|
|
476
476
|
* };
|
|
477
477
|
* ```
|
|
478
478
|
*/
|
|
479
|
-
export interface ThunkArgs<
|
|
479
|
+
export interface ThunkArgs<
|
|
480
|
+
S extends StoreDescriptor = StoreDescriptor,
|
|
481
|
+
PrivateSelectors extends Record< string, Function > = {},
|
|
482
|
+
PrivateActions extends Record< string, ActionCreator > = {},
|
|
483
|
+
> {
|
|
480
484
|
dispatch: ActionCreatorsOf< S > &
|
|
481
|
-
|
|
482
|
-
|
|
485
|
+
PromisifiedActionCreators< PrivateActions > & {
|
|
486
|
+
< R >( thunk: ( ...args: any[] ) => R ): R;
|
|
487
|
+
( action: Record< string, unknown > ): unknown;
|
|
488
|
+
};
|
|
489
|
+
select: CurriedSelectorsOf< S > & {
|
|
490
|
+
[ key in keyof PrivateSelectors ]: CurriedState<
|
|
491
|
+
PrivateSelectors[ key ]
|
|
492
|
+
>;
|
|
493
|
+
};
|
|
483
494
|
resolveSelect: CurriedSelectorsResolveOf< S >;
|
|
484
495
|
registry: DataRegistry;
|
|
485
496
|
}
|