@wordpress/data 10.36.1-next.738bb1424.0 → 10.36.1-next.8fd3f8831.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/README.md CHANGED
@@ -620,7 +620,7 @@ _Parameters_
620
620
 
621
621
  _Returns_
622
622
 
623
- - `Object`: Object containing the store's promise-wrapped selectors.
623
+ - `CurriedSelectorsResolveOf< T >`: Object containing the store's promise-wrapped selectors.
624
624
 
625
625
  ### select
626
626
 
package/build/index.cjs CHANGED
@@ -78,7 +78,9 @@ var import_dispatch = require("./dispatch.cjs");
78
78
  var import_select = require("./select.cjs");
79
79
  var defaultRegistry = import_default_registry.default;
80
80
  var combineReducers = import_redux_store.combineReducers;
81
- var resolveSelect = (storeNameOrDescriptor) => defaultRegistry.resolveSelect(storeNameOrDescriptor);
81
+ function resolveSelect(storeNameOrDescriptor) {
82
+ return defaultRegistry.resolveSelect(storeNameOrDescriptor);
83
+ }
82
84
  var suspendSelect = (storeNameOrDescriptor) => defaultRegistry.suspendSelect(storeNameOrDescriptor);
83
85
  var subscribe = (listener, storeNameOrDescriptor) => defaultRegistry.subscribe(listener, storeNameOrDescriptor);
84
86
  var registerGenericStore = defaultRegistry.registerGenericStore;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport defaultRegistryUntyped from './default-registry';\nimport * as plugins from './plugins';\nimport { combineReducers as combineReducersModule } from './redux-store';\n\nimport type {\n\tStoreDescriptor,\n\tReduxStoreConfig,\n\tcombineReducers as CombineReducers,\n} from './types';\n\n// The runtime registry is created from the JavaScript implementation in `registry.js`.\n// Its JSDoc type (`WPDataRegistry`) doesn't include some newer methods like\n// `resolveSelect` or `suspendSelect`, so we widen the type here for the typed\n// exports in this module.\nconst defaultRegistry: any = defaultRegistryUntyped;\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { createSelector } from './create-selector';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\nexport type * from './types';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport const combineReducers =\n\tcombineReducersModule as unknown as CombineReducers;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors\n * pre-bound to state so that you only need to supply additional arguments, and\n * modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = (\n\tstoreNameOrDescriptor:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): any => defaultRegistry.resolveSelect( storeNameOrDescriptor );\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = (\n\tstoreNameOrDescriptor:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): any => defaultRegistry.suspendSelect( storeNameOrDescriptor );\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = (\n\tlistener: () => void,\n\tstoreNameOrDescriptor?:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): ( () => void ) =>\n\tdefaultRegistry.subscribe( listener, storeNameOrDescriptor );\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore: Function =\n\tdefaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore: Function = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use: any = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = (\n\tstore: StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): void => defaultRegistry.register( store );\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,8BAAmC;AACnC,cAAyB;AACzB,yBAAyD;AAczD,yBAAsC;AACtC,2BAAwC;AACxC,2BAAwC;AACxC,+BAIO;AACP,wBAGO;AACP,0BAA4B;AAC5B,iCAAkC;AAClC,sBAA+B;AAC/B,qBAA8D;AAC9D,6BAA+B;AAC/B,sBAAyB;AACzB,IAAAA,sBAA4C;AAC5C,sBAAyB;AACzB,oBAAuB;AAtBvB,IAAM,kBAAuB,wBAAAC;AAwEtB,IAAM,kBACZ,mBAAAC;AAsBM,IAAM,gBAAgB,CAC5B,0BAGS,gBAAgB,cAAe,qBAAsB;AAaxD,IAAM,gBAAgB,CAC5B,0BAGS,gBAAgB,cAAe,qBAAsB;AA0BxD,IAAM,YAAY,CACxB,UACA,0BAIA,gBAAgB,UAAW,UAAU,qBAAsB;AAUrD,IAAM,uBACZ,gBAAgB;AAYV,IAAM,gBAA0B,gBAAgB;AAShD,IAAM,MAAW,gBAAgB;AAoBjC,IAAM,WAAW,CACvB,UACU,gBAAgB,SAAU,KAAM;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport defaultRegistryUntyped from './default-registry';\nimport * as plugins from './plugins';\nimport { combineReducers as combineReducersModule } from './redux-store';\n\nimport type {\n\tStoreDescriptor,\n\tReduxStoreConfig,\n\tcombineReducers as CombineReducers,\n\tAnyConfig,\n\tCurriedSelectorsResolveOf,\n} from './types';\n\n// The runtime registry is created from the JavaScript implementation in `registry.js`.\n// Its JSDoc type (`WPDataRegistry`) doesn't include some newer methods like\n// `resolveSelect` or `suspendSelect`, so we widen the type here for the typed\n// exports in this module.\nconst defaultRegistry: any = defaultRegistryUntyped;\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { createSelector } from './create-selector';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\nexport type * from './types';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport const combineReducers =\n\tcombineReducersModule as unknown as CombineReducers;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors\n * pre-bound to state so that you only need to supply additional arguments, and\n * modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return Object containing the store's promise-wrapped selectors.\n */\nexport function resolveSelect< T extends StoreDescriptor< AnyConfig > >(\n\tstoreNameOrDescriptor: T | string\n): CurriedSelectorsResolveOf< T > {\n\treturn defaultRegistry.resolveSelect( storeNameOrDescriptor );\n}\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = (\n\tstoreNameOrDescriptor:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): any => defaultRegistry.suspendSelect( storeNameOrDescriptor );\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = (\n\tlistener: () => void,\n\tstoreNameOrDescriptor?:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): ( () => void ) =>\n\tdefaultRegistry.subscribe( listener, storeNameOrDescriptor );\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore: Function =\n\tdefaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore: Function = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use: any = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = (\n\tstore: StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): void => defaultRegistry.register( store );\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,8BAAmC;AACnC,cAAyB;AACzB,yBAAyD;AAgBzD,yBAAsC;AACtC,2BAAwC;AACxC,2BAAwC;AACxC,+BAIO;AACP,wBAGO;AACP,0BAA4B;AAC5B,iCAAkC;AAClC,sBAA+B;AAC/B,qBAA8D;AAC9D,6BAA+B;AAC/B,sBAAyB;AACzB,IAAAA,sBAA4C;AAC5C,sBAAyB;AACzB,oBAAuB;AAtBvB,IAAM,kBAAuB,wBAAAC;AAwEtB,IAAM,kBACZ,mBAAAC;AAsBM,SAAS,cACf,uBACiC;AACjC,SAAO,gBAAgB,cAAe,qBAAsB;AAC7D;AAaO,IAAM,gBAAgB,CAC5B,0BAGS,gBAAgB,cAAe,qBAAsB;AA0BxD,IAAM,YAAY,CACxB,UACA,0BAIA,gBAAgB,UAAW,UAAU,qBAAsB;AAUrD,IAAM,uBACZ,gBAAgB;AAYV,IAAM,gBAA0B,gBAAgB;AAShD,IAAM,MAAW,gBAAgB;AAoBjC,IAAM,WAAW,CACvB,UACU,gBAAgB,SAAU,KAAM;",
6
6
  "names": ["import_redux_store", "defaultRegistryUntyped", "combineReducersModule"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/types.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport type { combineReducers as reduxCombineReducers } from 'redux';\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<\n\tState,\n\tActionCreators extends MapOf< ActionCreator >,\n\tSelectors,\n> {\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< ConfigOf< 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< ConfigOf< 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? { [ key in keyof Selectors ]: CurriedState< Selectors[ key ] > }\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}\n\nexport interface DataRegistry {\n\tregister: ( store: StoreDescriptor< any > ) => void;\n\tdispatch: < S extends StoreDescriptor< any > >(\n\t\tstore: S\n\t) => ActionCreatorsOf< ConfigOf< S > >;\n}\n\n// Type Helpers.\n\nexport type ConfigOf< S > = S extends StoreDescriptor< infer C > ? C : never;\n\nexport type ActionCreatorsOf< Config extends AnyConfig > =\n\tConfig extends ReduxStoreConfig< any, infer ActionCreators, any >\n\t\t? PromisifiedActionCreators< ActionCreators >\n\t\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<\n\tActionCreators extends MapOf< ActionCreator >,\n> = {\n\t[ Action in keyof ActionCreators ]: PromisifyActionCreator<\n\t\tActionCreators[ Action ]\n\t>;\n};\n\n// Wraps action creator return types with a Promise and handles thunks.\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 >\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\nexport type combineReducers = typeof reduxCombineReducers;\n"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\n// eslint-disable-next-line no-restricted-imports\nimport type { combineReducers as reduxCombineReducers } from 'redux';\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<\n\tState,\n\tActionCreators extends MapOf< ActionCreator >,\n\tSelectors,\n> {\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< ConfigOf< 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< ConfigOf< 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? { [ key in keyof Selectors ]: CurriedState< Selectors[ key ] > }\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\nexport interface DataRegistry {\n\tregister: ( store: StoreDescriptor< any > ) => void;\n\tdispatch: < S extends StoreDescriptor< any > >(\n\t\tstore: S\n\t) => ActionCreatorsOf< ConfigOf< S > >;\n}\n\n// Type Helpers.\n\nexport type ConfigOf< S > = S extends StoreDescriptor< infer C > ? C : never;\n\nexport type ActionCreatorsOf< Config extends AnyConfig > =\n\tConfig extends ReduxStoreConfig< any, infer ActionCreators, any >\n\t\t? PromisifiedActionCreators< ActionCreators >\n\t\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<\n\tActionCreators extends MapOf< ActionCreator >,\n> = {\n\t[ Action in keyof ActionCreators ]: PromisifyActionCreator<\n\t\tActionCreators[ Action ]\n\t>;\n};\n\n// Wraps action creator return types with a Promise and handles thunks.\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 >\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\nexport type combineReducers = typeof reduxCombineReducers;\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;",
6
6
  "names": []
7
7
  }
@@ -25,7 +25,9 @@ import { dispatch } from "./dispatch.js";
25
25
  import { select } from "./select.js";
26
26
  var defaultRegistry = defaultRegistryUntyped;
27
27
  var combineReducers = combineReducersModule;
28
- var resolveSelect = (storeNameOrDescriptor) => defaultRegistry.resolveSelect(storeNameOrDescriptor);
28
+ function resolveSelect(storeNameOrDescriptor) {
29
+ return defaultRegistry.resolveSelect(storeNameOrDescriptor);
30
+ }
29
31
  var suspendSelect = (storeNameOrDescriptor) => defaultRegistry.suspendSelect(storeNameOrDescriptor);
30
32
  var subscribe = (listener, storeNameOrDescriptor) => defaultRegistry.subscribe(listener, storeNameOrDescriptor);
31
33
  var registerGenericStore = defaultRegistry.registerGenericStore;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["/**\n * Internal dependencies\n */\nimport defaultRegistryUntyped from './default-registry';\nimport * as plugins from './plugins';\nimport { combineReducers as combineReducersModule } from './redux-store';\n\nimport type {\n\tStoreDescriptor,\n\tReduxStoreConfig,\n\tcombineReducers as CombineReducers,\n} from './types';\n\n// The runtime registry is created from the JavaScript implementation in `registry.js`.\n// Its JSDoc type (`WPDataRegistry`) doesn't include some newer methods like\n// `resolveSelect` or `suspendSelect`, so we widen the type here for the typed\n// exports in this module.\nconst defaultRegistry: any = defaultRegistryUntyped;\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { createSelector } from './create-selector';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\nexport type * from './types';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport const combineReducers =\n\tcombineReducersModule as unknown as CombineReducers;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors\n * pre-bound to state so that you only need to supply additional arguments, and\n * modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = (\n\tstoreNameOrDescriptor:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): any => defaultRegistry.resolveSelect( storeNameOrDescriptor );\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = (\n\tstoreNameOrDescriptor:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): any => defaultRegistry.suspendSelect( storeNameOrDescriptor );\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = (\n\tlistener: () => void,\n\tstoreNameOrDescriptor?:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): ( () => void ) =>\n\tdefaultRegistry.subscribe( listener, storeNameOrDescriptor );\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore: Function =\n\tdefaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore: Function = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use: any = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = (\n\tstore: StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): void => defaultRegistry.register( store );\n"],
5
- "mappings": ";AAGA,OAAO,4BAA4B;AACnC,YAAY,aAAa;AACzB,SAAS,mBAAmB,6BAA6B;AAczD,SAAoB,WAAXA,gBAA6B;AACtC,SAAoB,WAAXA,gBAA+B;AACxC,SAAoB,WAAXA,gBAA+B;AACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACY,WAAXA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB,6BAA6B;AAC9D,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAoB,WAAXA,gBAAmC;AAC5C,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAtBvB,IAAM,kBAAuB;AAwEtB,IAAM,kBACZ;AAsBM,IAAM,gBAAgB,CAC5B,0BAGS,gBAAgB,cAAe,qBAAsB;AAaxD,IAAM,gBAAgB,CAC5B,0BAGS,gBAAgB,cAAe,qBAAsB;AA0BxD,IAAM,YAAY,CACxB,UACA,0BAIA,gBAAgB,UAAW,UAAU,qBAAsB;AAUrD,IAAM,uBACZ,gBAAgB;AAYV,IAAM,gBAA0B,gBAAgB;AAShD,IAAM,MAAW,gBAAgB;AAoBjC,IAAM,WAAW,CACvB,UACU,gBAAgB,SAAU,KAAM;",
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport defaultRegistryUntyped from './default-registry';\nimport * as plugins from './plugins';\nimport { combineReducers as combineReducersModule } from './redux-store';\n\nimport type {\n\tStoreDescriptor,\n\tReduxStoreConfig,\n\tcombineReducers as CombineReducers,\n\tAnyConfig,\n\tCurriedSelectorsResolveOf,\n} from './types';\n\n// The runtime registry is created from the JavaScript implementation in `registry.js`.\n// Its JSDoc type (`WPDataRegistry`) doesn't include some newer methods like\n// `resolveSelect` or `suspendSelect`, so we widen the type here for the typed\n// exports in this module.\nconst defaultRegistry: any = defaultRegistryUntyped;\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { createSelector } from './create-selector';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\nexport type * from './types';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport const combineReducers =\n\tcombineReducersModule as unknown as CombineReducers;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors\n * pre-bound to state so that you only need to supply additional arguments, and\n * modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return Object containing the store's promise-wrapped selectors.\n */\nexport function resolveSelect< T extends StoreDescriptor< AnyConfig > >(\n\tstoreNameOrDescriptor: T | string\n): CurriedSelectorsResolveOf< T > {\n\treturn defaultRegistry.resolveSelect( storeNameOrDescriptor );\n}\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = (\n\tstoreNameOrDescriptor:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): any => defaultRegistry.suspendSelect( storeNameOrDescriptor );\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = (\n\tlistener: () => void,\n\tstoreNameOrDescriptor?:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): ( () => void ) =>\n\tdefaultRegistry.subscribe( listener, storeNameOrDescriptor );\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore: Function =\n\tdefaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore: Function = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use: any = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = (\n\tstore: StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): void => defaultRegistry.register( store );\n"],
5
+ "mappings": ";AAGA,OAAO,4BAA4B;AACnC,YAAY,aAAa;AACzB,SAAS,mBAAmB,6BAA6B;AAgBzD,SAAoB,WAAXA,gBAA6B;AACtC,SAAoB,WAAXA,gBAA+B;AACxC,SAAoB,WAAXA,gBAA+B;AACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACY,WAAXA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB,6BAA6B;AAC9D,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAoB,WAAXA,gBAAmC;AAC5C,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAtBvB,IAAM,kBAAuB;AAwEtB,IAAM,kBACZ;AAsBM,SAAS,cACf,uBACiC;AACjC,SAAO,gBAAgB,cAAe,qBAAsB;AAC7D;AAaO,IAAM,gBAAgB,CAC5B,0BAGS,gBAAgB,cAAe,qBAAsB;AA0BxD,IAAM,YAAY,CACxB,UACA,0BAIA,gBAAgB,UAAW,UAAU,qBAAsB;AAUrD,IAAM,uBACZ,gBAAgB;AAYV,IAAM,gBAA0B,gBAAgB;AAShD,IAAM,MAAW,gBAAgB;AAoBjC,IAAM,WAAW,CACvB,UACU,gBAAgB,SAAU,KAAM;",
6
6
  "names": ["default"]
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import * as plugins from './plugins';
2
- import type { StoreDescriptor, ReduxStoreConfig, combineReducers as CombineReducers } from './types';
2
+ import type { StoreDescriptor, ReduxStoreConfig, combineReducers as CombineReducers, AnyConfig, CurriedSelectorsResolveOf } from './types';
3
3
  export { default as withSelect } from './components/with-select';
4
4
  export { default as withDispatch } from './components/with-dispatch';
5
5
  export { default as withRegistry } from './components/with-registry';
@@ -79,9 +79,9 @@ export declare const combineReducers: CombineReducers;
79
79
  * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)
80
80
  * ```
81
81
  *
82
- * @return {Object} Object containing the store's promise-wrapped selectors.
82
+ * @return Object containing the store's promise-wrapped selectors.
83
83
  */
84
- export declare const resolveSelect: (storeNameOrDescriptor: string | StoreDescriptor<ReduxStoreConfig<any, any, any>>) => any;
84
+ export declare function resolveSelect<T extends StoreDescriptor<AnyConfig>>(storeNameOrDescriptor: T | string): CurriedSelectorsResolveOf<T>;
85
85
  /**
86
86
  * Given a store descriptor, returns an object containing the store's selectors pre-bound to state
87
87
  * so that you only need to supply additional arguments, and modified so that they throw promises
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAGr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AAE,CAAE,KACrD,CAAE,MAAM,IAAI,CAC8C,CAAC;AAE9D;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,EAAE,QACE,CAAC;AAEtC;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,QAAwC,CAAC;AAErE;;;;;;GAMG;AACH,eAAO,MAAM,GAAG,EAAE,GAAyB,CAAC;AAE5C;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,QAAQ,GACpB,OAAO,eAAe,CAAE,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAE,CAAE,KACzD,IAAyC,CAAC"}
@@ -46,6 +46,26 @@ export type ListenerFunction = () => void;
46
46
  export type CurriedSelectorsOf<S> = S extends StoreDescriptor<ReduxStoreConfig<any, any, infer Selectors>> ? {
47
47
  [key in keyof Selectors]: CurriedState<Selectors[key]>;
48
48
  } : never;
49
+ /**
50
+ * Like CurriedState but wraps the return type in a Promise.
51
+ * Used for resolveSelect where selectors return promises.
52
+ *
53
+ * For generic selectors that define PromiseCurriedSignature, that signature
54
+ * is used directly to preserve generic type parameters (which would otherwise
55
+ * be lost when using `infer`).
56
+ */
57
+ type CurriedStateWithPromise<F> = F extends SelectorWithCustomCurrySignature & {
58
+ PromiseCurriedSignature: infer S;
59
+ } ? S : F extends SelectorWithCustomCurrySignature & {
60
+ CurriedSignature: (...args: infer P) => infer R;
61
+ } ? (...args: P) => Promise<R> : F extends (state: any, ...args: infer P) => infer R ? (...args: P) => Promise<R> : F;
62
+ /**
63
+ * Like CurriedSelectorsOf but each selector returns a Promise.
64
+ * Used for resolveSelect.
65
+ */
66
+ export type CurriedSelectorsResolveOf<S> = S extends StoreDescriptor<ReduxStoreConfig<any, any, infer Selectors>> ? {
67
+ [key in keyof Selectors]: CurriedStateWithPromise<Selectors[key]>;
68
+ } : never;
49
69
  /**
50
70
  * Removes the first argument from a function.
51
71
  *
@@ -109,6 +129,7 @@ type CurriedState<F> = F extends SelectorWithCustomCurrySignature ? F['CurriedSi
109
129
  */
110
130
  export interface SelectorWithCustomCurrySignature {
111
131
  CurriedSignature: Function;
132
+ PromiseCurriedSignature?: Function;
112
133
  }
113
134
  export interface DataRegistry {
114
135
  register: (store: StoreDescriptor<any>) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,IAAI,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAErE,KAAK,KAAK,CAAE,CAAC,IAAK;IAAE,CAAE,IAAI,EAAE,MAAM,GAAI,CAAC,CAAA;CAAE,CAAC;AAE1C,MAAM,MAAM,aAAa,GAAG,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAM,GAAG,GAAG,SAAS,CAAC;AAClE,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAC5C,MAAM,MAAM,QAAQ,GAAG,QAAQ,CAAC;AAEhC,MAAM,MAAM,SAAS,GAAG,gBAAgB,CAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAE,CAAC;AAE1D,MAAM,WAAW,aAAa,CAAE,MAAM,SAAS,SAAS;IACvD,YAAY,EAAE,MAAM,WAAW,CAAE,MAAM,CAAE,CAAC;IAC1C,UAAU,EAAE,MAAM,gBAAgB,CAAE,MAAM,CAAE,CAAC;IAC7C,SAAS,EAAE,CAAE,QAAQ,EAAE,MAAM,IAAI,KAAM,MAAM,IAAI,CAAC;CAClD;AAED,MAAM,WAAW,eAAe,CAAE,MAAM,SAAS,SAAS,GAAG,SAAS;IACrE;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,CAAE,QAAQ,EAAE,YAAY,KAAM,aAAa,CAAE,MAAM,CAAE,CAAC;CACnE;AAED,MAAM,WAAW,gBAAgB,CAChC,KAAK,EACL,cAAc,SAAS,KAAK,CAAE,aAAa,CAAE,EAC7C,SA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CAAC,GAAG,KAAK,CAAC;AAE7E,MAAM,MAAM,gBAAgB,CAAE,MAAM,SAAS,SAAS,IACrD,MAAM,SAAS,gBAAgB,CAAE,GAAG,EAAE,MAAM,cAAc,EAAE,GAAG,CAAE,GAC9D,yBAAyB,CAAE,cAAc,CAAE,GAC3C,KAAK,CAAC;AAKV,MAAM,MAAM,yBAAyB,CACpC,cAAc,SAAS,KAAK,CAAE,aAAa,CAAE,IAC1C;KACD,MAAM,IAAI,MAAM,cAAc,GAAI,sBAAsB,CACzD,cAAc,CAAE,MAAM,CAAE,CACxB;CACD,CAAC;AAGF,MAAM,MAAM,sBAAsB,CAAE,MAAM,SAAS,aAAa,IAAK,CACpE,GAAG,IAAI,EAAE,UAAU,CAAE,MAAM,CAAE,KACzB,OAAO,CACX,UAAU,CAAE,MAAM,CAAE,SAAS,CAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAM,GAAG,GACpD,eAAe,CAAE,MAAM,CAAE,GACzB,UAAU,CAAE,MAAM,CAAE,CACvB,CAAC;AAMF,MAAM,MAAM,eAAe,CAAE,MAAM,SAAS,aAAa,IAAK,OAAO,CACpE,UAAU,CAAE,UAAU,CAAE,MAAM,CAAE,CAAE,CAClC,CAAC;AAEF,KAAK,WAAW,CAAE,MAAM,SAAS,SAAS,IAAK,MAAM,SAAS,gBAAgB,CAC7E,GAAG,EACH,GAAG,EACH,MAAM,SAAS,CACf,GACE;KAAI,IAAI,IAAI,MAAM,SAAS,GAAI,QAAQ;CAAE,GACzC,KAAK,CAAC;AAET,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.36.1-next.738bb1424.0",
3
+ "version": "10.36.1-next.8fd3f8831.0",
4
4
  "description": "Data module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -46,13 +46,13 @@
46
46
  "types": "build-types",
47
47
  "sideEffects": false,
48
48
  "dependencies": {
49
- "@wordpress/compose": "^7.36.1-next.738bb1424.0",
50
- "@wordpress/deprecated": "^4.36.1-next.738bb1424.0",
51
- "@wordpress/element": "^6.36.1-next.738bb1424.0",
52
- "@wordpress/is-shallow-equal": "^5.36.1-next.738bb1424.0",
53
- "@wordpress/priority-queue": "^3.36.1-next.738bb1424.0",
54
- "@wordpress/private-apis": "^1.36.1-next.738bb1424.0",
55
- "@wordpress/redux-routine": "^5.36.1-next.738bb1424.0",
49
+ "@wordpress/compose": "^7.36.1-next.8fd3f8831.0",
50
+ "@wordpress/deprecated": "^4.36.1-next.8fd3f8831.0",
51
+ "@wordpress/element": "^6.36.1-next.8fd3f8831.0",
52
+ "@wordpress/is-shallow-equal": "^5.36.1-next.8fd3f8831.0",
53
+ "@wordpress/priority-queue": "^3.36.1-next.8fd3f8831.0",
54
+ "@wordpress/private-apis": "^1.36.1-next.8fd3f8831.0",
55
+ "@wordpress/redux-routine": "^5.36.1-next.8fd3f8831.0",
56
56
  "deepmerge": "^4.3.0",
57
57
  "equivalent-key-map": "^0.2.2",
58
58
  "is-plain-object": "^5.0.0",
@@ -67,5 +67,5 @@
67
67
  "publishConfig": {
68
68
  "access": "public"
69
69
  },
70
- "gitHead": "ab1b004c0d61c295aa34bc86ea07f979343983ce"
70
+ "gitHead": "e582b351bc4c4b8734bb087f63a3beec9875c3c7"
71
71
  }
package/src/index.ts CHANGED
@@ -9,6 +9,8 @@ import type {
9
9
  StoreDescriptor,
10
10
  ReduxStoreConfig,
11
11
  combineReducers as CombineReducers,
12
+ AnyConfig,
13
+ CurriedSelectorsResolveOf,
12
14
  } from './types';
13
15
 
14
16
  // The runtime registry is created from the JavaScript implementation in `registry.js`.
@@ -108,13 +110,13 @@ export const combineReducers =
108
110
  * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)
109
111
  * ```
110
112
  *
111
- * @return {Object} Object containing the store's promise-wrapped selectors.
113
+ * @return Object containing the store's promise-wrapped selectors.
112
114
  */
113
- export const resolveSelect = (
114
- storeNameOrDescriptor:
115
- | string
116
- | StoreDescriptor< ReduxStoreConfig< any, any, any > >
117
- ): any => defaultRegistry.resolveSelect( storeNameOrDescriptor );
115
+ export function resolveSelect< T extends StoreDescriptor< AnyConfig > >(
116
+ storeNameOrDescriptor: T | string
117
+ ): CurriedSelectorsResolveOf< T > {
118
+ return defaultRegistry.resolveSelect( storeNameOrDescriptor );
119
+ }
118
120
 
119
121
  /**
120
122
  * Given a store descriptor, returns an object containing the store's selectors pre-bound to state
package/src/types.ts CHANGED
@@ -87,6 +87,41 @@ export type CurriedSelectorsOf< S > = S extends StoreDescriptor<
87
87
  ? { [ key in keyof Selectors ]: CurriedState< Selectors[ key ] > }
88
88
  : never;
89
89
 
90
+ /**
91
+ * Like CurriedState but wraps the return type in a Promise.
92
+ * Used for resolveSelect where selectors return promises.
93
+ *
94
+ * For generic selectors that define PromiseCurriedSignature, that signature
95
+ * is used directly to preserve generic type parameters (which would otherwise
96
+ * be lost when using `infer`).
97
+ */
98
+ type CurriedStateWithPromise< F > =
99
+ F extends SelectorWithCustomCurrySignature & {
100
+ PromiseCurriedSignature: infer S;
101
+ }
102
+ ? S
103
+ : F extends SelectorWithCustomCurrySignature & {
104
+ CurriedSignature: ( ...args: infer P ) => infer R;
105
+ }
106
+ ? ( ...args: P ) => Promise< R >
107
+ : F extends ( state: any, ...args: infer P ) => infer R
108
+ ? ( ...args: P ) => Promise< R >
109
+ : F;
110
+
111
+ /**
112
+ * Like CurriedSelectorsOf but each selector returns a Promise.
113
+ * Used for resolveSelect.
114
+ */
115
+ export type CurriedSelectorsResolveOf< S > = S extends StoreDescriptor<
116
+ ReduxStoreConfig< any, any, infer Selectors >
117
+ >
118
+ ? {
119
+ [ key in keyof Selectors ]: CurriedStateWithPromise<
120
+ Selectors[ key ]
121
+ >;
122
+ }
123
+ : never;
124
+
90
125
  /**
91
126
  * Removes the first argument from a function.
92
127
  *
@@ -155,6 +190,7 @@ type CurriedState< F > = F extends SelectorWithCustomCurrySignature
155
190
  */
156
191
  export interface SelectorWithCustomCurrySignature {
157
192
  CurriedSignature: Function;
193
+ PromiseCurriedSignature?: Function;
158
194
  }
159
195
 
160
196
  export interface DataRegistry {