@wordpress/data 10.43.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/plugins/persistence/index.cjs +1 -1
- package/build/plugins/persistence/index.cjs.map +2 -2
- package/build/plugins/persistence/storage/default.cjs +1 -1
- package/build/plugins/persistence/storage/default.cjs.map +2 -2
- package/build/registry.cjs +3 -3
- package/build/registry.cjs.map +2 -2
- package/build/types.cjs.map +1 -1
- package/build-module/components/use-select/index.mjs.map +2 -2
- package/build-module/plugins/persistence/index.mjs +1 -1
- package/build-module/plugins/persistence/index.mjs.map +2 -2
- package/build-module/plugins/persistence/storage/default.mjs +1 -1
- package/build-module/plugins/persistence/storage/default.mjs.map +2 -2
- package/build-module/registry.mjs +3 -3
- package/build-module/registry.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/plugins/persistence/index.ts +1 -1
- package/src/plugins/persistence/storage/default.ts +1 -1
- package/src/redux-store/metadata/test/selectors.js +1 -1
- package/src/registry.ts +3 -3
- 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,MAAM,YAAY,OAAO,MAAM,WACnC,OAAO,KAAM,CAAE,EAAE,OAAQ,CAAE,MAAO,EAAG,CAAE,MAAM,EAAG,CAAE,CAAE,IACpD,CAAC;AAGL,UAAQ;AAAA,IACP;AAAA,IAGA,KAAK,KAAM,IAAK;AAAA,EACjB;AACD;AAOA,SAAS,MAAO,UAAwB,UAAoB;AAC3D,QAAM,SAAW,WACd,SAAS,gBACT,SAAS;AACZ,QAAM,eAAe,CAAC;AACtB,MAAI;AACJ,MAAI;AACJ,MAAI,qBAAqB;AACzB,MAAI;AACJ,MAAI;AACJ,MAAI;AACJ,QAAM,qBAAqB,oBAAI,IAAuB;AAEtD,WAAS,cAAe,MAAwB;AAI/C,WAAO,SAAS,OAAQ,IAAK,GAAG,OAAO,WAAW,KAAK,CAAC;AAAA,EACzD;AAEA,QAAM,mBAAmB,CAAE,WAAuC;AAGjE,UAAM,eAAe,CAAE,GAAG,MAAO;AAKjC,UAAM,sBAAsB,oBAAI,IAAqC;AAErE,aAAS,UAAW,UAAmC;AAQtD,UAAK,oBAAqB;AACzB,mBAAY,QAAQ,cAAe;AAClC,cACC,mBAAmB,IAAK,IAAK,MAAM,cAAe,IAAK,GACtD;AACD,iCAAqB;AAAA,UACtB;AAAA,QACD;A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AAC1D,UAAM,WAAW,mBAAmB,WAAW;AAC/C,UAAM,IAAI;AAAA,MACT,4BAA6B,QAAS,OAAQ,QAAS;AAAA,IACxD;AAAA,EACD;AAKA,SACC,mBACG,iBAAkB,SAA0C,IAC5D,kBAAmB,OAAO,WAAwB,IAAM;AAE7D;AAoBO,SAAS,kBACf,WACA,MACkB;AAClB,SAAO,kBAAmB,MAAM,WAAW,IAAK;AACjD;",
|
|
6
6
|
"names": ["useRegistry", "useAsyncMode"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/plugins/persistence/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,6BAA8B;AAC9B,uBAAsB;AAKtB,qBAA2B;AAC3B,eAAgC;AA4BhC,IAAM,kBAAkB,eAAAA;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACuB;AACvB,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAqC;AAC7C,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data!;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param key Key to update.\n\t * @param value Updated value.\n\t */\n\tfunction setData( key: string, value: unknown ): void {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param registry Data registry.\n * @param pluginOptions Plugin options.\n *\n * @return Data plugin.\n */\nfunction persistencePlugin(\n\tregistry: DataRegistry,\n\tpluginOptions: PersistencePluginOptions\n): Partial< DataRegistry > {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param getState Function which returns current state.\n\t * @param storeName Store name.\n\t * @param keys Optional subset of keys to save.\n\t *\n\t * @return Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange(\n\t\tgetState: () => unknown,\n\t\tstoreName: string,\n\t\tkeys: boolean | string[]\n\t): () => void {\n\t\tlet getPersistedState: ( state: any, action: any ) => any;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t(\n\t\t\t\t\taccumulator: Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t( state: any, action: any ) => any\n\t\t\t\t\t>,\n\t\t\t\t\tkey: string\n\t\t\t\t) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: (\n\t\t\t\t\t\t\tstate: unknown,\n\t\t\t\t\t\t\taction: { nextState: Record< string, unknown > }\n\t\t\t\t\t\t) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = (\n\t\t\t\t_state: unknown,\n\t\t\t\taction: { nextState: unknown }\n\t\t\t) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore(\n\t\t\tstoreName: string,\n\t\t\toptions: ReduxStoreConfig< any, any, any > & {\n\t\t\t\tpersist?: boolean | string[];\n\t\t\t}\n\t\t) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = deepmerge(\n\t\t\t\t\t\tinitialState as Record< string, unknown >,\n\t\t\t\t\t\tpersistedState as Record< string, unknown >,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tisMergeableObject: isPlainObject,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist!\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\nexport default Object.assign( persistencePlugin, {\n\t__unstableMigrate: () => {},\n} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,6BAA8B;AAC9B,uBAAsB;AAKtB,qBAA2B;AAC3B,eAAgC;AA4BhC,IAAM,kBAAkB,eAAAA;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACu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oBAAY;AAAA,MACb;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AAAA,IACN,cACC,WACA,SAGC;AACD,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO,SAAS,cAAe,WAAW,OAAQ;AAAA,MACnD;AAGA,YAAM,iBAAiB,YAAY,IAAI,EAAG,SAAU;AACpD,UAAK,mBAAmB,QAAY;AACnC,YAAI,eAAe,QAAQ,QAAS,QAAQ,cAAc;AAAA,UACzD,MAAM;AAAA,QACP,CAAE;AAEF,gBACC,sCAAe,YAAa,SAC5B,sCAAe,cAAe,GAC7B;AAMD,6BAAe,iBAAAC;AAAA,YACd;AAAA,YACA;AAAA,YACA;AAAA,cACC,mBAAmB;AAAA,YACpB;AAAA,UACD;AAAA,QACD,OAAO;AAGN,yBAAe;AAAA,QAChB;AAEA,kBAAU;AAAA,UACT,GAAG;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAEA,YAAM,QAAQ,SAAS,cAAe,WAAW,OAAQ;AAEzD,YAAM;AAAA,QACL;AAAA,UACC,MAAM;AAAA,UACN;AAAA,UACA,QAAQ;AAAA,QACT;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEA,IAAO,sBAAQ,OAAO,OAAQ,mBAAmB;AAAA,EAChD,mBAAmB,MAAM;AAAA,EAAC;AAC3B,CAAE;",
|
|
6
6
|
"names": ["defaultStorage", "deepmerge"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/persistence/storage/default.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA0B;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA0B;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,QAAQ;AACP,YAAU,cAAAA;AACX;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": ["objectStorage"]
|
|
7
7
|
}
|
package/build/registry.cjs
CHANGED
|
@@ -162,7 +162,7 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
162
162
|
(0, import_lock_unlock.unlock)(store.store).registerPrivateSelectors(
|
|
163
163
|
(0, import_lock_unlock.unlock)(parent).privateSelectorsOf(name)
|
|
164
164
|
);
|
|
165
|
-
} catch
|
|
165
|
+
} catch {
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
return store;
|
|
@@ -248,14 +248,14 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
248
248
|
privateActionsOf: (name) => {
|
|
249
249
|
try {
|
|
250
250
|
return (0, import_lock_unlock.unlock)(stores[name].store).privateActions;
|
|
251
|
-
} catch
|
|
251
|
+
} catch {
|
|
252
252
|
return {};
|
|
253
253
|
}
|
|
254
254
|
},
|
|
255
255
|
privateSelectorsOf: (name) => {
|
|
256
256
|
try {
|
|
257
257
|
return (0, import_lock_unlock.unlock)(stores[name].store).privateSelectors;
|
|
258
|
-
} catch
|
|
258
|
+
} catch {
|
|
259
259
|
return {};
|
|
260
260
|
}
|
|
261
261
|
}
|
package/build/registry.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/registry.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\nimport { lock, unlock } from './lock-unlock';\nimport type {\n\tStoreDescriptor,\n\tStoreNameOrDescriptor,\n\tDataRegistry,\n\tDataPlugin,\n\tInternalStoreInstance,\n\tAnyConfig,\n\tReduxStoreConfig,\n} from './types';\n\nfunction getStoreName( storeNameOrDescriptor: StoreNameOrDescriptor ): string {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param storeConfigs Initial store configurations.\n * @param parent Parent registry.\n *\n * @return Data registry.\n */\nexport function createRegistry(\n\tstoreConfigs: Record< string, ReduxStoreConfig< any, any, any > > = {},\n\tparent: DataRegistry | null = null\n): DataRegistry {\n\tconst stores: Record< string, InternalStoreInstance > = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores: Set< string > | null = null;\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param listener Listener function.\n\t * @param storeNameOrDescriptor Optional store name.\n\t *\n\t * @return Unsubscribe function.\n\t */\n\tconst subscribe = (\n\t\tlistener: () => void,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t): ( () => void ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to global `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores< T >(\n\t\tthis: DataRegistry,\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t): T {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors!();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors!();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins(\n\t\tattributes: Record< string, unknown >\n\t): Record< string, unknown > {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\t\treturn ( registry as any )[ key ]( ...args );\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} )\n\t\t);\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param name Store registry name.\n\t * @param createStoreFunc Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance(\n\t\tname: string,\n\t\tcreateStoreFunc: () => InternalStoreInstance\n\t): InternalStoreInstance {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store: any = createStoreFunc();\n\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener: () => void ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param store Store descriptor.\n\t */\n\tfunction register( store: StoreDescriptor< AnyConfig > ) {\n\t\tregisterStoreInstance(\n\t\t\tstore.name,\n\t\t\t() => store.instantiate( registry ) as InternalStoreInstance\n\t\t);\n\t}\n\n\tfunction registerGenericStore(\n\t\tname: string,\n\t\tstore: InternalStoreInstance\n\t) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, () => store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param storeName Unique namespace identifier.\n\t * @param options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return Registered store object.\n\t */\n\tfunction registerStore(\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance(\n\t\t\tstoreName,\n\t\t\t() =>\n\t\t\t\tcreateReduxStore( storeName, options ).instantiate(\n\t\t\t\t\tregistry\n\t\t\t\t) as InternalStoreInstance\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback: () => void ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\n\t}\n\n\tlet registry: DataRegistry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t} as DataRegistry;\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin: DataPlugin, options?: Record< string, unknown > ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\tconst registryWithPlugins = withPlugins(\n\t\tregistry as unknown as Record< string, unknown >\n\t);\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws an error the store was not locked \u2013 this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins as unknown as DataRegistry;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AAKvB,yBAA6B;AAC7B,mBAA0B;AAC1B,qBAA8B;AAC9B,yBAA6B;AAW7B,SAAS,aAAc,uBAAuD;AAC7E,SAAO,OAAO,0BAA0B,WACrC,wBACA,sBAAsB;AAC1B;AAWO,SAAS,eACf,eAAoE,CAAC,GACrE,SAA8B,MACf;AACf,QAAM,SAAkD,CAAC;AACzD,QAAM,cAAU,8BAAc;AAC9B,MAAI,kBAAwC;AAK5C,WAAS,iBAAiB;AACzB,YAAQ,KAAK;AAAA,EACd;AAWA,QAAM,YAAY,CACjB,UACA,0BACoB;AAEpB,QAAK,CAAE,uBAAwB;AAC9B,aAAO,QAAQ,UAAW,QAAS;AAAA,IACpC;AAGA,UAAM,YAAY,aAAc,qBAAsB;AACtD,UAAM,QAAQ,OAAQ,SAAU;AAChC,QAAK,OAAQ;AACZ,aAAO,MAAM,UAAW,QAAS;AAAA,IAClC;AAMA,QAAK,CAAE,QAAS;AACf,aAAO,QAAQ,UAAW,QAAS;AAAA,IACpC;AAEA,WAAO,OAAO,UAAW,UAAU,qBAAsB;AAAA,EAC1D;AAUA,WAAS,OAAQ,uBAA+C;AAC/D,UAAM,YAAY,aAAc,qBAAsB;AACtD,qBAAiB,IAAK,SAAU;AAChC,UAAM,QAAQ,OAAQ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C5C;AAAA,QACD;AAAA,MACD,CAAE;AAAA,IACH;AAAA,EACD;AAQA,WAAS,sBACR,MACA,iBACwB;AACxB,QAAK,OAAQ,IAAK,GAAI;AAErB,cAAQ,MAAO,YAAY,OAAO,0BAA2B;AAC7D,aAAO,OAAQ,IAAK;AAAA,IACrB;AAEA,UAAM,QAAa,gBAAgB;AAEnC,QAAK,OAAO,MAAM,iBAAiB,YAAa;AAC/C,YAAM,IAAI,UAAW,uCAAwC;AAAA,IAC9D;AACA,QAAK,OAAO,MAAM,eAAe,YAAa;AAC7C,YAAM,IAAI,UAAW,qCAAsC;AAAA,IAC5D;AACA,QAAK,OAAO,MAAM,cAAc,YAAa;AAC5C,YAAM,IAAI,UAAW,oCAAqC;AAAA,IAC3D;AAIA,UAAM,cAAU,8BAAc;AAC9B,UAAM,mBAAmB,MAAM;AAC/B,UAAM,YAAY,CAAE,aAA0B;AAC7C,YAAM,yBAAyB,MAAM,QAAQ,UAAW,QAAS;AACjE,YAAM,uBAAuB,iBAAkB,MAAM;AACpD,YAAK,MAAM,QAAQ,UAAW;AAC7B,gBAAM,QAAQ,KAAK;AACnB;AAAA,QACD;AACA,iBAAS;AAAA,MACV,CAAE;AAEF,aAAO,MAAM;AACZ,+BAAuB;AACvB,iCAAyB;AAAA,MAC1B;AAAA,IACD;AACA,WAAQ,IAAK,IAAI;AACjB,UAAM,UAAW,cAAe;AAGhC,QAAK,QAAS;AACb,UAAI;AACH,uCAAQ,MAAM,KAAM,EAAE;AAAA,cACrB,2BAAQ,MAAO,EAAE,iBAAkB,IAAK;AAAA,QACzC;AACA,uCAAQ,MAAM,KAAM,EAAE;AAAA,cACrB,2BAAQ,MAAO,EAAE,mBAAoB,IAAK;AAAA,QAC3C;AAAA,MACD,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\nimport { lock, unlock } from './lock-unlock';\nimport type {\n\tStoreDescriptor,\n\tStoreNameOrDescriptor,\n\tDataRegistry,\n\tDataPlugin,\n\tInternalStoreInstance,\n\tAnyConfig,\n\tReduxStoreConfig,\n} from './types';\n\nfunction getStoreName( storeNameOrDescriptor: StoreNameOrDescriptor ): string {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param storeConfigs Initial store configurations.\n * @param parent Parent registry.\n *\n * @return Data registry.\n */\nexport function createRegistry(\n\tstoreConfigs: Record< string, ReduxStoreConfig< any, any, any > > = {},\n\tparent: DataRegistry | null = null\n): DataRegistry {\n\tconst stores: Record< string, InternalStoreInstance > = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores: Set< string > | null = null;\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param listener Listener function.\n\t * @param storeNameOrDescriptor Optional store name.\n\t *\n\t * @return Unsubscribe function.\n\t */\n\tconst subscribe = (\n\t\tlistener: () => void,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t): ( () => void ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to global `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores< T >(\n\t\tthis: DataRegistry,\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t): T {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors!();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors!();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins(\n\t\tattributes: Record< string, unknown >\n\t): Record< string, unknown > {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\t\treturn ( registry as any )[ key ]( ...args );\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} )\n\t\t);\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param name Store registry name.\n\t * @param createStoreFunc Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance(\n\t\tname: string,\n\t\tcreateStoreFunc: () => InternalStoreInstance\n\t): InternalStoreInstance {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store: any = createStoreFunc();\n\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener: () => void ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param store Store descriptor.\n\t */\n\tfunction register( store: StoreDescriptor< AnyConfig > ) {\n\t\tregisterStoreInstance(\n\t\t\tstore.name,\n\t\t\t() => store.instantiate( registry ) as InternalStoreInstance\n\t\t);\n\t}\n\n\tfunction registerGenericStore(\n\t\tname: string,\n\t\tstore: InternalStoreInstance\n\t) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, () => store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param storeName Unique namespace identifier.\n\t * @param options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return Registered store object.\n\t */\n\tfunction registerStore(\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance(\n\t\t\tstoreName,\n\t\t\t() =>\n\t\t\t\tcreateReduxStore( storeName, options ).instantiate(\n\t\t\t\t\tregistry\n\t\t\t\t) as InternalStoreInstance\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback: () => void ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\n\t}\n\n\tlet registry: DataRegistry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t} as DataRegistry;\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin: DataPlugin, options?: Record< string, unknown > ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\tconst registryWithPlugins = withPlugins(\n\t\tregistry as unknown as Record< string, unknown >\n\t);\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch {\n\t\t\t\t// unlock() throws an error the store was not locked \u2013 this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins as unknown as DataRegistry;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AAKvB,yBAA6B;AAC7B,mBAA0B;AAC1B,qBAA8B;AAC9B,yBAA6B;AAW7B,SAAS,aAAc,uBAAuD;AAC7E,SAAO,OAAO,0BAA0B,WACrC,wBACA,sBAAsB;AAC1B;AAWO,SAAS,eACf,eAAoE,CAAC,GACrE,SAA8B,MACf;AACf,QAAM,SAAkD,CAAC;AACzD,QAAM,cAAU,8BA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,MAAM,QAAQ,OAAO;AAAA,MACtB;AAAA,IACD;AAAA,EACD;AAEA,MAAI,WAAyB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,YAAY;AAAA;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAKA,WAAS,IAAK,QAAoB,SAAsC;AACvE,QAAK,CAAE,QAAS;AACf;AAAA,IACD;AAEA,eAAW;AAAA,MACV,GAAG;AAAA,MACH,GAAG,OAAQ,UAAU,OAAQ;AAAA,IAC9B;AAEA,WAAO;AAAA,EACR;AAEA,WAAS,SAAU,aAAAC,OAAc;AAEjC,aAAY,CAAE,MAAM,MAAO,KAAK,OAAO,QAAS,YAAa,GAAI;AAChE,aAAS,aAAU,mBAAAD,SAAkB,MAAM,MAAO,CAAE;AAAA,EACrD;AAEA,MAAK,QAAS;AACb,WAAO,UAAW,cAAe;AAAA,EAClC;AAEA,QAAM,sBAAsB;AAAA,IAC3B;AAAA,EACD;AACA,+BAAM,qBAAqB;AAAA,IAC1B,kBAAkB,CAAE,SAAkB;AACrC,UAAI;AACH,mBAAO,2BAAQ,OAAQ,IAAK,EAAE,KAAM,EAAE;AAAA,MACvC,QAAQ;AAGP,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,IACA,oBAAoB,CAAE,SAAkB;AACvC,UAAI;AACH,mBAAO,2BAAQ,OAAQ,IAAK,EAAE,KAAM,EAAE;AAAA,MACvC,QAAQ;AACP,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
|
|
6
6
|
"names": ["deprecated", "createReduxStore", "coreDataStore"]
|
|
7
7
|
}
|
package/build/types.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.ts"],
|
|
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< 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,EAC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"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/plugins/persistence/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch
|
|
5
|
-
"mappings": ";AAIA,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AAKtB,OAAO,oBAAoB;AAC3B,SAAS,uBAAuB;AA4BhC,IAAM,kBAAkB;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACuB;AACvB,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAqC;AAC7C,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data!;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param key Key to update.\n\t * @param value Updated value.\n\t */\n\tfunction setData( key: string, value: unknown ): void {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param registry Data registry.\n * @param pluginOptions Plugin options.\n *\n * @return Data plugin.\n */\nfunction persistencePlugin(\n\tregistry: DataRegistry,\n\tpluginOptions: PersistencePluginOptions\n): Partial< DataRegistry > {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param getState Function which returns current state.\n\t * @param storeName Store name.\n\t * @param keys Optional subset of keys to save.\n\t *\n\t * @return Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange(\n\t\tgetState: () => unknown,\n\t\tstoreName: string,\n\t\tkeys: boolean | string[]\n\t): () => void {\n\t\tlet getPersistedState: ( state: any, action: any ) => any;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t(\n\t\t\t\t\taccumulator: Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t( state: any, action: any ) => any\n\t\t\t\t\t>,\n\t\t\t\t\tkey: string\n\t\t\t\t) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: (\n\t\t\t\t\t\t\tstate: unknown,\n\t\t\t\t\t\t\taction: { nextState: Record< string, unknown > }\n\t\t\t\t\t\t) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = (\n\t\t\t\t_state: unknown,\n\t\t\t\taction: { nextState: unknown }\n\t\t\t) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore(\n\t\t\tstoreName: string,\n\t\t\toptions: ReduxStoreConfig< any, any, any > & {\n\t\t\t\tpersist?: boolean | string[];\n\t\t\t}\n\t\t) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = deepmerge(\n\t\t\t\t\t\tinitialState as Record< string, unknown >,\n\t\t\t\t\t\tpersistedState as Record< string, unknown >,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tisMergeableObject: isPlainObject,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist!\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\nexport default Object.assign( persistencePlugin, {\n\t__unstableMigrate: () => {},\n} );\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AAKtB,OAAO,oBAAoB;AAC3B,SAAS,uBAAuB;AA4BhC,IAAM,kBAAkB;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACuB;AACvB,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAqC;AAC7C,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,QAAQ;AAGP,iBAAO,CAAC;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAQA,WAAS,QAAS,KAAa,OAAuB;AACrD,WAAO,EAAE,GAAG,MAAM,CAAE,GAAI,G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;AAAA,YACpB;AAAA,UACD;AAAA,QACD,OAAO;AAGN,yBAAe;AAAA,QAChB;AAEA,kBAAU;AAAA,UACT,GAAG;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAEA,YAAM,QAAQ,SAAS,cAAe,WAAW,OAAQ;AAEzD,YAAM;AAAA,QACL;AAAA,UACC,MAAM;AAAA,UACN;AAAA,UACA,QAAQ;AAAA,QACT;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEA,IAAO,sBAAQ,OAAO,OAAQ,mBAAmB;AAAA,EAChD,mBAAmB,MAAM;AAAA,EAAC;AAC3B,CAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/persistence/storage/default.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch
|
|
5
|
-
"mappings": ";AAIA,OAAO,mBAAmB;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO,mBAAmB;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,QAAQ;AACP,YAAU;AACX;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -128,7 +128,7 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
128
128
|
unlock(store.store).registerPrivateSelectors(
|
|
129
129
|
unlock(parent).privateSelectorsOf(name)
|
|
130
130
|
);
|
|
131
|
-
} catch
|
|
131
|
+
} catch {
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
return store;
|
|
@@ -214,14 +214,14 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
214
214
|
privateActionsOf: (name) => {
|
|
215
215
|
try {
|
|
216
216
|
return unlock(stores[name].store).privateActions;
|
|
217
|
-
} catch
|
|
217
|
+
} catch {
|
|
218
218
|
return {};
|
|
219
219
|
}
|
|
220
220
|
},
|
|
221
221
|
privateSelectorsOf: (name) => {
|
|
222
222
|
try {
|
|
223
223
|
return unlock(stores[name].store).privateSelectors;
|
|
224
|
-
} catch
|
|
224
|
+
} catch {
|
|
225
225
|
return {};
|
|
226
226
|
}
|
|
227
227
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/registry.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\nimport { lock, unlock } from './lock-unlock';\nimport type {\n\tStoreDescriptor,\n\tStoreNameOrDescriptor,\n\tDataRegistry,\n\tDataPlugin,\n\tInternalStoreInstance,\n\tAnyConfig,\n\tReduxStoreConfig,\n} from './types';\n\nfunction getStoreName( storeNameOrDescriptor: StoreNameOrDescriptor ): string {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param storeConfigs Initial store configurations.\n * @param parent Parent registry.\n *\n * @return Data registry.\n */\nexport function createRegistry(\n\tstoreConfigs: Record< string, ReduxStoreConfig< any, any, any > > = {},\n\tparent: DataRegistry | null = null\n): DataRegistry {\n\tconst stores: Record< string, InternalStoreInstance > = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores: Set< string > | null = null;\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param listener Listener function.\n\t * @param storeNameOrDescriptor Optional store name.\n\t *\n\t * @return Unsubscribe function.\n\t */\n\tconst subscribe = (\n\t\tlistener: () => void,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t): ( () => void ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to global `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores< T >(\n\t\tthis: DataRegistry,\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t): T {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors!();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors!();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins(\n\t\tattributes: Record< string, unknown >\n\t): Record< string, unknown > {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\t\treturn ( registry as any )[ key ]( ...args );\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} )\n\t\t);\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param name Store registry name.\n\t * @param createStoreFunc Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance(\n\t\tname: string,\n\t\tcreateStoreFunc: () => InternalStoreInstance\n\t): InternalStoreInstance {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store: any = createStoreFunc();\n\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener: () => void ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param store Store descriptor.\n\t */\n\tfunction register( store: StoreDescriptor< AnyConfig > ) {\n\t\tregisterStoreInstance(\n\t\t\tstore.name,\n\t\t\t() => store.instantiate( registry ) as InternalStoreInstance\n\t\t);\n\t}\n\n\tfunction registerGenericStore(\n\t\tname: string,\n\t\tstore: InternalStoreInstance\n\t) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, () => store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param storeName Unique namespace identifier.\n\t * @param options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return Registered store object.\n\t */\n\tfunction registerStore(\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance(\n\t\t\tstoreName,\n\t\t\t() =>\n\t\t\t\tcreateReduxStore( storeName, options ).instantiate(\n\t\t\t\t\tregistry\n\t\t\t\t) as InternalStoreInstance\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback: () => void ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\n\t}\n\n\tlet registry: DataRegistry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t} as DataRegistry;\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin: DataPlugin, options?: Record< string, unknown > ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\tconst registryWithPlugins = withPlugins(\n\t\tregistry as unknown as Record< string, unknown >\n\t);\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws an error the store was not locked \u2013 this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins as unknown as DataRegistry;\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,OAAO,gBAAgB;AAKvB,OAAO,sBAAsB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,MAAM,cAAc;AAW7B,SAAS,aAAc,uBAAuD;AAC7E,SAAO,OAAO,0BAA0B,WACrC,wBACA,sBAAsB;AAC1B;AAWO,SAAS,eACf,eAAoE,CAAC,GACrE,SAA8B,MACf;AACf,QAAM,SAAkD,CAAC;AACzD,QAAM,UAAU,cAAc;AAC9B,MAAI,kBAAwC;AAK5C,WA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AAA,MACV,CAAE;AAEF,aAAO,MAAM;AACZ,+BAAuB;AACvB,iCAAyB;AAAA,MAC1B;AAAA,IACD;AACA,WAAQ,IAAK,IAAI;AACjB,UAAM,UAAW,cAAe;AAGhC,QAAK,QAAS;AACb,UAAI;AACH,eAAQ,MAAM,KAAM,EAAE;AAAA,UACrB,OAAQ,MAAO,EAAE,iBAAkB,IAAK;AAAA,QACzC;AACA,eAAQ,MAAM,KAAM,EAAE;AAAA,UACrB,OAAQ,MAAO,EAAE,mBAAoB,IAAK;AAAA,QAC3C;AAAA,MACD,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\nimport { lock, unlock } from './lock-unlock';\nimport type {\n\tStoreDescriptor,\n\tStoreNameOrDescriptor,\n\tDataRegistry,\n\tDataPlugin,\n\tInternalStoreInstance,\n\tAnyConfig,\n\tReduxStoreConfig,\n} from './types';\n\nfunction getStoreName( storeNameOrDescriptor: StoreNameOrDescriptor ): string {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param storeConfigs Initial store configurations.\n * @param parent Parent registry.\n *\n * @return Data registry.\n */\nexport function createRegistry(\n\tstoreConfigs: Record< string, ReduxStoreConfig< any, any, any > > = {},\n\tparent: DataRegistry | null = null\n): DataRegistry {\n\tconst stores: Record< string, InternalStoreInstance > = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores: Set< string > | null = null;\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param listener Listener function.\n\t * @param storeNameOrDescriptor Optional store name.\n\t *\n\t * @return Unsubscribe function.\n\t */\n\tconst subscribe = (\n\t\tlistener: () => void,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t): ( () => void ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to global `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores< T >(\n\t\tthis: DataRegistry,\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t): T {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors!();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors!();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor: StoreNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins(\n\t\tattributes: Record< string, unknown >\n\t): Record< string, unknown > {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\t\treturn ( registry as any )[ key ]( ...args );\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} )\n\t\t);\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param name Store registry name.\n\t * @param createStoreFunc Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance(\n\t\tname: string,\n\t\tcreateStoreFunc: () => InternalStoreInstance\n\t): InternalStoreInstance {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store: any = createStoreFunc();\n\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener: () => void ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param store Store descriptor.\n\t */\n\tfunction register( store: StoreDescriptor< AnyConfig > ) {\n\t\tregisterStoreInstance(\n\t\t\tstore.name,\n\t\t\t() => store.instantiate( registry ) as InternalStoreInstance\n\t\t);\n\t}\n\n\tfunction registerGenericStore(\n\t\tname: string,\n\t\tstore: InternalStoreInstance\n\t) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, () => store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param storeName Unique namespace identifier.\n\t * @param options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return Registered store object.\n\t */\n\tfunction registerStore(\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance(\n\t\t\tstoreName,\n\t\t\t() =>\n\t\t\t\tcreateReduxStore( storeName, options ).instantiate(\n\t\t\t\t\tregistry\n\t\t\t\t) as InternalStoreInstance\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback: () => void ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\n\t}\n\n\tlet registry: DataRegistry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t} as DataRegistry;\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin: DataPlugin, options?: Record< string, unknown > ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\tconst registryWithPlugins = withPlugins(\n\t\tregistry as unknown as Record< string, unknown >\n\t);\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch {\n\t\t\t\t// unlock() throws an error the store was not locked \u2013 this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins as unknown as DataRegistry;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,gBAAgB;AAKvB,OAAO,sBAAsB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,MAAM,cAAc;AAW7B,SAAS,aAAc,uBAAuD;AAC7E,SAAO,OAAO,0BAA0B,WACrC,wBACA,sBAAsB;AAC1B;AAWO,SAAS,eACf,eAAoE,CAAC,GACrE,SAA8B,MACf;AACf,QAAM,SAAkD,CAAC;AACzD,QAAM,UAAU,cAAc;AAC9B,MAAI,kBAAwC;AAK5C,WAAS,iBAAiB;AACzB,YAAQ,KAAK;AAAA,EACd;AAWA,QAAM,YAAY,CACjB,UACA,0BACoB;AAEpB,QAAK,CAAE,uBAAwB;AAC9B,aAAO,QAAQ,UAAW,QAAS;AAAA,IACpC;AAGA,UAAM,YAAY,aAAc,qBAAsB;AACtD,UAAM,QAAQ,OAAQ,SAAU;AAChC,QAAK,OAAQ;AACZ,aAAO,MAAM,UAAW,QAAS;AAAA,IAClC;AAMA,QAAK,CAAE,QAAS;AACf,aAAO,QAAQ,UAAW,QAAS;AAAA,IACpC;AAEA,WAAO,OAAO,UAAW,UAAU,qBAAsB;AAAA,EAC1D;AAUA,WAAS,OAAQ,uBAA+C;AAC/D,UAAM,YAAY,aAAc,qBAAsB;AACtD,qBAAiB,IAAK,SAAU;AAChC,UAAM,QAAQ,OAAQ,SAAU;AAChC,QAAK,OAAQ;AACZ,aAAO,MAAM,aAAa;AAAA,IAC3B;AAEA,WAAO,QAAQ,OAAQ,SAAU;AAAA,EAClC;AAEA,WAAS,8BAER,UACA,KACI;AACJ,sBAAkB,oBAAI,IAAI;AAC1B,QAAI;AACH,aAAO,SAAS,KAAM,IAAK;AAAA,IAC5B,UA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Q;AAGP,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,IACA,oBAAoB,CAAE,SAAkB;AACvC,UAAI;AACH,eAAO,OAAQ,OAAQ,IAAK,EAAE,KAAM,EAAE;AAAA,MACvC,QAAQ;AACP,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
|
|
6
6
|
"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,MAA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CAAC;IAC9C,QAAQ,EAAE,YAAY,CAAC;CACvB;AAED,MAAM,MAAM,eAAe,GAAG,OAAO,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.44.0",
|
|
4
4
|
"description": "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.
|
|
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 );
|
|
@@ -94,7 +94,7 @@ export function createPersistenceInterface(
|
|
|
94
94
|
} else {
|
|
95
95
|
try {
|
|
96
96
|
data = JSON.parse( persisted );
|
|
97
|
-
} catch
|
|
97
|
+
} catch {
|
|
98
98
|
// Similarly, should any error be thrown during parse of
|
|
99
99
|
// the string (malformed JSON), fall back to empty object.
|
|
100
100
|
data = {};
|
package/src/registry.ts
CHANGED
|
@@ -261,7 +261,7 @@ export function createRegistry(
|
|
|
261
261
|
unlock( store.store ).registerPrivateSelectors(
|
|
262
262
|
unlock( parent ).privateSelectorsOf( name )
|
|
263
263
|
);
|
|
264
|
-
} catch
|
|
264
|
+
} catch {
|
|
265
265
|
// unlock() throws if store.store was not locked.
|
|
266
266
|
// The error indicates there's nothing to do here so let's
|
|
267
267
|
// ignore it.
|
|
@@ -389,7 +389,7 @@ export function createRegistry(
|
|
|
389
389
|
privateActionsOf: ( name: string ) => {
|
|
390
390
|
try {
|
|
391
391
|
return unlock( stores[ name ].store ).privateActions;
|
|
392
|
-
} catch
|
|
392
|
+
} catch {
|
|
393
393
|
// unlock() throws an error the store was not locked – this means
|
|
394
394
|
// there no private actions are available
|
|
395
395
|
return {};
|
|
@@ -398,7 +398,7 @@ export function createRegistry(
|
|
|
398
398
|
privateSelectorsOf: ( name: string ) => {
|
|
399
399
|
try {
|
|
400
400
|
return unlock( stores[ name ].store ).privateSelectors;
|
|
401
|
-
} catch
|
|
401
|
+
} catch {
|
|
402
402
|
return {};
|
|
403
403
|
}
|
|
404
404
|
},
|
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
|
}
|