@wordpress/data 10.32.0 → 10.32.1-next.b8c8708f3.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/build/components/async-mode-provider/context.js +35 -54
- package/build/components/async-mode-provider/context.js.map +7 -1
- package/build/components/async-mode-provider/index.js +40 -25
- package/build/components/async-mode-provider/index.js.map +7 -1
- package/build/components/async-mode-provider/use-async-mode.js +25 -16
- package/build/components/async-mode-provider/use-async-mode.js.map +7 -1
- package/build/components/registry-provider/context.js +46 -64
- package/build/components/registry-provider/context.js.map +7 -1
- package/build/components/registry-provider/index.js +40 -25
- package/build/components/registry-provider/index.js.map +7 -1
- package/build/components/registry-provider/use-registry.js +25 -55
- package/build/components/registry-provider/use-registry.js.map +7 -1
- package/build/components/use-dispatch/index.js +38 -17
- package/build/components/use-dispatch/index.js.map +7 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +59 -44
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
- package/build/components/use-dispatch/use-dispatch.js +36 -71
- package/build/components/use-dispatch/use-dispatch.js.map +7 -1
- package/build/components/use-select/index.js +79 -208
- package/build/components/use-select/index.js.map +7 -1
- package/build/components/with-dispatch/index.js +34 -107
- package/build/components/with-dispatch/index.js.map +7 -1
- package/build/components/with-registry/index.js +30 -30
- package/build/components/with-registry/index.js.map +7 -1
- package/build/components/with-select/index.js +44 -67
- package/build/components/with-select/index.js.map +7 -1
- package/build/controls.js +49 -110
- package/build/controls.js.map +7 -1
- package/build/create-selector.js +36 -11
- package/build/create-selector.js.map +7 -1
- package/build/default-registry.js +24 -10
- package/build/default-registry.js.map +7 -1
- package/build/dispatch.js +38 -31
- package/build/dispatch.js.map +7 -1
- package/build/factory.js +29 -85
- package/build/factory.js.map +7 -1
- package/build/index.js +114 -301
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/plugins/index.js +36 -11
- package/build/plugins/index.js.map +7 -1
- package/build/plugins/persistence/index.js +74 -139
- package/build/plugins/persistence/index.js.map +7 -1
- package/build/plugins/persistence/storage/default.js +37 -18
- package/build/plugins/persistence/storage/default.js.map +7 -1
- package/build/plugins/persistence/storage/object.js +24 -7
- package/build/plugins/persistence/storage/object.js.map +7 -1
- package/build/promise-middleware.js +37 -20
- package/build/promise-middleware.js.map +7 -1
- package/build/redux-store/combine-reducers.js +26 -5
- package/build/redux-store/combine-reducers.js.map +7 -1
- package/build/redux-store/index.js +221 -331
- package/build/redux-store/index.js.map +7 -1
- package/build/redux-store/metadata/actions.js +51 -112
- package/build/redux-store/metadata/actions.js.map +7 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js +1 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
- package/build/redux-store/metadata/reducer.js +111 -115
- package/build/redux-store/metadata/reducer.js.map +7 -1
- package/build/redux-store/metadata/selectors.js +109 -181
- package/build/redux-store/metadata/selectors.js.map +7 -1
- package/build/redux-store/metadata/utils.js +32 -35
- package/build/redux-store/metadata/utils.js.map +7 -1
- package/build/redux-store/thunk-middleware.js +24 -7
- package/build/redux-store/thunk-middleware.js.map +7 -1
- package/build/registry.js +94 -198
- package/build/registry.js.map +7 -1
- package/build/resolvers-cache-middleware.js +26 -27
- package/build/resolvers-cache-middleware.js.map +7 -1
- package/build/select.js +38 -31
- package/build/select.js.map +7 -1
- package/build/store/index.js +52 -16
- package/build/store/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/emitter.js +33 -16
- package/build/utils/emitter.js.map +7 -1
- package/build-module/components/async-mode-provider/context.js +12 -49
- package/build-module/components/async-mode-provider/context.js.map +7 -1
- package/build-module/components/async-mode-provider/index.js +8 -3
- package/build-module/components/async-mode-provider/index.js.map +7 -1
- package/build-module/components/async-mode-provider/use-async-mode.js +7 -11
- package/build-module/components/async-mode-provider/use-async-mode.js.map +7 -1
- package/build-module/components/registry-provider/context.js +13 -58
- package/build-module/components/registry-provider/context.js.map +7 -1
- package/build-module/components/registry-provider/index.js +8 -3
- package/build-module/components/registry-provider/index.js.map +7 -1
- package/build-module/components/registry-provider/use-registry.js +7 -51
- package/build-module/components/registry-provider/use-registry.js.map +7 -1
- package/build-module/components/use-dispatch/index.js +7 -3
- package/build-module/components/use-dispatch/index.js.map +7 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +27 -35
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
- package/build-module/components/use-dispatch/use-dispatch.js +8 -66
- package/build-module/components/use-dispatch/use-dispatch.js.map +7 -1
- package/build-module/components/use-select/index.js +45 -193
- package/build-module/components/use-select/index.js.map +7 -1
- package/build-module/components/with-dispatch/index.js +16 -104
- package/build-module/components/with-dispatch/index.js.map +7 -1
- package/build-module/components/with-registry/index.js +12 -27
- package/build-module/components/with-registry/index.js.map +7 -1
- package/build-module/components/with-select/index.js +16 -63
- package/build-module/components/with-select/index.js.map +7 -1
- package/build-module/controls.js +25 -105
- package/build-module/controls.js.map +7 -1
- package/build-module/create-selector.js +5 -8
- package/build-module/create-selector.js.map +7 -1
- package/build-module/default-registry.js +6 -6
- package/build-module/default-registry.js.map +7 -1
- package/build-module/dispatch.js +6 -27
- package/build-module/dispatch.js.map +7 -1
- package/build-module/factory.js +8 -82
- package/build-module/factory.js.map +7 -1
- package/build-module/index.js +62 -185
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/plugins/index.js +5 -2
- package/build-module/plugins/index.js.map +7 -1
- package/build-module/plugins/persistence/index.js +38 -129
- package/build-module/plugins/persistence/index.js.map +7 -1
- package/build-module/plugins/persistence/storage/default.js +8 -11
- package/build-module/plugins/persistence/storage/default.js.map +7 -1
- package/build-module/plugins/persistence/storage/object.js +6 -3
- package/build-module/plugins/persistence/storage/object.js.map +7 -1
- package/build-module/promise-middleware.js +8 -14
- package/build-module/promise-middleware.js.map +7 -1
- package/build-module/redux-store/combine-reducers.js +5 -2
- package/build-module/redux-store/combine-reducers.js.map +7 -1
- package/build-module/redux-store/index.js +180 -310
- package/build-module/redux-store/index.js.map +7 -1
- package/build-module/redux-store/metadata/actions.js +30 -109
- package/build-module/redux-store/metadata/actions.js.map +7 -1
- package/build-module/redux-store/metadata/equivalent-key-map.d.js +1 -2
- package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
- package/build-module/redux-store/metadata/reducer.js +83 -108
- package/build-module/redux-store/metadata/reducer.js.map +7 -1
- package/build-module/redux-store/metadata/selectors.js +76 -175
- package/build-module/redux-store/metadata/selectors.js.map +7 -1
- package/build-module/redux-store/metadata/utils.js +10 -30
- package/build-module/redux-store/metadata/utils.js.map +7 -1
- package/build-module/redux-store/thunk-middleware.js +7 -4
- package/build-module/redux-store/thunk-middleware.js.map +7 -1
- package/build-module/registry.js +56 -187
- package/build-module/registry.js.map +7 -1
- package/build-module/resolvers-cache-middleware.js +8 -23
- package/build-module/resolvers-cache-middleware.js.map +7 -1
- package/build-module/select.js +6 -27
- package/build-module/select.js.map +7 -1
- package/build-module/store/index.js +34 -12
- package/build-module/store/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/emitter.js +12 -13
- package/build-module/utils/emitter.js.map +7 -1
- package/package.json +17 -10
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["_deprecated","_interopRequireDefault","require","_createSelector","_utils","getResolutionState","state","selectorName","args","map","get","selectorArgsToStateKey","getIsResolving","deprecated","since","version","alternative","resolutionState","status","hasStartedResolution","undefined","hasFinishedResolution","hasResolutionFailed","getResolutionError","error","isResolving","getCachedResolvers","hasResolvingSelectors","Object","values","some","selectorState","Array","from","_map","resolution","countSelectorsByStatus","exports","createSelector","selectorsByStatus","forEach","_resolution$1$status","currentStatus"],"sources":["@wordpress/data/src/redux-store/metadata/selectors.js"],"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';\n\n/** @typedef {Record<string, import('./reducer').State>} State */\n/** @typedef {import('./reducer').StateValue} StateValue */\n/** @typedef {import('./reducer').Status} Status */\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {StateValue|undefined} isResolving value.\n */\nexport function getResolutionState( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean | undefined} isResolving value.\n */\nexport function getIsResolving( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has been triggered.\n */\nexport function hasStartedResolution( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has completed.\n */\nexport function hasFinishedResolution( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Has resolution failed\n */\nexport function hasResolutionFailed( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {Error|unknown} Last resolution error\n */\nexport function getResolutionError( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution is in progress.\n */\nexport function isResolving( state, selectorName, args ) {\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} state Data state.\n *\n * @return {State} Resolvers mapped by args and selectorName.\n */\nexport function getCachedResolvers( state ) {\n\treturn state;\n}\n\n/**\n * Whether the store has any currently resolving selectors.\n *\n * @param {State} state Data state.\n *\n * @return {boolean} True if one or more selectors are resolving, false otherwise.\n */\nexport function hasResolvingSelectors( state ) {\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._map.values() ).some(\n\t\t\t( resolution ) => 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} state Data state.\n *\n * @return {Object} Object, containing selector totals by status.\n */\nexport const countSelectorsByStatus = createSelector(\n\t( state ) => {\n\t\tconst selectorsByStatus = {};\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._map.values() ).forEach(\n\t\t\t\t( resolution ) => {\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 ) => [ state ]\n);\n"],"mappings":";;;;;;;;;;;;;;;;AAGA,IAAAA,WAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASG,kB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Z,MAAMiC,iBAAiB,GAAG,CAAC,CAAC;EAE5BX,MAAM,CAACC,MAAM,CAAEvB,KAAM,CAAC,CAACkC,OAAO,CAAIT,aAAa;EAC9C;AACH;AACA;AACA;AACA;AACA;AACA;EACGC,KAAK,CAACC,IAAI,CAAEF,aAAa,CAACG,IAAI,CAACL,MAAM,CAAC,CAAE,CAAC,CAACW,OAAO,CAC9CL,UAAU,IAAM;IAAA,IAAAM,oBAAA;IACjB,MAAMC,aAAa,IAAAD,oBAAA,GAAGN,UAAU,CAAE,CAAC,CAAE,EAAEjB,MAAM,cAAAuB,oBAAA,cAAAA,oBAAA,GAAI,OAAO;IACxD,IAAK,CAAEF,iBAAiB,CAAEG,aAAa,CAAE,EAAG;MAC3CH,iBAAiB,CAAEG,aAAa,CAAE,GAAG,CAAC;IACvC;IACAH,iBAAiB,CAAEG,aAAa,CAAE,EAAE;EACrC,CACD,CACD,CAAC;EAED,OAAOH,iBAAiB;AACzB,CAAC,EACCjC,KAAK,IAAM,CAAEA,KAAK,CACrB,CAAC","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/redux-store/metadata/selectors.js"],
|
|
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';\n\n/** @typedef {Record<string, import('./reducer').State>} State */\n/** @typedef {import('./reducer').StateValue} StateValue */\n/** @typedef {import('./reducer').Status} Status */\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {StateValue|undefined} isResolving value.\n */\nexport function getResolutionState( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean | undefined} isResolving value.\n */\nexport function getIsResolving( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has been triggered.\n */\nexport function hasStartedResolution( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has completed.\n */\nexport function hasFinishedResolution( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Has resolution failed\n */\nexport function hasResolutionFailed( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {Error|unknown} Last resolution error\n */\nexport function getResolutionError( state, selectorName, args ) {\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} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution is in progress.\n */\nexport function isResolving( state, selectorName, args ) {\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} state Data state.\n *\n * @return {State} Resolvers mapped by args and selectorName.\n */\nexport function getCachedResolvers( state ) {\n\treturn state;\n}\n\n/**\n * Whether the store has any currently resolving selectors.\n *\n * @param {State} state Data state.\n *\n * @return {boolean} True if one or more selectors are resolving, false otherwise.\n */\nexport function hasResolvingSelectors( state ) {\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._map.values() ).some(\n\t\t\t( resolution ) => 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} state Data state.\n *\n * @return {Object} Object, containing selector totals by status.\n */\nexport const countSelectorsByStatus = createSelector(\n\t( state ) => {\n\t\tconst selectorsByStatus = {};\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._map.values() ).forEach(\n\t\t\t\t( resolution ) => {\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 ) => [ state ]\n);\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AAKvB,6BAA+B;AAC/B,mBAAuC;AAkBhC,SAAS,mBAAoB,OAAO,cAAc,MAAO;AAC/D,QAAM,MAAM,MAAO,YAAa;AAChC,MAAK,CAAE,KAAM;AACZ;AAAA,EACD;AAEA,SAAO,IAAI,QAAK,qCAAwB,IAAK,CAAE;AAChD;AAoBO,SAAS,eAAgB,OAAO,cAAc,MAAO;AAC3D,wBAAAA,SAAY,0CAA0C;AAAA,IACrD,OAAO;AAAA,IACP,SAAS;AAAA,IACT,aAAa;AAAA,EACd,CAAE;AAEF,QAAM,kBAAkB,mBAAoB,OAAO,cAAc,IAAK;AACtE,SAAO,mBAAmB,gBAAgB,WAAW;AACtD;AAYO,SAAS,qBAAsB,OAAO,cAAc,MAAO;AACjE,SAAO,mBAAoB,OAAO,cAAc,IAAK,MAAM;AAC5D;AAYO,SAAS,sBAAuB,OAAO,cAAc,MAAO;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names": ["deprecated"]
|
|
7
|
+
}
|
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var utils_exports = {};
|
|
20
|
+
__export(utils_exports, {
|
|
21
|
+
onSubKey: () => onSubKey,
|
|
22
|
+
selectorArgsToStateKey: () => selectorArgsToStateKey
|
|
5
23
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* External dependencies
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Higher-order reducer creator which creates a combined reducer object, keyed
|
|
14
|
-
* by a property on the action object.
|
|
15
|
-
*
|
|
16
|
-
* @param actionProperty Action property by which to key object.
|
|
17
|
-
* @return Higher-order reducer.
|
|
18
|
-
*/
|
|
19
|
-
const onSubKey = actionProperty => reducer => (state = {}, action) => {
|
|
20
|
-
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
|
21
|
-
// where reducer is scoped by action shape.
|
|
24
|
+
module.exports = __toCommonJS(utils_exports);
|
|
25
|
+
const onSubKey = (actionProperty) => (reducer) => (state = {}, action) => {
|
|
22
26
|
const key = action[actionProperty];
|
|
23
|
-
if (key ===
|
|
27
|
+
if (key === void 0) {
|
|
24
28
|
return state;
|
|
25
29
|
}
|
|
26
|
-
|
|
27
|
-
// Avoid updating state if unchanged. Note that this also accounts for a
|
|
28
|
-
// reducer which returns undefined on a key which is not yet tracked.
|
|
29
30
|
const nextKeyState = reducer(state[key], action);
|
|
30
31
|
if (nextKeyState === state[key]) {
|
|
31
32
|
return state;
|
|
@@ -35,24 +36,20 @@ const onSubKey = actionProperty => reducer => (state = {}, action) => {
|
|
|
35
36
|
[key]: nextKeyState
|
|
36
37
|
};
|
|
37
38
|
};
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Normalize selector argument array by defaulting `undefined` value to an empty array
|
|
41
|
-
* and removing trailing `undefined` values.
|
|
42
|
-
*
|
|
43
|
-
* @param args Selector argument array
|
|
44
|
-
* @return Normalized state key array
|
|
45
|
-
*/
|
|
46
|
-
exports.onSubKey = onSubKey;
|
|
47
39
|
function selectorArgsToStateKey(args) {
|
|
48
|
-
if (args ===
|
|
40
|
+
if (args === void 0 || args === null) {
|
|
49
41
|
return [];
|
|
50
42
|
}
|
|
51
43
|
const len = args.length;
|
|
52
44
|
let idx = len;
|
|
53
|
-
while (idx > 0 && args[idx - 1] ===
|
|
45
|
+
while (idx > 0 && args[idx - 1] === void 0) {
|
|
54
46
|
idx--;
|
|
55
47
|
}
|
|
56
48
|
return idx === len ? args : args.slice(0, idx);
|
|
57
49
|
}
|
|
58
|
-
|
|
50
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
51
|
+
0 && (module.exports = {
|
|
52
|
+
onSubKey,
|
|
53
|
+
selectorArgsToStateKey
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/redux-store/metadata/utils.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { AnyAction, Reducer } from 'redux';\n\n/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param actionProperty Action property by which to key object.\n * @return Higher-order reducer.\n */\nexport const onSubKey =\n\t< TState extends unknown, TAction extends AnyAction >(\n\t\tactionProperty: string\n\t) =>\n\t(\n\t\treducer: Reducer< TState, TAction >\n\t): Reducer< Record< string, TState >, TAction > =>\n\t( state: Record< string, TState > = {}, action ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\n/**\n * Normalize selector argument array by defaulting `undefined` value to an empty array\n * and removing trailing `undefined` values.\n *\n * @param args Selector argument array\n * @return Normalized state key array\n */\nexport function selectorArgsToStateKey( args: unknown[] | null | undefined ) {\n\tif ( args === undefined || args === null ) {\n\t\treturn [];\n\t}\n\n\tconst len = args.length;\n\tlet idx = len;\n\twhile ( idx > 0 && args[ idx - 1 ] === undefined ) {\n\t\tidx--;\n\t}\n\treturn idx === len ? args : args.slice( 0, idx );\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYO,MAAM,WACZ,CACC,mBAED,CACC,YAED,CAAE,QAAkC,CAAC,GAAG,WAAY;AAGnD,QAAM,MAAM,OAAQ,cAAe;AACnC,MAAK,QAAQ,QAAY;AACxB,WAAO;AAAA,EACR;AAIA,QAAM,eAAe,QAAS,MAAO,GAAI,GAAG,MAAO;AACnD,MAAK,iBAAiB,MAAO,GAAI,GAAI;AACpC,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,GAAI,GAAG;AAAA,EACV;AACD;AASM,SAAS,uBAAwB,MAAqC;AAC5E,MAAK,SAAS,UAAa,SAAS,MAAO;AAC1C,WAAO,CAAC;AAAA,EACT;AAEA,QAAM,MAAM,KAAK;AACjB,MAAI,MAAM;AACV,SAAQ,MAAM,KAAK,KAAM,MAAM,CAAE,MAAM,QAAY;AAClD;AAAA,EACD;AACA,SAAO,QAAQ,MAAM,OAAO,KAAK,MAAO,GAAG,GAAI;AAChD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var thunk_middleware_exports = {};
|
|
20
|
+
__export(thunk_middleware_exports, {
|
|
21
|
+
default: () => createThunkMiddleware
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
23
|
+
module.exports = __toCommonJS(thunk_middleware_exports);
|
|
7
24
|
function createThunkMiddleware(args) {
|
|
8
|
-
return () => next => action => {
|
|
9
|
-
if (typeof action ===
|
|
25
|
+
return () => (next) => (action) => {
|
|
26
|
+
if (typeof action === "function") {
|
|
10
27
|
return action(args);
|
|
11
28
|
}
|
|
12
29
|
return next(action);
|
|
13
30
|
};
|
|
14
31
|
}
|
|
15
|
-
//# sourceMappingURL=thunk-middleware.js.map
|
|
32
|
+
//# sourceMappingURL=thunk-middleware.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/redux-store/thunk-middleware.js"],
|
|
4
|
+
"sourcesContent": ["export default function createThunkMiddleware( args ) {\n\treturn () => ( next ) => ( action ) => {\n\t\tif ( typeof action === 'function' ) {\n\t\t\treturn action( args );\n\t\t}\n\n\t\treturn next( action );\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAe,SAAR,sBAAwC,MAAO;AACrD,SAAO,MAAM,CAAE,SAAU,CAAE,WAAY;AACtC,QAAK,OAAO,WAAW,YAAa;AACnC,aAAO,OAAQ,IAAK;AAAA,IACrB;AAEA,WAAO,KAAM,MAAO;AAAA,EACrB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build/registry.js
CHANGED
|
@@ -1,115 +1,65 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var registry_exports = {};
|
|
30
|
+
__export(registry_exports, {
|
|
31
|
+
createRegistry: () => createRegistry
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
/**
|
|
14
|
-
* WordPress dependencies
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Internal dependencies
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.
|
|
25
|
-
*
|
|
26
|
-
* @property {Function} registerGenericStore Given a namespace key and settings
|
|
27
|
-
* object, registers a new generic
|
|
28
|
-
* store.
|
|
29
|
-
* @property {Function} registerStore Given a namespace key and settings
|
|
30
|
-
* object, registers a new namespace
|
|
31
|
-
* store.
|
|
32
|
-
* @property {Function} subscribe Given a function callback, invokes
|
|
33
|
-
* the callback on any change to state
|
|
34
|
-
* within any registered store.
|
|
35
|
-
* @property {Function} select Given a namespace key, returns an
|
|
36
|
-
* object of the store's registered
|
|
37
|
-
* selectors.
|
|
38
|
-
* @property {Function} dispatch Given a namespace key, returns an
|
|
39
|
-
* object of the store's registered
|
|
40
|
-
* action dispatchers.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @typedef {Object} WPDataPlugin An object of registry function overrides.
|
|
45
|
-
*
|
|
46
|
-
* @property {Function} registerStore registers store.
|
|
47
|
-
*/
|
|
48
|
-
|
|
33
|
+
module.exports = __toCommonJS(registry_exports);
|
|
34
|
+
var import_deprecated = __toESM(require("@wordpress/deprecated"));
|
|
35
|
+
var import_redux_store = __toESM(require("./redux-store"));
|
|
36
|
+
var import_store = __toESM(require("./store"));
|
|
37
|
+
var import_emitter = require("./utils/emitter");
|
|
38
|
+
var import_lock_unlock = require("./lock-unlock");
|
|
49
39
|
function getStoreName(storeNameOrDescriptor) {
|
|
50
|
-
return typeof storeNameOrDescriptor ===
|
|
40
|
+
return typeof storeNameOrDescriptor === "string" ? storeNameOrDescriptor : storeNameOrDescriptor.name;
|
|
51
41
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Creates a new store registry, given an optional object of initial store
|
|
54
|
-
* configurations.
|
|
55
|
-
*
|
|
56
|
-
* @param {Object} storeConfigs Initial store configurations.
|
|
57
|
-
* @param {?Object} parent Parent registry.
|
|
58
|
-
*
|
|
59
|
-
* @return {WPDataRegistry} Data registry.
|
|
60
|
-
*/
|
|
61
42
|
function createRegistry(storeConfigs = {}, parent = null) {
|
|
62
43
|
const stores = {};
|
|
63
|
-
const emitter = (0,
|
|
44
|
+
const emitter = (0, import_emitter.createEmitter)();
|
|
64
45
|
let listeningStores = null;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Global listener called for each store's update.
|
|
68
|
-
*/
|
|
69
46
|
function globalListener() {
|
|
70
47
|
emitter.emit();
|
|
71
48
|
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Subscribe to changes to any data, either in all stores in registry, or
|
|
75
|
-
* in one specific store.
|
|
76
|
-
*
|
|
77
|
-
* @param {Function} listener Listener function.
|
|
78
|
-
* @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.
|
|
79
|
-
*
|
|
80
|
-
* @return {Function} Unsubscribe function.
|
|
81
|
-
*/
|
|
82
49
|
const subscribe = (listener, storeNameOrDescriptor) => {
|
|
83
|
-
// subscribe to all stores
|
|
84
50
|
if (!storeNameOrDescriptor) {
|
|
85
51
|
return emitter.subscribe(listener);
|
|
86
52
|
}
|
|
87
|
-
|
|
88
|
-
// subscribe to one store
|
|
89
53
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
90
54
|
const store = stores[storeName];
|
|
91
55
|
if (store) {
|
|
92
56
|
return store.subscribe(listener);
|
|
93
57
|
}
|
|
94
|
-
|
|
95
|
-
// Trying to access a store that hasn't been registered,
|
|
96
|
-
// this is a pattern rarely used but seen in some places.
|
|
97
|
-
// We fallback to global `subscribe` here for backward-compatibility for now.
|
|
98
|
-
// See https://github.com/WordPress/gutenberg/pull/27466 for more info.
|
|
99
58
|
if (!parent) {
|
|
100
59
|
return emitter.subscribe(listener);
|
|
101
60
|
}
|
|
102
61
|
return parent.subscribe(listener, storeNameOrDescriptor);
|
|
103
62
|
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Calls a selector given the current state and extra arguments.
|
|
107
|
-
*
|
|
108
|
-
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
109
|
-
* or the store descriptor.
|
|
110
|
-
*
|
|
111
|
-
* @return {*} The selector's returned value.
|
|
112
|
-
*/
|
|
113
63
|
function select(storeNameOrDescriptor) {
|
|
114
64
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
115
65
|
listeningStores?.add(storeName);
|
|
@@ -120,7 +70,7 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
120
70
|
return parent?.select(storeName);
|
|
121
71
|
}
|
|
122
72
|
function __unstableMarkListeningStores(callback, ref) {
|
|
123
|
-
listeningStores = new Set();
|
|
73
|
+
listeningStores = /* @__PURE__ */ new Set();
|
|
124
74
|
try {
|
|
125
75
|
return callback.call(this);
|
|
126
76
|
} finally {
|
|
@@ -128,18 +78,6 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
128
78
|
listeningStores = null;
|
|
129
79
|
}
|
|
130
80
|
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Given a store descriptor, returns an object containing the store's selectors pre-bound to
|
|
134
|
-
* state so that you only need to supply additional arguments, and modified so that they return
|
|
135
|
-
* promises that resolve to their eventual values, after any resolvers have ran.
|
|
136
|
-
*
|
|
137
|
-
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
138
|
-
* convention of passing the store name is
|
|
139
|
-
* also supported.
|
|
140
|
-
*
|
|
141
|
-
* @return {Object} Each key of the object matches the name of a selector.
|
|
142
|
-
*/
|
|
143
81
|
function resolveSelect(storeNameOrDescriptor) {
|
|
144
82
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
145
83
|
listeningStores?.add(storeName);
|
|
@@ -149,18 +87,6 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
149
87
|
}
|
|
150
88
|
return parent && parent.resolveSelect(storeName);
|
|
151
89
|
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Given a store descriptor, returns an object containing the store's selectors pre-bound to
|
|
155
|
-
* state so that you only need to supply additional arguments, and modified so that they throw
|
|
156
|
-
* promises in case the selector is not resolved yet.
|
|
157
|
-
*
|
|
158
|
-
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
159
|
-
* convention of passing the store name is
|
|
160
|
-
* also supported.
|
|
161
|
-
*
|
|
162
|
-
* @return {Object} Object containing the store's suspense-wrapped selectors.
|
|
163
|
-
*/
|
|
164
90
|
function suspendSelect(storeNameOrDescriptor) {
|
|
165
91
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
166
92
|
listeningStores?.add(storeName);
|
|
@@ -170,15 +96,6 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
170
96
|
}
|
|
171
97
|
return parent && parent.suspendSelect(storeName);
|
|
172
98
|
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Returns the available actions for a part of the state.
|
|
176
|
-
*
|
|
177
|
-
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
178
|
-
* or the store descriptor.
|
|
179
|
-
*
|
|
180
|
-
* @return {*} The action's returned value.
|
|
181
|
-
*/
|
|
182
99
|
function dispatch(storeNameOrDescriptor) {
|
|
183
100
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
184
101
|
const store = stores[storeName];
|
|
@@ -187,49 +104,39 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
187
104
|
}
|
|
188
105
|
return parent && parent.dispatch(storeName);
|
|
189
106
|
}
|
|
190
|
-
|
|
191
|
-
//
|
|
192
|
-
// Deprecated
|
|
193
|
-
// TODO: Remove this after `use()` is removed.
|
|
194
107
|
function withPlugins(attributes) {
|
|
195
|
-
return Object.fromEntries(
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return
|
|
201
|
-
|
|
202
|
-
|
|
108
|
+
return Object.fromEntries(
|
|
109
|
+
Object.entries(attributes).map(([key, attribute]) => {
|
|
110
|
+
if (typeof attribute !== "function") {
|
|
111
|
+
return [key, attribute];
|
|
112
|
+
}
|
|
113
|
+
return [
|
|
114
|
+
key,
|
|
115
|
+
function() {
|
|
116
|
+
return registry[key].apply(null, arguments);
|
|
117
|
+
}
|
|
118
|
+
];
|
|
119
|
+
})
|
|
120
|
+
);
|
|
203
121
|
}
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Registers a store instance.
|
|
207
|
-
*
|
|
208
|
-
* @param {string} name Store registry name.
|
|
209
|
-
* @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).
|
|
210
|
-
*/
|
|
211
122
|
function registerStoreInstance(name, createStore) {
|
|
212
123
|
if (stores[name]) {
|
|
213
|
-
// eslint-disable-next-line no-console
|
|
214
124
|
console.error('Store "' + name + '" is already registered.');
|
|
215
125
|
return stores[name];
|
|
216
126
|
}
|
|
217
127
|
const store = createStore();
|
|
218
|
-
if (typeof store.getSelectors !==
|
|
219
|
-
throw new TypeError(
|
|
128
|
+
if (typeof store.getSelectors !== "function") {
|
|
129
|
+
throw new TypeError("store.getSelectors must be a function");
|
|
220
130
|
}
|
|
221
|
-
if (typeof store.getActions !==
|
|
222
|
-
throw new TypeError(
|
|
131
|
+
if (typeof store.getActions !== "function") {
|
|
132
|
+
throw new TypeError("store.getActions must be a function");
|
|
223
133
|
}
|
|
224
|
-
if (typeof store.subscribe !==
|
|
225
|
-
throw new TypeError(
|
|
134
|
+
if (typeof store.subscribe !== "function") {
|
|
135
|
+
throw new TypeError("store.subscribe must be a function");
|
|
226
136
|
}
|
|
227
|
-
|
|
228
|
-
// get paused, that way, when resumed we should be able to call all these
|
|
229
|
-
// pending listeners.
|
|
230
|
-
store.emitter = (0, _emitter.createEmitter)();
|
|
137
|
+
store.emitter = (0, import_emitter.createEmitter)();
|
|
231
138
|
const currentSubscribe = store.subscribe;
|
|
232
|
-
store.subscribe = listener => {
|
|
139
|
+
store.subscribe = (listener) => {
|
|
233
140
|
const unsubscribeFromEmitter = store.emitter.subscribe(listener);
|
|
234
141
|
const unsubscribeFromStore = currentSubscribe(() => {
|
|
235
142
|
if (store.emitter.isPaused) {
|
|
@@ -245,65 +152,56 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
245
152
|
};
|
|
246
153
|
stores[name] = store;
|
|
247
154
|
store.subscribe(globalListener);
|
|
248
|
-
|
|
249
|
-
// Copy private actions and selectors from the parent store.
|
|
250
155
|
if (parent) {
|
|
251
156
|
try {
|
|
252
|
-
(0,
|
|
253
|
-
|
|
157
|
+
(0, import_lock_unlock.unlock)(store.store).registerPrivateActions(
|
|
158
|
+
(0, import_lock_unlock.unlock)(parent).privateActionsOf(name)
|
|
159
|
+
);
|
|
160
|
+
(0, import_lock_unlock.unlock)(store.store).registerPrivateSelectors(
|
|
161
|
+
(0, import_lock_unlock.unlock)(parent).privateSelectorsOf(name)
|
|
162
|
+
);
|
|
254
163
|
} catch (e) {
|
|
255
|
-
// unlock() throws if store.store was not locked.
|
|
256
|
-
// The error indicates there's nothing to do here so let's
|
|
257
|
-
// ignore it.
|
|
258
164
|
}
|
|
259
165
|
}
|
|
260
166
|
return store;
|
|
261
167
|
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Registers a new store given a store descriptor.
|
|
265
|
-
*
|
|
266
|
-
* @param {StoreDescriptor} store Store descriptor.
|
|
267
|
-
*/
|
|
268
168
|
function register(store) {
|
|
269
|
-
registerStoreInstance(
|
|
169
|
+
registerStoreInstance(
|
|
170
|
+
store.name,
|
|
171
|
+
() => store.instantiate(registry)
|
|
172
|
+
);
|
|
270
173
|
}
|
|
271
174
|
function registerGenericStore(name, store) {
|
|
272
|
-
(0,
|
|
273
|
-
since:
|
|
274
|
-
alternative:
|
|
175
|
+
(0, import_deprecated.default)("wp.data.registerGenericStore", {
|
|
176
|
+
since: "5.9",
|
|
177
|
+
alternative: "wp.data.register( storeDescriptor )"
|
|
275
178
|
});
|
|
276
179
|
registerStoreInstance(name, () => store);
|
|
277
180
|
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* Registers a standard `@wordpress/data` store.
|
|
281
|
-
*
|
|
282
|
-
* @param {string} storeName Unique namespace identifier.
|
|
283
|
-
* @param {Object} options Store description (reducer, actions, selectors, resolvers).
|
|
284
|
-
*
|
|
285
|
-
* @return {Object} Registered store object.
|
|
286
|
-
*/
|
|
287
181
|
function registerStore(storeName, options) {
|
|
288
182
|
if (!options.reducer) {
|
|
289
|
-
throw new TypeError(
|
|
183
|
+
throw new TypeError("Must specify store reducer");
|
|
290
184
|
}
|
|
291
|
-
const store = registerStoreInstance(
|
|
185
|
+
const store = registerStoreInstance(
|
|
186
|
+
storeName,
|
|
187
|
+
() => (0, import_redux_store.default)(storeName, options).instantiate(registry)
|
|
188
|
+
);
|
|
292
189
|
return store.store;
|
|
293
190
|
}
|
|
294
191
|
function batch(callback) {
|
|
295
|
-
// If we're already batching, just call the callback.
|
|
296
192
|
if (emitter.isPaused) {
|
|
297
193
|
callback();
|
|
298
194
|
return;
|
|
299
195
|
}
|
|
300
196
|
emitter.pause();
|
|
301
|
-
Object.values(stores).forEach(store => store.emitter.pause());
|
|
197
|
+
Object.values(stores).forEach((store) => store.emitter.pause());
|
|
302
198
|
try {
|
|
303
199
|
callback();
|
|
304
200
|
} finally {
|
|
305
201
|
emitter.resume();
|
|
306
|
-
Object.values(stores).forEach(
|
|
202
|
+
Object.values(stores).forEach(
|
|
203
|
+
(store) => store.emitter.resume()
|
|
204
|
+
);
|
|
307
205
|
}
|
|
308
206
|
}
|
|
309
207
|
let registry = {
|
|
@@ -322,10 +220,6 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
322
220
|
registerStore,
|
|
323
221
|
__unstableMarkListeningStores
|
|
324
222
|
};
|
|
325
|
-
|
|
326
|
-
//
|
|
327
|
-
// TODO:
|
|
328
|
-
// This function will be deprecated as soon as it is no longer internally referenced.
|
|
329
223
|
function use(plugin, options) {
|
|
330
224
|
if (!plugin) {
|
|
331
225
|
return;
|
|
@@ -336,27 +230,25 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
336
230
|
};
|
|
337
231
|
return registry;
|
|
338
232
|
}
|
|
339
|
-
registry.register(
|
|
233
|
+
registry.register(import_store.default);
|
|
340
234
|
for (const [name, config] of Object.entries(storeConfigs)) {
|
|
341
|
-
registry.register((0,
|
|
235
|
+
registry.register((0, import_redux_store.default)(name, config));
|
|
342
236
|
}
|
|
343
237
|
if (parent) {
|
|
344
238
|
parent.subscribe(globalListener);
|
|
345
239
|
}
|
|
346
240
|
const registryWithPlugins = withPlugins(registry);
|
|
347
|
-
(0,
|
|
348
|
-
privateActionsOf: name => {
|
|
241
|
+
(0, import_lock_unlock.lock)(registryWithPlugins, {
|
|
242
|
+
privateActionsOf: (name) => {
|
|
349
243
|
try {
|
|
350
|
-
return (0,
|
|
244
|
+
return (0, import_lock_unlock.unlock)(stores[name].store).privateActions;
|
|
351
245
|
} catch (e) {
|
|
352
|
-
// unlock() throws an error the store was not locked – this means
|
|
353
|
-
// there no private actions are available
|
|
354
246
|
return {};
|
|
355
247
|
}
|
|
356
248
|
},
|
|
357
|
-
privateSelectorsOf: name => {
|
|
249
|
+
privateSelectorsOf: (name) => {
|
|
358
250
|
try {
|
|
359
|
-
return (0,
|
|
251
|
+
return (0, import_lock_unlock.unlock)(stores[name].store).privateSelectors;
|
|
360
252
|
} catch (e) {
|
|
361
253
|
return {};
|
|
362
254
|
}
|
|
@@ -364,4 +256,8 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
364
256
|
});
|
|
365
257
|
return registryWithPlugins;
|
|
366
258
|
}
|
|
367
|
-
|
|
259
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
260
|
+
0 && (module.exports = {
|
|
261
|
+
createRegistry
|
|
262
|
+
});
|
|
263
|
+
//# sourceMappingURL=registry.js.map
|