@wordpress/data 10.41.0 → 10.41.1-next.v.202603161435.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 +20 -28
- package/build/components/async-mode-provider/context.cjs +1 -1
- package/build/components/async-mode-provider/context.cjs.map +3 -3
- package/build/components/async-mode-provider/index.cjs +1 -1
- package/build/components/async-mode-provider/index.cjs.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs.map +3 -3
- package/build/components/registry-provider/context.cjs +1 -1
- package/build/components/registry-provider/context.cjs.map +1 -1
- package/build/components/registry-provider/index.cjs +1 -1
- package/build/components/registry-provider/index.cjs.map +1 -1
- package/build/components/registry-provider/use-registry.cjs +1 -1
- package/build/components/registry-provider/use-registry.cjs.map +3 -3
- package/build/components/use-dispatch/index.cjs +1 -1
- package/build/components/use-dispatch/index.cjs.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs.map +3 -3
- package/build/components/use-dispatch/use-dispatch.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch.cjs.map +3 -3
- package/build/components/use-select/index.cjs +2 -2
- package/build/components/use-select/index.cjs.map +3 -3
- package/build/components/with-dispatch/index.cjs +1 -1
- package/build/components/with-dispatch/index.cjs.map +3 -3
- package/build/components/with-registry/index.cjs +1 -1
- package/build/components/with-registry/index.cjs.map +3 -3
- package/build/components/with-select/index.cjs +1 -1
- package/build/components/with-select/index.cjs.map +3 -3
- package/build/controls.cjs +7 -6
- package/build/controls.cjs.map +3 -3
- package/build/default-registry.cjs +3 -2
- package/build/default-registry.cjs.map +3 -3
- package/build/dispatch.cjs +3 -1
- package/build/dispatch.cjs.map +2 -2
- package/build/factory.cjs.map +2 -2
- package/build/index.cjs +9 -8
- package/build/index.cjs.map +3 -3
- package/build/plugins/index.cjs +1 -1
- package/build/plugins/index.cjs.map +1 -1
- package/build/plugins/persistence/index.cjs +13 -8
- package/build/plugins/persistence/index.cjs.map +3 -3
- package/build/plugins/persistence/storage/default.cjs +1 -1
- package/build/plugins/persistence/storage/default.cjs.map +3 -3
- package/build/plugins/persistence/storage/object.cjs +1 -1
- package/build/plugins/persistence/storage/object.cjs.map +3 -3
- package/build/promise-middleware.cjs +2 -1
- package/build/promise-middleware.cjs.map +3 -3
- package/build/redux-store/index.cjs +32 -16
- package/build/redux-store/index.cjs.map +3 -3
- package/build/redux-store/metadata/selectors.cjs +1 -1
- package/build/redux-store/metadata/selectors.cjs.map +3 -3
- package/build/redux-store/metadata/types.cjs +19 -0
- package/build/redux-store/metadata/types.cjs.map +7 -0
- package/build/registry.cjs +11 -7
- package/build/registry.cjs.map +3 -3
- package/build/resolvers-cache-middleware.cjs +6 -3
- package/build/resolvers-cache-middleware.cjs.map +3 -3
- package/build/select.cjs +3 -1
- package/build/select.cjs.map +2 -2
- package/build/store/index.cjs +1 -1
- package/build/store/index.cjs.map +3 -3
- package/build/types.cjs.map +1 -1
- package/build-module/components/async-mode-provider/context.mjs +1 -1
- package/build-module/components/async-mode-provider/context.mjs.map +3 -3
- package/build-module/components/async-mode-provider/index.mjs +1 -1
- package/build-module/components/async-mode-provider/index.mjs.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs.map +3 -3
- package/build-module/components/registry-provider/context.mjs +1 -1
- package/build-module/components/registry-provider/context.mjs.map +1 -1
- package/build-module/components/registry-provider/index.mjs +1 -1
- package/build-module/components/registry-provider/index.mjs.map +1 -1
- package/build-module/components/registry-provider/use-registry.mjs +1 -1
- package/build-module/components/registry-provider/use-registry.mjs.map +3 -3
- package/build-module/components/use-dispatch/index.mjs +1 -1
- package/build-module/components/use-dispatch/index.mjs.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs.map +3 -3
- package/build-module/components/use-dispatch/use-dispatch.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch.mjs.map +3 -3
- package/build-module/components/use-select/index.mjs +2 -2
- package/build-module/components/use-select/index.mjs.map +3 -3
- package/build-module/components/with-dispatch/index.mjs +1 -1
- package/build-module/components/with-dispatch/index.mjs.map +3 -3
- package/build-module/components/with-registry/index.mjs +1 -1
- package/build-module/components/with-registry/index.mjs.map +3 -3
- package/build-module/components/with-select/index.mjs +1 -1
- package/build-module/components/with-select/index.mjs.map +3 -3
- package/build-module/controls.mjs +7 -6
- package/build-module/controls.mjs.map +3 -3
- package/build-module/default-registry.mjs +3 -2
- package/build-module/default-registry.mjs.map +3 -3
- package/build-module/dispatch.mjs +3 -1
- package/build-module/dispatch.mjs.map +2 -2
- package/build-module/factory.mjs.map +2 -2
- package/build-module/index.mjs +4 -3
- package/build-module/index.mjs.map +2 -2
- package/build-module/plugins/index.mjs +1 -1
- package/build-module/plugins/index.mjs.map +1 -1
- package/build-module/plugins/persistence/index.mjs +13 -8
- package/build-module/plugins/persistence/index.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/default.mjs +1 -1
- package/build-module/plugins/persistence/storage/default.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/object.mjs +1 -1
- package/build-module/plugins/persistence/storage/object.mjs.map +3 -3
- package/build-module/promise-middleware.mjs +2 -1
- package/build-module/promise-middleware.mjs.map +3 -3
- package/build-module/redux-store/index.mjs +32 -16
- package/build-module/redux-store/index.mjs.map +3 -3
- package/build-module/redux-store/metadata/selectors.mjs +1 -1
- package/build-module/redux-store/metadata/selectors.mjs.map +3 -3
- package/build-module/redux-store/metadata/types.mjs +1 -0
- package/build-module/redux-store/metadata/types.mjs.map +7 -0
- package/build-module/registry.mjs +11 -7
- package/build-module/registry.mjs.map +3 -3
- package/build-module/resolvers-cache-middleware.mjs +6 -3
- package/build-module/resolvers-cache-middleware.mjs.map +3 -3
- package/build-module/select.mjs +3 -1
- package/build-module/select.mjs.map +2 -2
- package/build-module/store/index.mjs +1 -1
- package/build-module/store/index.mjs.map +3 -3
- package/build-types/components/async-mode-provider/context.d.ts +37 -3
- package/build-types/components/async-mode-provider/context.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/index.d.ts +2 -2
- package/build-types/components/async-mode-provider/index.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -1
- package/build-types/components/registry-provider/context.d.ts +10 -3
- package/build-types/components/registry-provider/context.d.ts.map +1 -1
- package/build-types/components/registry-provider/index.d.ts +2 -2
- package/build-types/components/registry-provider/index.d.ts.map +1 -1
- package/build-types/components/registry-provider/use-registry.d.ts +3 -2
- package/build-types/components/registry-provider/use-registry.d.ts.map +1 -1
- package/build-types/components/use-dispatch/index.d.ts +2 -2
- package/build-types/components/use-dispatch/index.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +11 -9
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch.d.ts +10 -19
- package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -1
- package/build-types/components/use-select/index.d.ts +24 -28
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/components/with-dispatch/index.d.ts +10 -11
- package/build-types/components/with-dispatch/index.d.ts.map +1 -1
- package/build-types/components/with-registry/index.d.ts +2 -6
- package/build-types/components/with-registry/index.d.ts.map +1 -1
- package/build-types/components/with-select/index.d.ts +7 -8
- package/build-types/components/with-select/index.d.ts.map +1 -1
- package/build-types/controls.d.ts +57 -44
- package/build-types/controls.d.ts.map +1 -1
- package/build-types/default-registry.d.ts +2 -2
- package/build-types/default-registry.d.ts.map +1 -1
- package/build-types/dispatch.d.ts +4 -0
- package/build-types/dispatch.d.ts.map +1 -1
- package/build-types/factory.d.ts +2 -1
- package/build-types/factory.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/plugins/index.d.ts +1 -1
- package/build-types/plugins/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/index.d.ts +38 -27
- package/build-types/plugins/persistence/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/default.d.ts +7 -1
- package/build-types/plugins/persistence/storage/default.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/object.d.ts +4 -5
- package/build-types/plugins/persistence/storage/object.d.ts.map +1 -1
- package/build-types/promise-middleware.d.ts +6 -4
- package/build-types/promise-middleware.d.ts.map +1 -1
- package/build-types/redux-store/index.d.ts +12 -15
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/build-types/redux-store/metadata/selectors.d.ts +45 -50
- package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
- package/build-types/redux-store/metadata/types.d.ts +48 -0
- package/build-types/redux-store/metadata/types.d.ts.map +1 -0
- package/build-types/registry.d.ts +5 -49
- package/build-types/registry.d.ts.map +1 -1
- package/build-types/resolvers-cache-middleware.d.ts +13 -7
- package/build-types/resolvers-cache-middleware.d.ts.map +1 -1
- package/build-types/select.d.ts +3 -0
- package/build-types/select.d.ts.map +1 -1
- package/build-types/store/index.d.ts +5 -12
- package/build-types/store/index.d.ts.map +1 -1
- package/build-types/types.d.ts +201 -10
- package/build-types/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/components/async-mode-provider/{context.js → context.ts} +0 -1
- package/src/components/async-mode-provider/{use-async-mode.js → use-async-mode.ts} +1 -1
- package/src/components/registry-provider/{use-registry.js → use-registry.ts} +3 -2
- package/src/components/use-dispatch/{use-dispatch-with-map.js → use-dispatch-with-map.ts} +18 -9
- package/src/components/use-dispatch/{use-dispatch.js → use-dispatch.ts} +25 -20
- package/src/components/use-select/{index.js → index.ts} +84 -70
- package/src/components/with-dispatch/{index.js → index.tsx} +20 -13
- package/src/components/with-registry/{index.js → index.tsx} +1 -5
- package/src/components/with-select/{index.js → index.tsx} +17 -10
- package/src/{controls.js → controls.ts} +53 -26
- package/src/{default-registry.js → default-registry.ts} +3 -1
- package/src/dispatch.ts +7 -1
- package/src/factory.ts +4 -3
- package/src/index.ts +4 -8
- package/src/plugins/persistence/{index.js → index.ts} +93 -54
- package/src/plugins/persistence/storage/{default.js → default.ts} +3 -2
- package/src/plugins/persistence/storage/object.ts +25 -0
- package/src/{promise-middleware.js → promise-middleware.ts} +3 -3
- package/src/redux-store/{index.js → index.ts} +218 -131
- package/src/redux-store/metadata/{selectors.js → selectors.ts} +83 -54
- package/src/redux-store/metadata/types.ts +100 -0
- package/src/{registry.js → registry.ts} +98 -88
- package/src/{resolvers-cache-middleware.js → resolvers-cache-middleware.ts} +22 -7
- package/src/select.ts +6 -1
- package/src/store/{index.js → index.ts} +13 -8
- package/src/types.ts +263 -24
- package/src/plugins/persistence/storage/object.js +0 -23
- /package/src/components/async-mode-provider/{index.js → index.ts} +0 -0
- /package/src/components/registry-provider/{context.js → context.ts} +0 -0
- /package/src/components/registry-provider/{index.js → index.ts} +0 -0
- /package/src/components/use-dispatch/{index.js → index.ts} +0 -0
- /package/src/plugins/{index.js → index.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/redux-store/index.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport createReduxRoutineMiddleware from '@wordpress/redux-routine';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { combineReducers } from './combine-reducers';\nimport { builtinControls } from '../controls';\nimport { lock } from '../lock-unlock';\nimport promise from '../promise-middleware';\nimport createResolversCacheMiddleware from '../resolvers-cache-middleware';\nimport createThunkMiddleware from './thunk-middleware';\nimport metadataReducer from './metadata/reducer';\nimport * as metadataSelectors from './metadata/selectors';\nimport * as metadataActions from './metadata/actions';\n\nexport { combineReducers };\n\n/** @typedef {import('../types').DataRegistry} DataRegistry */\n/** @typedef {import('../types').ListenerFunction} ListenerFunction */\n/**\n * @typedef {import('../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../types').AnyConfig} C\n */\n/**\n * @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../types').ActionCreator>} Actions\n * @template Selectors\n */\n\nconst trimUndefinedValues = ( array ) => {\n\tconst result = [ ...array ];\n\tfor ( let i = result.length - 1; i >= 0; i-- ) {\n\t\tif ( result[ i ] === undefined ) {\n\t\t\tresult.splice( i, 1 );\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * Creates a new object with the same keys, but with `callback()` called as\n * a transformer function on each of the values.\n *\n * @param {Object} obj The object to transform.\n * @param {Function} callback The function to transform each object value.\n * @return {Array} Transformed object.\n */\nconst mapValues = ( obj, callback ) =>\n\tObject.fromEntries(\n\t\tObject.entries( obj ?? {} ).map( ( [ key, value ] ) => [\n\t\t\tkey,\n\t\t\tcallback( value, key ),\n\t\t] )\n\t);\n\n// Convert non serializable types to plain objects\nconst devToolsReplacer = ( key, state ) => {\n\tif ( state instanceof Map ) {\n\t\treturn Object.fromEntries( state );\n\t}\n\n\tif ( state instanceof window.HTMLElement ) {\n\t\treturn null;\n\t}\n\n\treturn state;\n};\n\n/**\n * Create a cache to track whether resolvers started running or not.\n *\n * @return {Object} Resolvers Cache.\n */\nfunction createResolversCache() {\n\tconst cache = {};\n\treturn {\n\t\tisRunning( selectorName, args ) {\n\t\t\treturn (\n\t\t\t\tcache[ selectorName ] &&\n\t\t\t\tcache[ selectorName ].get( trimUndefinedValues( args ) )\n\t\t\t);\n\t\t},\n\n\t\tclear( selectorName, args ) {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( trimUndefinedValues( args ) );\n\t\t\t}\n\t\t},\n\n\t\tmarkAsRunning( selectorName, args ) {\n\t\t\tif ( ! cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ] = new EquivalentKeyMap();\n\t\t\t}\n\n\t\t\tcache[ selectorName ].set( trimUndefinedValues( args ), true );\n\t\t},\n\t};\n}\n\nfunction createBindingCache( getItem, bindItem ) {\n\tconst cache = new WeakMap();\n\n\treturn {\n\t\tget( itemName ) {\n\t\t\tconst item = getItem( itemName );\n\t\t\tif ( ! item ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet boundItem = cache.get( item );\n\t\t\tif ( ! boundItem ) {\n\t\t\t\tboundItem = bindItem( item, itemName );\n\t\t\t\tcache.set( item, boundItem );\n\t\t\t}\n\t\t\treturn boundItem;\n\t\t},\n\t};\n}\n\nfunction createPrivateProxy( publicItems, privateItems ) {\n\treturn new Proxy( publicItems, {\n\t\tget: ( target, itemName ) =>\n\t\t\tprivateItems.get( itemName ) || Reflect.get( target, itemName ),\n\t} );\n}\n\n/**\n * Creates a data store descriptor for the provided Redux store configuration containing\n * properties describing reducer, actions, selectors, controls and resolvers.\n *\n * @example\n * ```js\n * import { createReduxStore } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * ```\n *\n * @template State\n * @template {Record<string,import('../types').ActionCreator>} Actions\n * @template Selectors\n * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>} Store Object.\n */\nexport default function createReduxStore( key, options ) {\n\tconst privateActions = {};\n\tconst privateSelectors = {};\n\tconst privateRegistrationFunctions = {\n\t\tprivateActions,\n\t\tregisterPrivateActions: ( actions ) => {\n\t\t\tObject.assign( privateActions, actions );\n\t\t},\n\t\tprivateSelectors,\n\t\tregisterPrivateSelectors: ( selectors ) => {\n\t\t\tObject.assign( privateSelectors, selectors );\n\t\t},\n\t};\n\tconst storeDescriptor = {\n\t\tname: key,\n\t\tinstantiate: ( registry ) => {\n\t\t\t/**\n\t\t\t * Stores listener functions registered with `subscribe()`.\n\t\t\t *\n\t\t\t * When functions register to listen to store changes with\n\t\t\t * `subscribe()` they get added here. Although Redux offers\n\t\t\t * its own `subscribe()` function directly, by wrapping the\n\t\t\t * subscription in this store instance it's possible to\n\t\t\t * optimize checking if the state has changed before calling\n\t\t\t * each listener.\n\t\t\t *\n\t\t\t * @type {Set<ListenerFunction>}\n\t\t\t */\n\t\t\tconst listeners = new Set();\n\t\t\tconst reducer = options.reducer;\n\n\t\t\t// Object that every thunk function receives as the first argument. It contains the\n\t\t\t// `registry`, `dispatch`, `select` and `resolveSelect` fields. Some of them are\n\t\t\t// constructed as getters to avoid circular dependencies.\n\t\t\tconst thunkArgs = {\n\t\t\t\tregistry,\n\t\t\t\tget dispatch() {\n\t\t\t\t\treturn thunkDispatch;\n\t\t\t\t},\n\t\t\t\tget select() {\n\t\t\t\t\treturn thunkSelect;\n\t\t\t\t},\n\t\t\t\tget resolveSelect() {\n\t\t\t\t\treturn resolveSelectors;\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst store = instantiateReduxStore(\n\t\t\t\tkey,\n\t\t\t\toptions,\n\t\t\t\tregistry,\n\t\t\t\tthunkArgs\n\t\t\t);\n\n\t\t\t// Expose the private registration functions on the store\n\t\t\t// so they can be copied to a sub registry in registry.js.\n\t\t\tlock( store, privateRegistrationFunctions );\n\t\t\tconst resolversCache = createResolversCache();\n\n\t\t\t// Binds an action creator (`action`) to the `store`, making it a callable function.\n\t\t\t// These are the functions that are returned by `useDispatch`, for example.\n\t\t\t// It always returns a `Promise`, although actions are not always async. That's an\n\t\t\t// unfortunate backward compatibility measure.\n\t\t\tfunction bindAction( action ) {\n\t\t\t\treturn ( ...args ) =>\n\t\t\t\t\tPromise.resolve( store.dispatch( action( ...args ) ) );\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Object with all public actions, both metadata and store actions.\n\t\t\t */\n\t\t\tconst actions = {\n\t\t\t\t...mapValues( metadataActions, bindAction ),\n\t\t\t\t...mapValues( options.actions, bindAction ),\n\t\t\t};\n\n\t\t\t// Object with both public and private actions. Private actions are accessed through a proxy,\n\t\t\t// which looks them up in real time on the `privateActions` object. That's because private\n\t\t\t// actions can be registered at any time with `registerPrivateActions`. Also once a private\n\t\t\t// action creator is bound to the store, it is cached to give it a stable identity.\n\t\t\tconst allActions = createPrivateProxy(\n\t\t\t\tactions,\n\t\t\t\tcreateBindingCache(\n\t\t\t\t\t( name ) => privateActions[ name ],\n\t\t\t\t\tbindAction\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// An object that implements the `dispatch` object that is passed to thunk functions.\n\t\t\t// It is callable (`dispatch( action )`) and also has methods (`dispatch.foo()`) that\n\t\t\t// correspond to bound registered actions, both public and private. Implemented with the proxy\n\t\t\t// `get` method, delegating to `allActions`.\n\t\t\tconst thunkDispatch = new Proxy(\n\t\t\t\t( action ) => store.dispatch( action ),\n\t\t\t\t{ get: ( target, name ) => allActions[ name ] }\n\t\t\t);\n\n\t\t\t// To the public `actions` object, add the \"locked\" `allActions` object. When used,\n\t\t\t// `unlock( actions )` will return `allActions`, implementing a way how to get at the private actions.\n\t\t\tlock( actions, allActions );\n\n\t\t\t// If we have selector resolvers, convert them to a normalized form.\n\t\t\tconst resolvers = options.resolvers\n\t\t\t\t? mapValues( options.resolvers, mapResolver )\n\t\t\t\t: {};\n\n\t\t\t// Bind a selector to the store. Call the selector with the current state, correct registry,\n\t\t\t// and if there is a resolver, attach the resolver logic to the selector.\n\t\t\tfunction bindSelector( selector, selectorName ) {\n\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\tselector.registry = registry;\n\t\t\t\t}\n\t\t\t\tconst boundSelector = ( ...args ) => {\n\t\t\t\t\targs = normalize( selector, args );\n\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\t\t// Before calling the selector, switch to the correct registry.\n\t\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\t\tselector.registry = registry;\n\t\t\t\t\t}\n\t\t\t\t\treturn selector( state.root, ...args );\n\t\t\t\t};\n\n\t\t\t\t// Expose normalization method on the bound selector\n\t\t\t\t// in order that it can be called when fulfilling\n\t\t\t\t// the resolver.\n\t\t\t\tboundSelector.__unstableNormalizeArgs =\n\t\t\t\t\tselector.__unstableNormalizeArgs;\n\n\t\t\t\tconst resolver = resolvers[ selectorName ];\n\n\t\t\t\tif ( ! resolver ) {\n\t\t\t\t\tboundSelector.hasResolver = false;\n\t\t\t\t\treturn boundSelector;\n\t\t\t\t}\n\n\t\t\t\treturn mapSelectorWithResolver(\n\t\t\t\t\tboundSelector,\n\t\t\t\t\tselectorName,\n\t\t\t\t\tresolver,\n\t\t\t\t\tstore,\n\t\t\t\t\tresolversCache,\n\t\t\t\t\tboundMetadataSelectors\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Metadata selectors are bound differently: different state (`state.metadata`), no resolvers,\n\t\t\t// normalization depending on the target selector.\n\t\t\tfunction bindMetadataSelector( metaDataSelector ) {\n\t\t\t\tconst boundSelector = (\n\t\t\t\t\tselectorName,\n\t\t\t\t\tselectorArgs,\n\t\t\t\t\t...args\n\t\t\t\t) => {\n\t\t\t\t\t// Normalize the arguments passed to the target selector.\n\t\t\t\t\tif ( selectorName ) {\n\t\t\t\t\t\tconst targetSelector =\n\t\t\t\t\t\t\toptions.selectors?.[ selectorName ];\n\t\t\t\t\t\tif ( targetSelector ) {\n\t\t\t\t\t\t\tselectorArgs = normalize(\n\t\t\t\t\t\t\t\ttargetSelector,\n\t\t\t\t\t\t\t\tselectorArgs\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\n\t\t\t\t\treturn metaDataSelector(\n\t\t\t\t\t\tstate.metadata,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\tselectorArgs,\n\t\t\t\t\t\t...args\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\tboundSelector.hasResolver = false;\n\t\t\t\treturn boundSelector;\n\t\t\t}\n\n\t\t\t// Perform binding of both metadata and store selectors and combine them in one\n\t\t\t// `selectors` object. These are all public selectors of the store.\n\t\t\tconst boundMetadataSelectors = mapValues(\n\t\t\t\tmetadataSelectors,\n\t\t\t\tbindMetadataSelector\n\t\t\t);\n\n\t\t\tconst boundSelectors = mapValues( options.selectors, bindSelector );\n\n\t\t\tconst selectors = {\n\t\t\t\t...boundMetadataSelectors,\n\t\t\t\t...boundSelectors,\n\t\t\t};\n\n\t\t\t// Cache of bould private selectors. They are bound only when first accessed, because\n\t\t\t// new private selectors can be registered at any time (with `registerPrivateSelectors`).\n\t\t\t// Once bound, they are cached to give them a stable identity.\n\t\t\tconst boundPrivateSelectors = createBindingCache(\n\t\t\t\t( name ) => privateSelectors[ name ],\n\t\t\t\tbindSelector\n\t\t\t);\n\n\t\t\tconst allSelectors = createPrivateProxy(\n\t\t\t\tselectors,\n\t\t\t\tboundPrivateSelectors\n\t\t\t);\n\n\t\t\t// Pre-bind the private selectors that have been registered by the time of\n\t\t\t// instantiation, so that registry selectors are bound to the registry.\n\t\t\tfor ( const selectorName of Object.keys( privateSelectors ) ) {\n\t\t\t\tboundPrivateSelectors.get( selectorName );\n\t\t\t}\n\n\t\t\t// An object that implements the `select` object that is passed to thunk functions.\n\t\t\t// It is callable (`select( selector )`) and also has methods (`select.foo()`) that\n\t\t\t// correspond to bound registered selectors, both public and private. Implemented with the proxy\n\t\t\t// `get` method, delegating to `allSelectors`.\n\t\t\tconst thunkSelect = new Proxy(\n\t\t\t\t( selector ) => selector( store.__unstableOriginalGetState() ),\n\t\t\t\t{ get: ( target, name ) => allSelectors[ name ] }\n\t\t\t);\n\n\t\t\t// To the public `selectors` object, add the \"locked\" `allSelectors` object. When used,\n\t\t\t// `unlock( selectors )` will return `allSelectors`, implementing a way how to get at the private selectors.\n\t\t\tlock( selectors, allSelectors );\n\n\t\t\t// For each selector, create a function that calls the selector, waits for resolution and returns\n\t\t\t// a promise that resolves when the resolution is finished.\n\t\t\tconst bindResolveSelector = mapResolveSelector(\n\t\t\t\tstore,\n\t\t\t\tboundMetadataSelectors\n\t\t\t);\n\n\t\t\t// Now apply this function to all bound selectors, public and private. We are excluding\n\t\t\t// metadata selectors because they don't have resolvers.\n\t\t\tconst resolveSelectors = mapValues(\n\t\t\t\tboundSelectors,\n\t\t\t\tbindResolveSelector\n\t\t\t);\n\n\t\t\tconst allResolveSelectors = createPrivateProxy(\n\t\t\t\tresolveSelectors,\n\t\t\t\tcreateBindingCache(\n\t\t\t\t\t( name ) => boundPrivateSelectors.get( name ),\n\t\t\t\t\tbindResolveSelector\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// Lock the selectors so that `unlock( resolveSelectors )` returns `allResolveSelectors`.\n\t\t\tlock( resolveSelectors, allResolveSelectors );\n\n\t\t\t// Now, in a way very similar to `bindResolveSelector`, we create a function that maps\n\t\t\t// selectors to functions that throw a suspense promise if not yet resolved.\n\t\t\tconst bindSuspendSelector = mapSuspendSelector(\n\t\t\t\tstore,\n\t\t\t\tboundMetadataSelectors\n\t\t\t);\n\n\t\t\tconst suspendSelectors = {\n\t\t\t\t...boundMetadataSelectors, // no special suspense behavior\n\t\t\t\t...mapValues( boundSelectors, bindSuspendSelector ),\n\t\t\t};\n\n\t\t\tconst allSuspendSelectors = createPrivateProxy(\n\t\t\t\tsuspendSelectors,\n\t\t\t\tcreateBindingCache(\n\t\t\t\t\t( name ) => boundPrivateSelectors.get( name ),\n\t\t\t\t\tbindSuspendSelector\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// Lock the selectors so that `unlock( suspendSelectors )` returns 'allSuspendSelectors`.\n\t\t\tlock( suspendSelectors, allSuspendSelectors );\n\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\n\t\t\tconst getSuspendSelectors = () => suspendSelectors;\n\n\t\t\t// We have some modules monkey-patching the store object\n\t\t\t// It's wrong to do so but until we refactor all of our effects to controls\n\t\t\t// We need to keep the same \"store\" instance here.\n\t\t\tstore.__unstableOriginalGetState = store.getState;\n\t\t\tstore.getState = () => store.__unstableOriginalGetState().root;\n\n\t\t\t// Customize subscribe behavior to call listeners only on effective change,\n\t\t\t// not on every dispatch.\n\t\t\tconst subscribe =\n\t\t\t\tstore &&\n\t\t\t\t( ( listener ) => {\n\t\t\t\t\tlisteners.add( listener );\n\n\t\t\t\t\treturn () => listeners.delete( listener );\n\t\t\t\t} );\n\n\t\t\tlet lastState = store.__unstableOriginalGetState();\n\t\t\tstore.subscribe( () => {\n\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\tconst hasChanged = state !== lastState;\n\t\t\t\tlastState = state;\n\n\t\t\t\tif ( hasChanged ) {\n\t\t\t\t\tfor ( const listener of listeners ) {\n\t\t\t\t\t\tlistener();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\t// This can be simplified to just { subscribe, getSelectors, getActions }\n\t\t\t// Once we remove the use function.\n\t\t\treturn {\n\t\t\t\treducer,\n\t\t\t\tstore,\n\t\t\t\tactions,\n\t\t\t\tselectors,\n\t\t\t\tresolvers,\n\t\t\t\tgetSelectors,\n\t\t\t\tgetResolveSelectors,\n\t\t\t\tgetSuspendSelectors,\n\t\t\t\tgetActions,\n\t\t\t\tsubscribe,\n\t\t\t};\n\t\t},\n\t};\n\n\t// Expose the private registration functions on the store\n\t// descriptor. That's a natural choice since that's where the\n\t// public actions and selectors are stored.\n\tlock( storeDescriptor, privateRegistrationFunctions );\n\n\treturn storeDescriptor;\n}\n\n/**\n * Creates a redux store for a namespace.\n *\n * @param {string} key Unique namespace identifier.\n * @param {Object} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n * @param {DataRegistry} registry Registry reference.\n * @param {Object} thunkArgs Argument object for the thunk middleware.\n * @return {Object} Newly created redux store.\n */\nfunction instantiateReduxStore( key, options, registry, thunkArgs ) {\n\tconst controls = {\n\t\t...options.controls,\n\t\t...builtinControls,\n\t};\n\n\tconst normalizedControls = mapValues( controls, ( control ) =>\n\t\tcontrol.isRegistryControl ? control( registry ) : control\n\t);\n\n\tconst middlewares = [\n\t\tcreateResolversCacheMiddleware( registry, key ),\n\t\tpromise,\n\t\tcreateReduxRoutineMiddleware( normalizedControls ),\n\t\tcreateThunkMiddleware( thunkArgs ),\n\t];\n\n\tconst enhancers = [ applyMiddleware( ...middlewares ) ];\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__REDUX_DEVTOOLS_EXTENSION__\n\t) {\n\t\tenhancers.push(\n\t\t\twindow.__REDUX_DEVTOOLS_EXTENSION__( {\n\t\t\t\tname: key,\n\t\t\t\tinstanceId: key,\n\t\t\t\tserialize: {\n\t\t\t\t\treplacer: devToolsReplacer,\n\t\t\t\t},\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst { reducer, initialState } = options;\n\tconst enhancedReducer = combineReducers( {\n\t\tmetadata: metadataReducer,\n\t\troot: reducer,\n\t} );\n\n\treturn createStore(\n\t\tenhancedReducer,\n\t\t{ root: initialState },\n\t\tcompose( enhancers )\n\t);\n}\n\n/**\n * Maps selectors to functions that return a resolution promise for them.\n *\n * @param {Object} store The redux store the selectors are bound to.\n * @param {Object} boundMetadataSelectors The bound metadata selectors.\n *\n * @return {Function} Function that maps selectors to resolvers.\n */\nfunction mapResolveSelector( store, boundMetadataSelectors ) {\n\treturn ( selector, selectorName ) => {\n\t\t// If the selector doesn't have a resolver, just convert the return value\n\t\t// (including exceptions) to a Promise, no additional extra behavior is needed.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn async ( ...args ) => selector.apply( null, args );\n\t\t}\n\n\t\treturn ( ...args ) =>\n\t\t\tnew Promise( ( resolve, reject ) => {\n\t\t\t\tconst hasFinished = () => {\n\t\t\t\t\treturn boundMetadataSelectors.hasFinishedResolution(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\tconst finalize = ( result ) => {\n\t\t\t\t\tconst hasFailed =\n\t\t\t\t\t\tboundMetadataSelectors.hasResolutionFailed(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\tif ( hasFailed ) {\n\t\t\t\t\t\tconst error = boundMetadataSelectors.getResolutionError(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresolve( result );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst getResult = () => selector.apply( null, args );\n\n\t\t\t\t// Trigger the selector (to trigger the resolver)\n\t\t\t\tconst result = getResult();\n\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\treturn finalize( result );\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tfinalize( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t};\n}\n\n/**\n * Maps selectors to functions that throw a suspense promise if not yet resolved.\n *\n * @param {Object} store The redux store the selectors select from.\n * @param {Object} boundMetadataSelectors The bound metadata selectors.\n *\n * @return {Function} Function that maps selectors to their suspending versions.\n */\nfunction mapSuspendSelector( store, boundMetadataSelectors ) {\n\treturn ( selector, selectorName ) => {\n\t\t// Selector without a resolver doesn't have any extra suspense behavior.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn selector;\n\t\t}\n\n\t\treturn ( ...args ) => {\n\t\t\tconst result = selector.apply( null, args );\n\n\t\t\tif (\n\t\t\t\tboundMetadataSelectors.hasFinishedResolution(\n\t\t\t\t\tselectorName,\n\t\t\t\t\targs\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif (\n\t\t\t\t\tboundMetadataSelectors.hasResolutionFailed(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthrow boundMetadataSelectors.getResolutionError(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tthrow new Promise( ( resolve ) => {\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tboundMetadataSelectors.hasFinishedResolution(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t};\n}\n\n/**\n * Convert a resolver to a normalized form, an object with `fulfill` method and\n * optional methods like `isFulfilled`.\n *\n * @param {Function} resolver Resolver to convert\n */\nfunction mapResolver( resolver ) {\n\tif ( resolver.fulfill ) {\n\t\treturn resolver;\n\t}\n\n\treturn {\n\t\t...resolver, // Copy the enumerable properties of the resolver function.\n\t\tfulfill: resolver, // Add the fulfill method.\n\t};\n}\n\n/**\n * Returns a selector with a matched resolver.\n * Resolvers are side effects invoked once per argument set of a given selector call,\n * used in ensuring that the data needs for the selector are satisfied.\n *\n * @param {Object} selector The selector function to be bound.\n * @param {string} selectorName The selector name.\n * @param {Object} resolver Resolver to call.\n * @param {Object} store The redux store to which the resolvers should be mapped.\n * @param {Object} resolversCache Resolvers Cache.\n * @param {Object} boundMetadataSelectors The bound metadata selectors.\n */\nfunction mapSelectorWithResolver(\n\tselector,\n\tselectorName,\n\tresolver,\n\tstore,\n\tresolversCache,\n\tboundMetadataSelectors\n) {\n\tfunction fulfillSelector( args ) {\n\t\tif (\n\t\t\tresolversCache.isRunning( selectorName, args ) ||\n\t\t\tboundMetadataSelectors.hasStartedResolution( selectorName, args )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tresolversCache.markAsRunning( selectorName, args );\n\n\t\tsetTimeout( async () => {\n\t\t\tresolversCache.clear( selectorName, args );\n\t\t\tstore.dispatch(\n\t\t\t\tmetadataActions.startResolution( selectorName, args )\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tconst isFulfilled =\n\t\t\t\t\ttypeof resolver.isFulfilled === 'function' &&\n\t\t\t\t\tresolver.isFulfilled( store.getState(), ...args );\n\t\t\t\tif ( ! isFulfilled ) {\n\t\t\t\t\tconst action = resolver.fulfill( ...args );\n\t\t\t\t\tif ( action ) {\n\t\t\t\t\t\tawait store.dispatch( action );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstore.dispatch(\n\t\t\t\t\tmetadataActions.finishResolution( selectorName, args )\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tstore.dispatch(\n\t\t\t\t\tmetadataActions.failResolution( selectorName, args, error )\n\t\t\t\t);\n\t\t\t}\n\t\t}, 0 );\n\t}\n\n\tconst selectorResolver = ( ...args ) => {\n\t\targs = normalize( selector, args );\n\t\tfulfillSelector( args );\n\t\treturn selector( ...args );\n\t};\n\tselectorResolver.hasResolver = true;\n\treturn selectorResolver;\n}\n\n/**\n * Applies selector's normalization function to the given arguments\n * if it exists.\n *\n * @param {Object} selector The selector potentially with a normalization method property.\n * @param {Array} args selector arguments to normalize.\n * @return {Array} Potentially normalized arguments.\n */\nfunction normalize( selector, args ) {\n\tif (\n\t\tselector.__unstableNormalizeArgs &&\n\t\ttypeof selector.__unstableNormalizeArgs === 'function' &&\n\t\targs?.length\n\t) {\n\t\treturn selector.__unstableNormalizeArgs( args );\n\t}\n\treturn args;\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa,uBAAuB;
|
|
3
|
+
"sources": ["../../src/redux-store/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport type { Store as ReduxStore, StoreEnhancer } from 'redux';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport createReduxRoutineMiddleware from '@wordpress/redux-routine';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { combineReducers } from './combine-reducers';\nimport { builtinControls } from '../controls';\nimport { lock } from '../lock-unlock';\nimport promise from '../promise-middleware';\nimport createResolversCacheMiddleware from '../resolvers-cache-middleware';\nimport createThunkMiddleware from './thunk-middleware';\nimport metadataReducer from './metadata/reducer';\nimport * as metadataSelectors from './metadata/selectors';\nimport * as metadataActions from './metadata/actions';\nimport type {\n\tDataRegistry,\n\tListenerFunction,\n\tStoreDescriptor,\n\tReduxStoreConfig,\n\tActionCreator,\n\tNormalizedResolver,\n} from '../types';\n\nexport { combineReducers };\n\n/**\n * Augment the Redux store with internal properties used by the data module.\n */\ninterface AugmentedReduxStore extends ReduxStore {\n\t__unstableOriginalGetState: ReduxStore[ 'getState' ];\n}\n\ninterface ResolversCache {\n\tisRunning: ( selectorName: string, args: unknown[] ) => boolean;\n\tclear: ( selectorName: string, args: unknown[] ) => void;\n\tmarkAsRunning: ( selectorName: string, args: unknown[] ) => void;\n}\n\ninterface BindingCache {\n\tget: ( itemName: string ) => ( ( ...args: unknown[] ) => unknown ) | null;\n}\n\ninterface SelectorLike {\n\t( ...args: any[] ): any;\n\thasResolver?: boolean;\n\tisRegistrySelector?: boolean;\n\tregistry?: DataRegistry;\n\t__unstableNormalizeArgs?: ( args: unknown[] ) => unknown[];\n}\n\nconst trimUndefinedValues = ( array: unknown[] ): unknown[] => {\n\tconst result = [ ...array ];\n\tfor ( let i = result.length - 1; i >= 0; i-- ) {\n\t\tif ( result[ i ] === undefined ) {\n\t\t\tresult.splice( i, 1 );\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * Creates a new object with the same keys, but with `callback()` called as\n * a transformer function on each of the values.\n *\n * @param obj The object to transform.\n * @param callback The function to transform each object value.\n * @return Transformed object.\n */\nconst mapValues = < T, U >(\n\tobj: Record< string, T > | undefined,\n\tcallback: ( value: T, key: string ) => U\n): Record< string, U > =>\n\tObject.fromEntries(\n\t\tObject.entries( obj ?? {} ).map( ( [ key, value ] ) => [\n\t\t\tkey,\n\t\t\tcallback( value, key ),\n\t\t] )\n\t);\n\n// Convert non serializable types to plain objects\nconst devToolsReplacer = ( _key: string, state: unknown ): unknown => {\n\tif ( state instanceof Map ) {\n\t\treturn Object.fromEntries( state );\n\t}\n\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\tstate instanceof window.HTMLElement\n\t) {\n\t\treturn null;\n\t}\n\n\treturn state;\n};\n\n/**\n * Create a cache to track whether resolvers started running or not.\n *\n * @return Resolvers Cache.\n */\nfunction createResolversCache(): ResolversCache {\n\tconst cache: Record< string, EquivalentKeyMap< unknown[], boolean > > = {};\n\treturn {\n\t\tisRunning( selectorName: string, args: unknown[] ): boolean {\n\t\t\treturn !! (\n\t\t\t\tcache[ selectorName ] &&\n\t\t\t\tcache[ selectorName ].get( trimUndefinedValues( args ) )\n\t\t\t);\n\t\t},\n\n\t\tclear( selectorName: string, args: unknown[] ): void {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( trimUndefinedValues( args ) );\n\t\t\t}\n\t\t},\n\n\t\tmarkAsRunning( selectorName: string, args: unknown[] ): void {\n\t\t\tif ( ! cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ] = new EquivalentKeyMap();\n\t\t\t}\n\n\t\t\tcache[ selectorName ].set( trimUndefinedValues( args ), true );\n\t\t},\n\t};\n}\n\nfunction createBindingCache(\n\tgetItem: ( name: string ) => ( ( ...args: any[] ) => any ) | undefined,\n\tbindItem: (\n\t\titem: ( ...args: any[] ) => any,\n\t\tname: string\n\t) => ( ...args: unknown[] ) => unknown\n): BindingCache {\n\tconst cache = new WeakMap<\n\t\t( ...args: any[] ) => any,\n\t\t( ...args: unknown[] ) => unknown\n\t>();\n\n\treturn {\n\t\tget( itemName: string ) {\n\t\t\tconst item = getItem( itemName );\n\t\t\tif ( ! item ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tlet boundItem = cache.get( item );\n\t\t\tif ( ! boundItem ) {\n\t\t\t\tboundItem = bindItem( item, itemName );\n\t\t\t\tcache.set( item, boundItem );\n\t\t\t}\n\t\t\treturn boundItem;\n\t\t},\n\t};\n}\n\nfunction createPrivateProxy< T extends Record< string, any > >(\n\tpublicItems: T,\n\tprivateItems: BindingCache\n): T {\n\treturn new Proxy( publicItems, {\n\t\tget: ( target, itemName: string ) =>\n\t\t\tprivateItems.get( itemName ) || Reflect.get( target, itemName ),\n\t} );\n}\n\n/**\n * Creates a data store descriptor for the provided Redux store configuration containing\n * properties describing reducer, actions, selectors, controls and resolvers.\n *\n * @example\n * ```js\n * import { createReduxStore } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * ```\n *\n * @param key Unique namespace identifier.\n * @param options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return Store Object.\n */\nexport default function createReduxStore< State, Actions, Selectors >(\n\tkey: string,\n\toptions: ReduxStoreConfig< State, Actions, Selectors >\n): StoreDescriptor< ReduxStoreConfig< State, Actions, Selectors > > {\n\tconst privateActions: Record< string, ActionCreator > = {};\n\tconst privateSelectors: Record< string, SelectorLike > = {};\n\tconst privateRegistrationFunctions = {\n\t\tprivateActions,\n\t\tregisterPrivateActions: (\n\t\t\tactions: Record< string, ActionCreator >\n\t\t) => {\n\t\t\tObject.assign( privateActions, actions );\n\t\t},\n\t\tprivateSelectors,\n\t\tregisterPrivateSelectors: (\n\t\t\tselectors: Record< string, SelectorLike >\n\t\t) => {\n\t\t\tObject.assign( privateSelectors, selectors );\n\t\t},\n\t};\n\tconst storeDescriptor = {\n\t\tname: key,\n\t\tinstantiate: ( registry: DataRegistry ) => {\n\t\t\t/**\n\t\t\t * Stores listener functions registered with `subscribe()`.\n\t\t\t *\n\t\t\t * When functions register to listen to store changes with\n\t\t\t * `subscribe()` they get added here. Although Redux offers\n\t\t\t * its own `subscribe()` function directly, by wrapping the\n\t\t\t * subscription in this store instance it's possible to\n\t\t\t * optimize checking if the state has changed before calling\n\t\t\t * each listener.\n\t\t\t */\n\t\t\tconst listeners = new Set< ListenerFunction >();\n\t\t\tconst reducer = options.reducer;\n\n\t\t\t// Object that every thunk function receives as the first argument. It contains the\n\t\t\t// `registry`, `dispatch`, `select` and `resolveSelect` fields. Some of them are\n\t\t\t// constructed as getters to avoid circular dependencies.\n\t\t\tconst thunkArgs = {\n\t\t\t\tregistry,\n\t\t\t\tget dispatch() {\n\t\t\t\t\treturn thunkDispatch;\n\t\t\t\t},\n\t\t\t\tget select() {\n\t\t\t\t\treturn thunkSelect;\n\t\t\t\t},\n\t\t\t\tget resolveSelect() {\n\t\t\t\t\treturn resolveSelectors;\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst store = instantiateReduxStore(\n\t\t\t\tkey,\n\t\t\t\toptions,\n\t\t\t\tregistry,\n\t\t\t\tthunkArgs\n\t\t\t) as AugmentedReduxStore;\n\n\t\t\t// Expose the private registration functions on the store\n\t\t\t// so they can be copied to a sub registry in registry.js.\n\t\t\tlock( store, privateRegistrationFunctions );\n\t\t\tconst resolversCache = createResolversCache();\n\n\t\t\t// Binds an action creator (`action`) to the `store`, making it a callable function.\n\t\t\t// These are the functions that are returned by `useDispatch`, for example.\n\t\t\t// It always returns a `Promise`, although actions are not always async. That's an\n\t\t\t// unfortunate backward compatibility measure.\n\t\t\tfunction bindAction( action: ( ...args: any[] ) => any ) {\n\t\t\t\treturn ( ...args: unknown[] ) =>\n\t\t\t\t\tPromise.resolve( store.dispatch( action( ...args ) ) );\n\t\t\t}\n\n\t\t\t/*\n\t\t\t * Object with all public actions, both metadata and store actions.\n\t\t\t */\n\t\t\tconst actions = {\n\t\t\t\t...mapValues(\n\t\t\t\t\tmetadataActions as Record< string, ActionCreator >,\n\t\t\t\t\tbindAction\n\t\t\t\t),\n\t\t\t\t...mapValues(\n\t\t\t\t\toptions.actions as\n\t\t\t\t\t\t| Record< string, ActionCreator >\n\t\t\t\t\t\t| undefined,\n\t\t\t\t\tbindAction\n\t\t\t\t),\n\t\t\t};\n\n\t\t\t// Object with both public and private actions. Private actions are accessed through a proxy,\n\t\t\t// which looks them up in real time on the `privateActions` object. That's because private\n\t\t\t// actions can be registered at any time with `registerPrivateActions`. Also once a private\n\t\t\t// action creator is bound to the store, it is cached to give it a stable identity.\n\t\t\tconst allActions = createPrivateProxy(\n\t\t\t\tactions,\n\t\t\t\tcreateBindingCache(\n\t\t\t\t\t( name ) => privateActions[ name ],\n\t\t\t\t\tbindAction\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// An object that implements the `dispatch` object that is passed to thunk functions.\n\t\t\t// It is callable (`dispatch( action )`) and also has methods (`dispatch.foo()`) that\n\t\t\t// correspond to bound registered actions, both public and private. Implemented with the proxy\n\t\t\t// `get` method, delegating to `allActions`.\n\t\t\tconst thunkDispatch = new Proxy(\n\t\t\t\t( action: any ) => store.dispatch( action ),\n\t\t\t\t{\n\t\t\t\t\tget: ( _target, name: string ) => allActions[ name ],\n\t\t\t\t}\n\t\t\t);\n\n\t\t\t// To the public `actions` object, add the \"locked\" `allActions` object. When used,\n\t\t\t// `unlock( actions )` will return `allActions`, implementing a way how to get at the private actions.\n\t\t\tlock( actions, allActions );\n\n\t\t\t// If we have selector resolvers, convert them to a normalized form.\n\t\t\tconst resolvers: Record< string, NormalizedResolver > =\n\t\t\t\toptions.resolvers\n\t\t\t\t\t? mapValues(\n\t\t\t\t\t\t\toptions.resolvers as Record< string, any >,\n\t\t\t\t\t\t\tmapResolver\n\t\t\t\t\t )\n\t\t\t\t\t: {};\n\n\t\t\t// Bind a selector to the store. Call the selector with the current state, correct registry,\n\t\t\t// and if there is a resolver, attach the resolver logic to the selector.\n\t\t\tfunction bindSelector(\n\t\t\t\tselector: SelectorLike,\n\t\t\t\tselectorName: string\n\t\t\t): SelectorLike {\n\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\tselector.registry = registry;\n\t\t\t\t}\n\t\t\t\tconst boundSelector: SelectorLike = ( ...args: any[] ) => {\n\t\t\t\t\targs = normalize( selector, args );\n\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\t\t// Before calling the selector, switch to the correct registry.\n\t\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\t\tselector.registry = registry;\n\t\t\t\t\t}\n\t\t\t\t\treturn selector( state.root, ...args );\n\t\t\t\t};\n\n\t\t\t\t// Expose normalization method on the bound selector\n\t\t\t\t// in order that it can be called when fulfilling\n\t\t\t\t// the resolver.\n\t\t\t\tboundSelector.__unstableNormalizeArgs =\n\t\t\t\t\tselector.__unstableNormalizeArgs;\n\n\t\t\t\tconst resolver = resolvers[ selectorName ];\n\n\t\t\t\tif ( ! resolver ) {\n\t\t\t\t\tboundSelector.hasResolver = false;\n\t\t\t\t\treturn boundSelector;\n\t\t\t\t}\n\n\t\t\t\treturn mapSelectorWithResolver(\n\t\t\t\t\tboundSelector,\n\t\t\t\t\tselectorName,\n\t\t\t\t\tresolver,\n\t\t\t\t\tstore,\n\t\t\t\t\tresolversCache,\n\t\t\t\t\tboundMetadataSelectors\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Metadata selectors are bound differently: different state (`state.metadata`), no resolvers,\n\t\t\t// normalization depending on the target selector.\n\t\t\tfunction bindMetadataSelector(\n\t\t\t\tmetaDataSelector: ( ...args: any[] ) => any\n\t\t\t): SelectorLike {\n\t\t\t\tconst boundSelector: SelectorLike = (\n\t\t\t\t\tselectorName: string,\n\t\t\t\t\tselectorArgs: unknown[],\n\t\t\t\t\t...args: unknown[]\n\t\t\t\t) => {\n\t\t\t\t\t// Normalize the arguments passed to the target selector.\n\t\t\t\t\tif ( selectorName ) {\n\t\t\t\t\t\tconst targetSelector = ( options.selectors as any )?.[\n\t\t\t\t\t\t\tselectorName\n\t\t\t\t\t\t];\n\t\t\t\t\t\tif ( targetSelector ) {\n\t\t\t\t\t\t\tselectorArgs = normalize(\n\t\t\t\t\t\t\t\ttargetSelector,\n\t\t\t\t\t\t\t\tselectorArgs\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\n\t\t\t\t\treturn metaDataSelector(\n\t\t\t\t\t\tstate.metadata,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\tselectorArgs,\n\t\t\t\t\t\t...args\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\tboundSelector.hasResolver = false;\n\t\t\t\treturn boundSelector;\n\t\t\t}\n\n\t\t\t// Perform binding of both metadata and store selectors and combine them in one\n\t\t\t// `selectors` object. These are all public selectors of the store.\n\t\t\tconst boundMetadataSelectors = mapValues(\n\t\t\t\tmetadataSelectors as Record<\n\t\t\t\t\tstring,\n\t\t\t\t\t( ...args: any[] ) => any\n\t\t\t\t>,\n\t\t\t\tbindMetadataSelector\n\t\t\t);\n\n\t\t\tconst boundSelectors = mapValues(\n\t\t\t\toptions.selectors as Record< string, SelectorLike > | undefined,\n\t\t\t\tbindSelector\n\t\t\t);\n\n\t\t\tconst selectors = {\n\t\t\t\t...boundMetadataSelectors,\n\t\t\t\t...boundSelectors,\n\t\t\t};\n\n\t\t\t// Cache of bound private selectors. They are bound only when first accessed, because\n\t\t\t// new private selectors can be registered at any time (with `registerPrivateSelectors`).\n\t\t\t// Once bound, they are cached to give them a stable identity.\n\t\t\tconst boundPrivateSelectors = createBindingCache(\n\t\t\t\t( name ) => privateSelectors[ name ],\n\t\t\t\tbindSelector\n\t\t\t);\n\n\t\t\tconst allSelectors = createPrivateProxy(\n\t\t\t\tselectors,\n\t\t\t\tboundPrivateSelectors\n\t\t\t);\n\n\t\t\t// Pre-bind the private selectors that have been registered by the time of\n\t\t\t// instantiation, so that registry selectors are bound to the registry.\n\t\t\tfor ( const selectorName of Object.keys( privateSelectors ) ) {\n\t\t\t\tboundPrivateSelectors.get( selectorName );\n\t\t\t}\n\n\t\t\t// An object that implements the `select` object that is passed to thunk functions.\n\t\t\t// It is callable (`select( selector )`) and also has methods (`select.foo()`) that\n\t\t\t// correspond to bound registered selectors, both public and private. Implemented with the proxy\n\t\t\t// `get` method, delegating to `allSelectors`.\n\t\t\tconst thunkSelect = new Proxy(\n\t\t\t\t( selector: ( state: any ) => any ) =>\n\t\t\t\t\tselector( store.__unstableOriginalGetState() ),\n\t\t\t\t{\n\t\t\t\t\tget: ( _target, name: string ) => allSelectors[ name ],\n\t\t\t\t}\n\t\t\t);\n\n\t\t\t// To the public `selectors` object, add the \"locked\" `allSelectors` object. When used,\n\t\t\t// `unlock( selectors )` will return `allSelectors`, implementing a way how to get at the private selectors.\n\t\t\tlock( selectors, allSelectors );\n\n\t\t\t// For each selector, create a function that calls the selector, waits for resolution and returns\n\t\t\t// a promise that resolves when the resolution is finished.\n\t\t\tconst bindResolveSelector = mapResolveSelector(\n\t\t\t\tstore,\n\t\t\t\tboundMetadataSelectors\n\t\t\t);\n\n\t\t\t// Now apply this function to all bound selectors, public and private. We are excluding\n\t\t\t// metadata selectors because they don't have resolvers.\n\t\t\tconst resolveSelectors = mapValues(\n\t\t\t\tboundSelectors,\n\t\t\t\tbindResolveSelector\n\t\t\t);\n\n\t\t\tconst allResolveSelectors = createPrivateProxy(\n\t\t\t\tresolveSelectors,\n\t\t\t\tcreateBindingCache(\n\t\t\t\t\t( name ) =>\n\t\t\t\t\t\tboundPrivateSelectors.get( name ) as (\n\t\t\t\t\t\t\t...args: any[]\n\t\t\t\t\t\t) => any | undefined,\n\t\t\t\t\tbindResolveSelector\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// Lock the selectors so that `unlock( resolveSelectors )` returns `allResolveSelectors`.\n\t\t\tlock( resolveSelectors, allResolveSelectors );\n\n\t\t\t// Now, in a way very similar to `bindResolveSelector`, we create a function that maps\n\t\t\t// selectors to functions that throw a suspense promise if not yet resolved.\n\t\t\tconst bindSuspendSelector = mapSuspendSelector(\n\t\t\t\tstore,\n\t\t\t\tboundMetadataSelectors\n\t\t\t);\n\n\t\t\tconst suspendSelectors = {\n\t\t\t\t...boundMetadataSelectors, // no special suspense behavior\n\t\t\t\t...mapValues( boundSelectors, bindSuspendSelector ),\n\t\t\t};\n\n\t\t\tconst allSuspendSelectors = createPrivateProxy(\n\t\t\t\tsuspendSelectors,\n\t\t\t\tcreateBindingCache(\n\t\t\t\t\t( name ) =>\n\t\t\t\t\t\tboundPrivateSelectors.get( name ) as (\n\t\t\t\t\t\t\t...args: any[]\n\t\t\t\t\t\t) => any | undefined,\n\t\t\t\t\tbindSuspendSelector\n\t\t\t\t)\n\t\t\t);\n\n\t\t\t// Lock the selectors so that `unlock( suspendSelectors )` returns 'allSuspendSelectors`.\n\t\t\tlock( suspendSelectors, allSuspendSelectors );\n\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\n\t\t\tconst getSuspendSelectors = () => suspendSelectors;\n\n\t\t\t// We have some modules monkey-patching the store object\n\t\t\t// It's wrong to do so but until we refactor all of our effects to controls\n\t\t\t// We need to keep the same \"store\" instance here.\n\t\t\tstore.__unstableOriginalGetState = store.getState;\n\t\t\tstore.getState = () => store.__unstableOriginalGetState().root;\n\n\t\t\t// Customize subscribe behavior to call listeners only on effective change,\n\t\t\t// not on every dispatch.\n\t\t\tconst subscribe = ( listener: ListenerFunction ) => {\n\t\t\t\tlisteners.add( listener );\n\n\t\t\t\treturn () => listeners.delete( listener );\n\t\t\t};\n\n\t\t\tlet lastState = store.__unstableOriginalGetState();\n\t\t\tstore.subscribe( () => {\n\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\tconst hasChanged = state !== lastState;\n\t\t\t\tlastState = state;\n\n\t\t\t\tif ( hasChanged ) {\n\t\t\t\t\tfor ( const listener of listeners ) {\n\t\t\t\t\t\tlistener();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} );\n\n\t\t\t// This can be simplified to just { subscribe, getSelectors, getActions }\n\t\t\t// Once we remove the use function.\n\t\t\treturn {\n\t\t\t\treducer,\n\t\t\t\tstore,\n\t\t\t\tactions,\n\t\t\t\tselectors,\n\t\t\t\tresolvers,\n\t\t\t\tgetSelectors,\n\t\t\t\tgetResolveSelectors,\n\t\t\t\tgetSuspendSelectors,\n\t\t\t\tgetActions,\n\t\t\t\tsubscribe,\n\t\t\t};\n\t\t},\n\t};\n\n\t// Expose the private registration functions on the store\n\t// descriptor. That's a natural choice since that's where the\n\t// public actions and selectors are stored.\n\tlock( storeDescriptor, privateRegistrationFunctions );\n\n\treturn storeDescriptor as unknown as StoreDescriptor<\n\t\tReduxStoreConfig< State, Actions, Selectors >\n\t>;\n}\n\n/**\n * Creates a redux store for a namespace.\n *\n * @param key Unique namespace identifier.\n * @param options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n * @param registry Registry reference.\n * @param thunkArgs Argument object for the thunk middleware.\n * @return Newly created redux store.\n */\nfunction instantiateReduxStore(\n\tkey: string,\n\toptions: ReduxStoreConfig< any, any, any >,\n\tregistry: DataRegistry,\n\tthunkArgs: unknown\n): ReduxStore {\n\tconst controls = {\n\t\t...options.controls,\n\t\t...builtinControls,\n\t};\n\n\tconst normalizedControls = mapValues( controls, ( control: any ) =>\n\t\tcontrol.isRegistryControl ? control( registry ) : control\n\t);\n\n\tconst middlewares = [\n\t\tcreateResolversCacheMiddleware( registry, key ),\n\t\tpromise,\n\t\tcreateReduxRoutineMiddleware( normalizedControls ),\n\t\tcreateThunkMiddleware( thunkArgs ),\n\t];\n\n\tconst enhancers: StoreEnhancer[] = [ applyMiddleware( ...middlewares ) ];\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\t( window as any ).__REDUX_DEVTOOLS_EXTENSION__\n\t) {\n\t\tenhancers.push(\n\t\t\t( window as any ).__REDUX_DEVTOOLS_EXTENSION__( {\n\t\t\t\tname: key,\n\t\t\t\tinstanceId: key,\n\t\t\t\tserialize: {\n\t\t\t\t\treplacer: devToolsReplacer,\n\t\t\t\t},\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst { reducer, initialState } = options;\n\tconst enhancedReducer = combineReducers( {\n\t\tmetadata: metadataReducer,\n\t\troot: reducer,\n\t} );\n\n\treturn createStore(\n\t\tenhancedReducer,\n\t\t{ root: initialState } as any,\n\t\tcompose( ...enhancers ) as unknown as StoreEnhancer\n\t);\n}\n\n/**\n * Maps selectors to functions that return a resolution promise for them.\n *\n * @param store The redux store the selectors are bound to.\n * @param boundMetadataSelectors The bound metadata selectors.\n *\n * @return Function that maps selectors to resolvers.\n */\nfunction mapResolveSelector(\n\tstore: ReduxStore,\n\tboundMetadataSelectors: Record< string, SelectorLike >\n) {\n\treturn ( selector: SelectorLike, selectorName: string ) => {\n\t\t// If the selector doesn't have a resolver, just convert the return value\n\t\t// (including exceptions) to a Promise, no additional extra behavior is needed.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn async ( ...args: unknown[] ) => selector( ...args );\n\t\t}\n\n\t\treturn ( ...args: unknown[] ) =>\n\t\t\tnew Promise( ( resolve, reject ) => {\n\t\t\t\tconst hasFinished = () => {\n\t\t\t\t\treturn boundMetadataSelectors.hasFinishedResolution(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t\tconst finalize = ( result: unknown ) => {\n\t\t\t\t\tconst hasFailed =\n\t\t\t\t\t\tboundMetadataSelectors.hasResolutionFailed(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\tif ( hasFailed ) {\n\t\t\t\t\t\tconst error = boundMetadataSelectors.getResolutionError(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresolve( result );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst getResult = () => selector( ...args );\n\n\t\t\t\t// Trigger the selector (to trigger the resolver)\n\t\t\t\tconst result = getResult();\n\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\treturn finalize( result );\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tfinalize( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t};\n}\n\n/**\n * Maps selectors to functions that throw a suspense promise if not yet resolved.\n *\n * @param store The redux store the selectors select from.\n * @param boundMetadataSelectors The bound metadata selectors.\n *\n * @return Function that maps selectors to their suspending versions.\n */\nfunction mapSuspendSelector(\n\tstore: ReduxStore,\n\tboundMetadataSelectors: Record< string, SelectorLike >\n) {\n\treturn ( selector: SelectorLike, selectorName: string ) => {\n\t\t// Selector without a resolver doesn't have any extra suspense behavior.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn selector;\n\t\t}\n\n\t\treturn ( ...args: unknown[] ) => {\n\t\t\tconst result = selector( ...args );\n\n\t\t\tif (\n\t\t\t\tboundMetadataSelectors.hasFinishedResolution(\n\t\t\t\t\tselectorName,\n\t\t\t\t\targs\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tif (\n\t\t\t\t\tboundMetadataSelectors.hasResolutionFailed(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\tthrow boundMetadataSelectors.getResolutionError(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tthrow new Promise< void >( ( resolve ) => {\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tboundMetadataSelectors.hasFinishedResolution(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t)\n\t\t\t\t\t) {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t};\n}\n\n/**\n * Convert a resolver to a normalized form, an object with `fulfill` method and\n * optional methods like `isFulfilled`.\n *\n * @param resolver Resolver to convert\n */\nfunction mapResolver( resolver: any ): NormalizedResolver {\n\tif ( resolver.fulfill ) {\n\t\treturn resolver;\n\t}\n\n\treturn {\n\t\t...resolver, // Copy the enumerable properties of the resolver function.\n\t\tfulfill: resolver, // Add the fulfill method.\n\t};\n}\n\n/**\n * Returns a selector with a matched resolver.\n * Resolvers are side effects invoked once per argument set of a given selector call,\n * used in ensuring that the data needs for the selector are satisfied.\n *\n * @param selector The selector function to be bound.\n * @param selectorName The selector name.\n * @param resolver Resolver to call.\n * @param store The redux store to which the resolvers should be mapped.\n * @param resolversCache Resolvers Cache.\n * @param boundMetadataSelectors The bound metadata selectors.\n */\nfunction mapSelectorWithResolver(\n\tselector: SelectorLike,\n\tselectorName: string,\n\tresolver: NormalizedResolver,\n\tstore: AugmentedReduxStore,\n\tresolversCache: ResolversCache,\n\tboundMetadataSelectors: Record< string, SelectorLike >\n): SelectorLike {\n\tfunction fulfillSelector( args: unknown[] ): void {\n\t\tif (\n\t\t\tresolversCache.isRunning( selectorName, args ) ||\n\t\t\tboundMetadataSelectors.hasStartedResolution( selectorName, args )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tresolversCache.markAsRunning( selectorName, args );\n\n\t\tsetTimeout( async () => {\n\t\t\tresolversCache.clear( selectorName, args );\n\t\t\tstore.dispatch(\n\t\t\t\tmetadataActions.startResolution( selectorName, args )\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tconst isFulfilled =\n\t\t\t\t\ttypeof resolver.isFulfilled === 'function' &&\n\t\t\t\t\tresolver.isFulfilled( store.getState(), ...args );\n\t\t\t\tif ( ! isFulfilled ) {\n\t\t\t\t\tconst action = resolver.fulfill( ...args );\n\t\t\t\t\tif ( action ) {\n\t\t\t\t\t\tawait store.dispatch( action );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tstore.dispatch(\n\t\t\t\t\tmetadataActions.finishResolution( selectorName, args )\n\t\t\t\t);\n\t\t\t} catch ( error ) {\n\t\t\t\tstore.dispatch(\n\t\t\t\t\tmetadataActions.failResolution( selectorName, args, error )\n\t\t\t\t);\n\t\t\t}\n\t\t}, 0 );\n\t}\n\n\tconst selectorResolver: SelectorLike = ( ...args: unknown[] ) => {\n\t\targs = normalize( selector, args );\n\t\tfulfillSelector( args );\n\t\treturn selector( ...args );\n\t};\n\tselectorResolver.hasResolver = true;\n\treturn selectorResolver;\n}\n\n/**\n * Applies selector's normalization function to the given arguments\n * if it exists.\n *\n * @param selector The selector potentially with a normalization method property.\n * @param args selector arguments to normalize.\n * @return Potentially normalized arguments.\n */\nfunction normalize( selector: SelectorLike, args: unknown[] ): unknown[] {\n\tif (\n\t\tselector.__unstableNormalizeArgs &&\n\t\ttypeof selector.__unstableNormalizeArgs === 'function' &&\n\t\targs?.length\n\t) {\n\t\treturn selector.__unstableNormalizeArgs( args );\n\t}\n\treturn args;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa,uBAAuB;AAE7C,OAAO,sBAAsB;AAK7B,OAAO,kCAAkC;AACzC,SAAS,eAAe;AAKxB,SAAS,uBAAuB;AAChC,SAAS,uBAAuB;AAChC,SAAS,YAAY;AACrB,OAAO,aAAa;AACpB,OAAO,oCAAoC;AAC3C,OAAO,2BAA2B;AAClC,OAAO,qBAAqB;AAC5B,YAAY,uBAAuB;AACnC,YAAY,qBAAqB;AAqCjC,IAAM,sBAAsB,CAAE,UAAiC;AAC9D,QAAM,SAAS,CAAE,G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,MAAM,SAAU,MAAO;AAAA,UAC9B;AAAA,QACD;AACA,cAAM;AAAA,UACW,iCAAkB,cAAc,IAAK;AAAA,QACtD;AAAA,MACD,SAAU,OAAQ;AACjB,cAAM;AAAA,UACW,+BAAgB,cAAc,MAAM,KAAM;AAAA,QAC3D;AAAA,MACD;AAAA,IACD,GAAG,CAAE;AAAA,EACN;AAEA,QAAM,mBAAiC,IAAK,SAAqB;AAChE,WAAO,UAAW,UAAU,IAAK;AACjC,oBAAiB,IAAK;AACtB,WAAO,SAAU,GAAG,IAAK;AAAA,EAC1B;AACA,mBAAiB,cAAc;AAC/B,SAAO;AACR;AAUA,SAAS,UAAW,UAAwB,MAA6B;AACxE,MACC,SAAS,2BACT,OAAO,SAAS,4BAA4B,cAC5C,MAAM,QACL;AACD,WAAO,SAAS,wBAAyB,IAAK;AAAA,EAC/C;AACA,SAAO;AACR;",
|
|
6
6
|
"names": ["result"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/data/src/redux-store/metadata/selectors.
|
|
1
|
+
// packages/data/src/redux-store/metadata/selectors.ts
|
|
2
2
|
import deprecated from "@wordpress/deprecated";
|
|
3
3
|
import { createSelector } from "../../create-selector.mjs";
|
|
4
4
|
import { selectorArgsToStateKey } from "./utils.mjs";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/redux-store/metadata/selectors.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createSelector } from '../../create-selector';\nimport { selectorArgsToStateKey } from './utils';\
|
|
5
|
-
"mappings": ";AAGA,OAAO,gBAAgB;AAKvB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;
|
|
3
|
+
"sources": ["../../../src/redux-store/metadata/selectors.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createSelector } from '../../create-selector';\nimport { selectorArgsToStateKey } from './utils';\nimport type { State, StateValue } from './reducer';\n\n/**\n * Returns the raw resolution state value for a given selector name,\n * and arguments set. May be undefined if the selector has never been resolved\n * or not resolved for the given set of arguments, otherwise true or false for\n * resolution started and completed respectively.\n *\n * @param state Data state.\n * @param selectorName Selector name.\n * @param args Arguments passed to selector.\n *\n * @return isResolving value.\n */\nexport function getResolutionState(\n\tstate: Record< string, State >,\n\tselectorName: string,\n\targs?: unknown[] | null\n): StateValue | undefined {\n\tconst map = state[ selectorName ];\n\tif ( ! map ) {\n\t\treturn;\n\t}\n\n\treturn map.get( selectorArgsToStateKey( args ) );\n}\n\n/**\n * Returns an `isResolving`-like value for a given selector name and arguments set.\n * Its value is either `undefined` if the selector has never been resolved or has been\n * invalidated, or a `true`/`false` boolean value if the resolution is in progress or\n * has finished, respectively.\n *\n * This is a legacy selector that was implemented when the \"raw\" internal data had\n * this `undefined | boolean` format. Nowadays the internal value is an object that\n * can be retrieved with `getResolutionState`.\n *\n * @deprecated\n *\n * @param state Data state.\n * @param selectorName Selector name.\n * @param args Arguments passed to selector.\n *\n * @return isResolving value.\n */\nexport function getIsResolving(\n\tstate: Record< string, State >,\n\tselectorName: string,\n\targs?: unknown[] | null\n): boolean | undefined {\n\tdeprecated( 'wp.data.select( store ).getIsResolving', {\n\t\tsince: '6.6',\n\t\tversion: '6.8',\n\t\talternative: 'wp.data.select( store ).getResolutionState',\n\t} );\n\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\treturn resolutionState && resolutionState.status === 'resolving';\n}\n\n/**\n * Returns true if resolution has already been triggered for a given\n * selector name, and arguments set.\n *\n * @param state Data state.\n * @param selectorName Selector name.\n * @param args Arguments passed to selector.\n *\n * @return Whether resolution has been triggered.\n */\nexport function hasStartedResolution(\n\tstate: Record< string, State >,\n\tselectorName: string,\n\targs?: unknown[] | null\n): boolean {\n\treturn getResolutionState( state, selectorName, args ) !== undefined;\n}\n\n/**\n * Returns true if resolution has completed for a given selector\n * name, and arguments set.\n *\n * @param state Data state.\n * @param selectorName Selector name.\n * @param args Arguments passed to selector.\n *\n * @return Whether resolution has completed.\n */\nexport function hasFinishedResolution(\n\tstate: Record< string, State >,\n\tselectorName: string,\n\targs?: unknown[] | null\n): boolean {\n\tconst status = getResolutionState( state, selectorName, args )?.status;\n\treturn status === 'finished' || status === 'error';\n}\n\n/**\n * Returns true if resolution has failed for a given selector\n * name, and arguments set.\n *\n * @param state Data state.\n * @param selectorName Selector name.\n * @param args Arguments passed to selector.\n *\n * @return Has resolution failed\n */\nexport function hasResolutionFailed(\n\tstate: Record< string, State >,\n\tselectorName: string,\n\targs?: unknown[] | null\n): boolean {\n\treturn getResolutionState( state, selectorName, args )?.status === 'error';\n}\n\n/**\n * Returns the resolution error for a given selector name, and arguments set.\n * Note it may be of an Error type, but may also be null, undefined, or anything else\n * that can be `throw`-n.\n *\n * @param state Data state.\n * @param selectorName Selector name.\n * @param args Arguments passed to selector.\n *\n * @return Last resolution error\n */\nexport function getResolutionError(\n\tstate: Record< string, State >,\n\tselectorName: string,\n\targs?: unknown[] | null\n): Error | unknown {\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\treturn resolutionState?.status === 'error' ? resolutionState.error : null;\n}\n\n/**\n * Returns true if resolution has been triggered but has not yet completed for\n * a given selector name, and arguments set.\n *\n * @param state Data state.\n * @param selectorName Selector name.\n * @param args Arguments passed to selector.\n *\n * @return Whether resolution is in progress.\n */\nexport function isResolving(\n\tstate: Record< string, State >,\n\tselectorName: string,\n\targs?: unknown[] | null\n): boolean {\n\treturn (\n\t\tgetResolutionState( state, selectorName, args )?.status === 'resolving'\n\t);\n}\n\n/**\n * Returns the list of the cached resolvers.\n *\n * @param state Data state.\n *\n * @return Resolvers mapped by args and selectorName.\n */\nexport function getCachedResolvers(\n\tstate: Record< string, State >\n): Record< string, State > {\n\treturn state;\n}\n\n/**\n * Whether the store has any currently resolving selectors.\n *\n * @param state Data state.\n *\n * @return True if one or more selectors are resolving, false otherwise.\n */\nexport function hasResolvingSelectors(\n\tstate: Record< string, State >\n): boolean {\n\treturn Object.values( state ).some( ( selectorState ) =>\n\t\t/**\n\t\t * This uses the internal `_map` property of `EquivalentKeyMap` for\n\t\t * optimization purposes, since the `EquivalentKeyMap` implementation\n\t\t * does not support a `.values()` implementation.\n\t\t *\n\t\t * @see https://github.com/aduth/equivalent-key-map\n\t\t */\n\t\tArray.from( ( selectorState as any )._map.values() ).some(\n\t\t\t( resolution: any ) => resolution[ 1 ]?.status === 'resolving'\n\t\t)\n\t);\n}\n\n/**\n * Retrieves the total number of selectors, grouped per status.\n *\n * @param state Data state.\n *\n * @return Object, containing selector totals by status.\n */\nexport const countSelectorsByStatus = createSelector(\n\t( state: Record< string, State > ): Record< string, number > => {\n\t\tconst selectorsByStatus: Record< string, number > = {};\n\n\t\tObject.values( state ).forEach( ( selectorState ) =>\n\t\t\t/**\n\t\t\t * This uses the internal `_map` property of `EquivalentKeyMap` for\n\t\t\t * optimization purposes, since the `EquivalentKeyMap` implementation\n\t\t\t * does not support a `.values()` implementation.\n\t\t\t *\n\t\t\t * @see https://github.com/aduth/equivalent-key-map\n\t\t\t */\n\t\t\tArray.from( ( selectorState as any )._map.values() ).forEach(\n\t\t\t\t( resolution: any ) => {\n\t\t\t\t\tconst currentStatus = resolution[ 1 ]?.status ?? 'error';\n\t\t\t\t\tif ( ! selectorsByStatus[ currentStatus ] ) {\n\t\t\t\t\t\tselectorsByStatus[ currentStatus ] = 0;\n\t\t\t\t\t}\n\t\t\t\t\tselectorsByStatus[ currentStatus ]++;\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\n\t\treturn selectorsByStatus;\n\t},\n\t( state: Record< string, State > ) => [ state ]\n);\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,gBAAgB;AAKvB,SAAS,sBAAsB;AAC/B,SAAS,8BAA8B;AAehC,SAAS,mBACf,OAC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ErD,WAAO,OAAQ,KAAM,EAAE;AAAA,MAAS,CAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAQjC,MAAM,KAAQ,cAAuB,KAAK,OAAO,CAAE,EAAE;AAAA,UACpD,CAAE,eAAqB;AACtB,kBAAM,gBAAgB,WAAY,CAAE,GAAG,UAAU;AACjD,gBAAK,CAAE,kBAAmB,aAAc,GAAI;AAC3C,gCAAmB,aAAc,IAAI;AAAA,YACtC;AACA,8BAAmB,aAAc;AAAA,UAClC;AAAA,QACD;AAAA;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EACA,CAAE,UAAoC,CAAE,KAAM;AAC/C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/data/src/registry.
|
|
1
|
+
// packages/data/src/registry.ts
|
|
2
2
|
import deprecated from "@wordpress/deprecated";
|
|
3
3
|
import createReduxStore from "./redux-store/index.mjs";
|
|
4
4
|
import coreDataStore from "./store/index.mjs";
|
|
@@ -80,19 +80,19 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
80
80
|
}
|
|
81
81
|
return [
|
|
82
82
|
key,
|
|
83
|
-
|
|
84
|
-
return registry[key]
|
|
83
|
+
(...args) => {
|
|
84
|
+
return registry[key](...args);
|
|
85
85
|
}
|
|
86
86
|
];
|
|
87
87
|
})
|
|
88
88
|
);
|
|
89
89
|
}
|
|
90
|
-
function registerStoreInstance(name,
|
|
90
|
+
function registerStoreInstance(name, createStoreFunc) {
|
|
91
91
|
if (stores[name]) {
|
|
92
92
|
console.error('Store "' + name + '" is already registered.');
|
|
93
93
|
return stores[name];
|
|
94
94
|
}
|
|
95
|
-
const store =
|
|
95
|
+
const store = createStoreFunc();
|
|
96
96
|
if (typeof store.getSelectors !== "function") {
|
|
97
97
|
throw new TypeError("store.getSelectors must be a function");
|
|
98
98
|
}
|
|
@@ -152,7 +152,9 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
152
152
|
}
|
|
153
153
|
const store = registerStoreInstance(
|
|
154
154
|
storeName,
|
|
155
|
-
() => createReduxStore(storeName, options).instantiate(
|
|
155
|
+
() => createReduxStore(storeName, options).instantiate(
|
|
156
|
+
registry
|
|
157
|
+
)
|
|
156
158
|
);
|
|
157
159
|
return store.store;
|
|
158
160
|
}
|
|
@@ -205,7 +207,9 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
205
207
|
if (parent) {
|
|
206
208
|
parent.subscribe(globalListener);
|
|
207
209
|
}
|
|
208
|
-
const registryWithPlugins = withPlugins(
|
|
210
|
+
const registryWithPlugins = withPlugins(
|
|
211
|
+
registry
|
|
212
|
+
);
|
|
209
213
|
lock(registryWithPlugins, {
|
|
210
214
|
privateActionsOf: (name) => {
|
|
211
215
|
try {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/registry.
|
|
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';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\nfunction getStoreName( storeNameOrDescriptor ) {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {?Object} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores = 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 {Function} listener Listener function.\n\t * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener, storeNameOrDescriptor ) => {\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 {string|StoreDescriptor} 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 ) {\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( callback, ref ) {\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 {StoreDescriptor|string} 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} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( 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 {StoreDescriptor|string} 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} Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( 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 {string|StoreDescriptor} 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 ) {\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( attributes ) {\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\tfunction () {\n\t\t\t\t\t\treturn registry[ key ].apply( null, arguments );\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 {string} name Store registry name.\n\t * @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, createStore ) {\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 = createStore();\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 ) => {\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 {StoreDescriptor} store Store descriptor.\n\t */\n\tfunction register( store ) {\n\t\tregisterStoreInstance( store.name, () =>\n\t\t\tstore.instantiate( registry )\n\t\t);\n\t}\n\n\tfunction registerGenericStore( name, store ) {\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 {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tfunction registerStore( storeName, options ) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance( storeName, () =>\n\t\t\tcreateReduxStore( storeName, options ).instantiate( registry )\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback ) {\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 = {\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};\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, options ) {\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( registry );\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name ) => {\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 ) => {\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;\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,OAAO,gBAAgB;AAKvB,OAAO,sBAAsB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,MAAM,cAAc;
|
|
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,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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AkB,CAAE,SAAkB;AACrC,UAAI;AACH,eAAO,OAAQ,OAAQ,IAAK,EAAE,KAAM,EAAE;AAAA,MACvC,SAAU,GAAI;AAGb,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,IACA,oBAAoB,CAAE,SAAkB;AACvC,UAAI;AACH,eAAO,OAAQ,OAAQ,IAAK,EAAE,KAAM,EAAE;AAAA,MACvC,SAAU,GAAI;AACb,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
// packages/data/src/resolvers-cache-middleware.
|
|
1
|
+
// packages/data/src/resolvers-cache-middleware.ts
|
|
2
2
|
var createResolversCacheMiddleware = (registry, storeName) => () => (next) => (action) => {
|
|
3
3
|
const resolvers = registry.select(storeName).getCachedResolvers();
|
|
4
|
-
const resolverEntries = Object.entries(
|
|
4
|
+
const resolverEntries = Object.entries(
|
|
5
|
+
resolvers
|
|
6
|
+
);
|
|
5
7
|
resolverEntries.forEach(([selectorName, resolversByArgs]) => {
|
|
6
8
|
const resolver = registry.stores[storeName]?.resolvers?.[selectorName];
|
|
7
9
|
if (!resolver || !resolver.shouldInvalidate) {
|
|
8
10
|
return;
|
|
9
11
|
}
|
|
12
|
+
const { shouldInvalidate } = resolver;
|
|
10
13
|
resolversByArgs.forEach((value, args) => {
|
|
11
14
|
if (value === void 0) {
|
|
12
15
|
return;
|
|
@@ -14,7 +17,7 @@ var createResolversCacheMiddleware = (registry, storeName) => () => (next) => (a
|
|
|
14
17
|
if (value.status !== "finished" && value.status !== "error") {
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
17
|
-
if (!
|
|
20
|
+
if (!shouldInvalidate(action, ...args)) {
|
|
18
21
|
return;
|
|
19
22
|
}
|
|
20
23
|
registry.dispatch(storeName).invalidateResolution(selectorName, args);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/resolvers-cache-middleware.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../src/resolvers-cache-middleware.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { Middleware } from 'redux';\n\n/**\n * Internal dependencies\n */\nimport type { DataRegistry } from './types';\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param registry Registry for which to create the middleware.\n * @param storeName Name of the store for which to create the middleware.\n *\n * @return Middleware function.\n */\nconst createResolversCacheMiddleware =\n\t( registry: DataRegistry, storeName: string ): Middleware =>\n\t() =>\n\t( next ) =>\n\t( action ) => {\n\t\tconst resolvers = registry.select( storeName ).getCachedResolvers();\n\t\tconst resolverEntries =\n\t\t\tObject.entries< Map< string, { status: 'finished' | 'error' } > >(\n\t\t\t\tresolvers\n\t\t\t);\n\t\tresolverEntries.forEach( ( [ selectorName, resolversByArgs ] ) => {\n\t\t\tconst resolver =\n\t\t\t\tregistry.stores[ storeName ]?.resolvers?.[ selectorName ];\n\t\t\tif ( ! resolver || ! resolver.shouldInvalidate ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst { shouldInvalidate } = resolver;\n\t\t\tresolversByArgs.forEach( ( value, args ) => {\n\t\t\t\t// Works around a bug in `EquivalentKeyMap` where `map.delete` merely sets an entry value\n\t\t\t\t// to `undefined` and `map.forEach` then iterates also over these orphaned entries.\n\t\t\t\tif ( value === undefined ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.\n\t\t\t\t// If the value is \"finished\" or \"error\" it means this resolver has finished its resolution which means we need\n\t\t\t\t// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\tif ( value.status !== 'finished' && value.status !== 'error' ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( ! shouldInvalidate( action, ...args ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Trigger cache invalidation\n\t\t\t\tregistry\n\t\t\t\t\t.dispatch( storeName )\n\t\t\t\t\t.invalidateResolution( selectorName, args );\n\t\t\t} );\n\t\t} );\n\t\treturn next( action );\n\t};\n\nexport default createResolversCacheMiddleware;\n"],
|
|
5
|
+
"mappings": ";AAkBA,IAAM,iCACL,CAAE,UAAwB,cAC1B,MACA,CAAE,SACF,CAAE,WAAY;AACb,QAAM,YAAY,SAAS,OAAQ,SAAU,EAAE,mBAAmB;AAClE,QAAM,kBACL,OAAO;AAAA,IACN;AAAA,EACD;AACD,kBAAgB,QAAS,CAAE,CAAE,cAAc,eAAgB,MAAO;AACjE,UAAM,WACL,SAAS,OAAQ,SAAU,GAAG,YAAa,YAAa;AACzD,QAAK,CAAE,YAAY,CAAE,SAAS,kBAAmB;AAChD;AAAA,IACD;AACA,UAAM,EAAE,iBAAiB,IAAI;AAC7B,oBAAgB,QAAS,CAAE,OAAO,SAAU;AAG3C,UAAK,UAAU,QAAY;AAC1B;AAAA,MACD;AAKA,UAAK,MAAM,WAAW,cAAc,MAAM,WAAW,SAAU;AAC9D;AAAA,MACD;AAEA,UAAK,CAAE,iBAAkB,QAAQ,GAAG,IAAK,GAAI;AAC5C;AAAA,MACD;AAGA,eACE,SAAU,SAAU,EACpB,qBAAsB,cAAc,IAAK;AAAA,IAC5C,CAAE;AAAA,EACH,CAAE;AACF,SAAO,KAAM,MAAO;AACrB;AAED,IAAO,qCAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/select.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// packages/data/src/select.ts
|
|
2
2
|
import defaultRegistry from "./default-registry.mjs";
|
|
3
3
|
function select(storeNameOrDescriptor) {
|
|
4
|
-
return defaultRegistry.select(
|
|
4
|
+
return defaultRegistry.select(
|
|
5
|
+
storeNameOrDescriptor
|
|
6
|
+
);
|
|
5
7
|
}
|
|
6
8
|
export {
|
|
7
9
|
select
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/select.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, CurriedSelectorsOf, StoreDescriptor } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention\n * of passing the store name is also supported.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * select( myCustomStore ).getPrice( 'hammer' );\n * ```\n *\n * @return Object containing the store's selectors.\n */\nexport function select< T extends StoreDescriptor< AnyConfig > >(\n\tstoreNameOrDescriptor: string | T\n): CurriedSelectorsOf< T > {\n\treturn defaultRegistry.select(
|
|
5
|
-
"mappings": ";AAIA,OAAO,qBAAqB;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, CurriedSelectorsOf, StoreDescriptor } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n * Warning: This global `select` function only works with the default registry.\n * It will not work with custom `RegistryProvider` or `BlockEditorProvider` contexts.\n * In React components, prefer the `useSelect` hook instead, which is registry-aware.\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention\n * of passing the store name is also supported.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * select( myCustomStore ).getPrice( 'hammer' );\n * ```\n *\n * @return Object containing the store's selectors.\n */\nexport function select< T extends StoreDescriptor< AnyConfig > >(\n\tstoreNameOrDescriptor: string | T\n): CurriedSelectorsOf< T > {\n\treturn defaultRegistry.select(\n\t\tstoreNameOrDescriptor\n\t) as CurriedSelectorsOf< T >;\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO,qBAAqB;AAwBrB,SAAS,OACf,uBAC0B;AAC1B,SAAO,gBAAgB;AAAA,IACtB;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/store/index.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../../src/store/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { DataRegistry, StoreDescriptor, AnyConfig } from '../types';\n\nconst coreDataStore: StoreDescriptor< AnyConfig > = {\n\tname: 'core/data',\n\tinstantiate( registry: DataRegistry ) {\n\t\tconst getCoreDataSelector =\n\t\t\t( selectorName: string ) =>\n\t\t\t( key: string, ...args: unknown[] ) => {\n\t\t\t\treturn registry.select( key )[ selectorName ]( ...args );\n\t\t\t};\n\n\t\tconst getCoreDataAction =\n\t\t\t( actionName: string ) =>\n\t\t\t( key: string, ...args: unknown[] ) => {\n\t\t\t\treturn registry.dispatch( key )[ actionName ]( ...args );\n\t\t\t};\n\n\t\treturn {\n\t\t\tgetSelectors(): Record< string, ( ...args: any[] ) => any > {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'getIsResolving',\n\t\t\t\t\t\t'hasStartedResolution',\n\t\t\t\t\t\t'hasFinishedResolution',\n\t\t\t\t\t\t'isResolving',\n\t\t\t\t\t\t'getCachedResolvers',\n\t\t\t\t\t].map( ( selectorName ) => [\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\tgetCoreDataSelector( selectorName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tgetActions(): Record< string, ( ...args: any[] ) => any > {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'startResolution',\n\t\t\t\t\t\t'finishResolution',\n\t\t\t\t\t\t'invalidateResolution',\n\t\t\t\t\t\t'invalidateResolutionForStore',\n\t\t\t\t\t\t'invalidateResolutionForStoreSelector',\n\t\t\t\t\t].map( ( actionName ) => [\n\t\t\t\t\t\tactionName,\n\t\t\t\t\t\tgetCoreDataAction( actionName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tsubscribe() {\n\t\t\t\t// There's no reasons to trigger any listener when we subscribe to this store\n\t\t\t\t// because there's no state stored in this store that need to retrigger selectors\n\t\t\t\t// if a change happens, the corresponding store where the tracking stated live\n\t\t\t\t// would have already triggered a \"subscribe\" call.\n\t\t\t\treturn () => () => {};\n\t\t\t},\n\t\t};\n\t},\n};\n\nexport default coreDataStore;\n"],
|
|
5
|
+
"mappings": ";AAKA,IAAM,gBAA8C;AAAA,EACnD,MAAM;AAAA,EACN,YAAa,UAAyB;AACrC,UAAM,sBACL,CAAE,iBACF,CAAE,QAAgB,SAAqB;AACtC,aAAO,SAAS,OAAQ,GAAI,EAAG,YAAa,EAAG,GAAG,IAAK;AAAA,IACxD;AAED,UAAM,oBACL,CAAE,eACF,CAAE,QAAgB,SAAqB;AACtC,aAAO,SAAS,SAAU,GAAI,EAAG,UAAW,EAAG,GAAG,IAAK;AAAA,IACxD;AAED,WAAO;AAAA,MACN,eAA4D;AAC3D,eAAO,OAAO;AAAA,UACb;AAAA,YACC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACD,EAAE,IAAK,CAAE,iBAAkB;AAAA,YAC1B;AAAA,YACA,oBAAqB,YAAa;AAAA,UACnC,CAAE;AAAA,QACH;AAAA,MACD;AAAA,MAEA,aAA0D;AACzD,eAAO,OAAO;AAAA,UACb;AAAA,YACC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACD,EAAE,IAAK,CAAE,eAAgB;AAAA,YACxB;AAAA,YACA,kBAAmB,UAAW;AAAA,UAC/B,CAAE;AAAA,QACH;AAAA,MACD;AAAA,MAEA,YAAY;AAKX,eAAO,MAAM,MAAM;AAAA,QAAC;AAAA,MACrB;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAO,gBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
export const Context: import("react").Context<boolean>;
|
|
2
|
-
export const AsyncModeConsumer: import("react").Consumer<boolean>;
|
|
3
|
-
export default Provider;
|
|
1
|
+
export declare const Context: import("react").Context<boolean>;
|
|
4
2
|
declare const Provider: import("react").Provider<boolean>;
|
|
3
|
+
export declare const AsyncModeConsumer: import("react").Consumer<boolean>;
|
|
4
|
+
/**
|
|
5
|
+
* Context Provider Component used to switch the data module component rerendering
|
|
6
|
+
* between Sync and Async modes.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```js
|
|
11
|
+
* import { useSelect, AsyncModeProvider } from '@wordpress/data';
|
|
12
|
+
* import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
13
|
+
*
|
|
14
|
+
* function BlockCount() {
|
|
15
|
+
* const count = useSelect( ( select ) => {
|
|
16
|
+
* return select( blockEditorStore ).getBlockCount()
|
|
17
|
+
* }, [] );
|
|
18
|
+
*
|
|
19
|
+
* return count;
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* function App() {
|
|
23
|
+
* return (
|
|
24
|
+
* <AsyncModeProvider value={ true }>
|
|
25
|
+
* <BlockCount />
|
|
26
|
+
* </AsyncModeProvider>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* In this example, the BlockCount component is rerendered asynchronously.
|
|
32
|
+
* It means if a more critical task is being performed (like typing in an input),
|
|
33
|
+
* the rerendering is delayed until the browser becomes IDLE.
|
|
34
|
+
* It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior.
|
|
35
|
+
*
|
|
36
|
+
* @param {boolean} props.value Enable Async Mode.
|
|
37
|
+
*/
|
|
38
|
+
export default Provider;
|
|
5
39
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/components/async-mode-provider/context.
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/components/async-mode-provider/context.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,OAAO,kCAAyB,CAAC;AAG9C,QAAA,MAAkB,QAAQ,mCAAY,CAAC;AAEvC,eAAO,MAAM,iBAAiB,mCAAW,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAe,QAAQ,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { default as useAsyncMode } from
|
|
2
|
-
export { default as AsyncModeProvider, AsyncModeConsumer } from
|
|
1
|
+
export { default as useAsyncMode } from './use-async-mode';
|
|
2
|
+
export { default as AsyncModeProvider, AsyncModeConsumer } from './context';
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/async-mode-provider/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/async-mode-provider/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-async-mode.d.ts","sourceRoot":"","sources":["../../../src/components/async-mode-provider/use-async-mode.
|
|
1
|
+
{"version":3,"file":"use-async-mode.d.ts","sourceRoot":"","sources":["../../../src/components/async-mode-provider/use-async-mode.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,OAAO,UAAU,YAAY,IAAI,OAAO,CAE9C"}
|