@wordpress/data 9.12.2 → 9.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +6 -6
- package/build/components/async-mode-provider/context.js +1 -1
- package/build/components/async-mode-provider/context.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +1 -1
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/with-dispatch/index.js +4 -4
- package/build/components/with-dispatch/index.js.map +1 -1
- package/build/components/with-registry/index.js +4 -4
- package/build/components/with-registry/index.js.map +1 -1
- package/build/components/with-select/index.js +4 -4
- package/build/components/with-select/index.js.map +1 -1
- package/build/index.js +7 -9
- package/build/index.js.map +1 -1
- package/build/redux-store/combine-reducers.js +22 -0
- package/build/redux-store/combine-reducers.js.map +1 -0
- package/build/redux-store/index.js +10 -4
- package/build/redux-store/index.js.map +1 -1
- package/build/resolvers-cache-middleware.js +18 -16
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build-module/components/async-mode-provider/context.js +1 -1
- package/build-module/components/async-mode-provider/context.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/with-dispatch/index.js +3 -3
- package/build-module/components/with-dispatch/index.js.map +1 -1
- package/build-module/components/with-registry/index.js +3 -3
- package/build-module/components/with-registry/index.js.map +1 -1
- package/build-module/components/with-select/index.js +3 -3
- package/build-module/components/with-select/index.js.map +1 -1
- package/build-module/index.js +1 -6
- package/build-module/index.js.map +1 -1
- package/build-module/redux-store/combine-reducers.js +16 -0
- package/build-module/redux-store/combine-reducers.js.map +1 -0
- package/build-module/redux-store/index.js +4 -3
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +18 -15
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch.d.ts +1 -1
- package/build-types/components/with-dispatch/index.d.ts +4 -4
- package/build-types/components/with-dispatch/index.d.ts.map +1 -1
- package/build-types/components/with-registry/index.d.ts +2 -2
- package/build-types/components/with-select/index.d.ts +4 -4
- package/build-types/components/with-select/index.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -41
- package/build-types/index.d.ts.map +1 -1
- package/build-types/redux-store/combine-reducers.d.ts +2 -0
- package/build-types/redux-store/combine-reducers.d.ts.map +1 -0
- package/build-types/redux-store/index.d.ts +5 -3
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/build-types/resolvers-cache-middleware.d.ts +3 -5
- package/build-types/resolvers-cache-middleware.d.ts.map +1 -1
- package/package.json +9 -10
- package/src/components/async-mode-provider/context.js +1 -1
- package/src/components/use-dispatch/use-dispatch.js +1 -1
- package/src/components/with-dispatch/index.js +2 -2
- package/src/components/with-registry/index.js +2 -2
- package/src/components/with-select/index.js +2 -2
- package/src/index.js +1 -6
- package/src/redux-store/combine-reducers.js +17 -0
- package/src/redux-store/index.js +5 -3
- package/src/redux-store/test/combine-reducers.js +66 -0
- package/src/resolvers-cache-middleware.js +32 -38
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 9.13.0 (2023-10-05)
|
|
6
|
+
|
|
7
|
+
### Enhancements
|
|
8
|
+
|
|
9
|
+
- Change implementation of `combineReducers` so that it doesn't use `eval` internally, and can run with a CSP policy that doesn't allow `unsafe-eval` ([#54606](https://github.com/WordPress/gutenberg/pull/54606)).
|
|
10
|
+
|
|
5
11
|
## 9.12.0 (2023-09-20)
|
|
6
12
|
|
|
7
13
|
## 9.11.0 (2023-08-31)
|
package/README.md
CHANGED
|
@@ -315,7 +315,7 @@ _Parameters_
|
|
|
315
315
|
|
|
316
316
|
_Returns_
|
|
317
317
|
|
|
318
|
-
- `
|
|
318
|
+
- `Component`: The component to be rendered.
|
|
319
319
|
|
|
320
320
|
### combineReducers
|
|
321
321
|
|
|
@@ -702,8 +702,8 @@ the server via the `useSelect` hook to use in combination with the dispatch
|
|
|
702
702
|
action.
|
|
703
703
|
|
|
704
704
|
```jsx
|
|
705
|
+
import { useCallback } from 'react';
|
|
705
706
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
706
|
-
import { useCallback } from '@wordpress/element';
|
|
707
707
|
import { store as myCustomStore } from 'my-custom-store';
|
|
708
708
|
|
|
709
709
|
function Button( { onClick, children } ) {
|
|
@@ -939,7 +939,7 @@ _Parameters_
|
|
|
939
939
|
|
|
940
940
|
_Returns_
|
|
941
941
|
|
|
942
|
-
- `
|
|
942
|
+
- `ComponentType`: Enhanced component with merged dispatcher props.
|
|
943
943
|
|
|
944
944
|
### withRegistry
|
|
945
945
|
|
|
@@ -947,11 +947,11 @@ Higher-order component which renders the original component with the current reg
|
|
|
947
947
|
|
|
948
948
|
_Parameters_
|
|
949
949
|
|
|
950
|
-
- _OriginalComponent_ `
|
|
950
|
+
- _OriginalComponent_ `Component`: Original component.
|
|
951
951
|
|
|
952
952
|
_Returns_
|
|
953
953
|
|
|
954
|
-
- `
|
|
954
|
+
- `Component`: Enhanced component.
|
|
955
955
|
|
|
956
956
|
### withSelect
|
|
957
957
|
|
|
@@ -995,7 +995,7 @@ _Parameters_
|
|
|
995
995
|
|
|
996
996
|
_Returns_
|
|
997
997
|
|
|
998
|
-
- `
|
|
998
|
+
- `ComponentType`: Enhanced component with merged state data props.
|
|
999
999
|
|
|
1000
1000
|
<!-- END TOKEN(Autogenerated API docs) -->
|
|
1001
1001
|
|
|
@@ -50,7 +50,7 @@ const AsyncModeConsumer = Consumer;
|
|
|
50
50
|
* It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior.
|
|
51
51
|
*
|
|
52
52
|
* @param {boolean} props.value Enable Async Mode.
|
|
53
|
-
* @return {
|
|
53
|
+
* @return {Component} The component to be rendered.
|
|
54
54
|
*/
|
|
55
55
|
exports.AsyncModeConsumer = AsyncModeConsumer;
|
|
56
56
|
var _default = Provider;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","Context","createContext","exports","Consumer","Provider","AsyncModeConsumer","_default","default"],"sources":["@wordpress/data/src/components/async-mode-provider/context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\nexport const Context = createContext( false );\n\nconst { Consumer, Provider } = Context;\n\nexport const AsyncModeConsumer = Consumer;\n\n/**\n * Context Provider Component used to switch the data module component rerendering\n * between Sync and Async modes.\n *\n * @example\n *\n * ```js\n * import { useSelect, AsyncModeProvider } from '@wordpress/data';\n * import { store as blockEditorStore } from '@wordpress/block-editor';\n *\n * function BlockCount() {\n * const count = useSelect( ( select ) => {\n * return select( blockEditorStore ).getBlockCount()\n * }, [] );\n *\n * return count;\n * }\n *\n * function App() {\n * return (\n * <AsyncModeProvider value={ true }>\n * <BlockCount />\n * </AsyncModeProvider>\n * );\n * }\n * ```\n *\n * In this example, the BlockCount component is rerendered asynchronously.\n * It means if a more critical task is being performed (like typing in an input),\n * the rerendering is delayed until the browser becomes IDLE.\n * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior.\n *\n * @param {boolean} props.value Enable Async Mode.\n * @return {
|
|
1
|
+
{"version":3,"names":["_element","require","Context","createContext","exports","Consumer","Provider","AsyncModeConsumer","_default","default"],"sources":["@wordpress/data/src/components/async-mode-provider/context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\nexport const Context = createContext( false );\n\nconst { Consumer, Provider } = Context;\n\nexport const AsyncModeConsumer = Consumer;\n\n/**\n * Context Provider Component used to switch the data module component rerendering\n * between Sync and Async modes.\n *\n * @example\n *\n * ```js\n * import { useSelect, AsyncModeProvider } from '@wordpress/data';\n * import { store as blockEditorStore } from '@wordpress/block-editor';\n *\n * function BlockCount() {\n * const count = useSelect( ( select ) => {\n * return select( blockEditorStore ).getBlockCount()\n * }, [] );\n *\n * return count;\n * }\n *\n * function App() {\n * return (\n * <AsyncModeProvider value={ true }>\n * <BlockCount />\n * </AsyncModeProvider>\n * );\n * }\n * ```\n *\n * In this example, the BlockCount component is rerendered asynchronously.\n * It means if a more critical task is being performed (like typing in an input),\n * the rerendering is delayed until the browser becomes IDLE.\n * It is possible to nest multiple levels of AsyncModeProvider to fine-tune the rendering behavior.\n *\n * @param {boolean} props.value Enable Async Mode.\n * @return {Component} The component to be rendered.\n */\nexport default Provider;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGO,MAAMC,OAAO,GAAG,IAAAC,sBAAa,EAAE,KAAM,CAAC;AAACC,OAAA,CAAAF,OAAA,GAAAA,OAAA;AAE9C,MAAM;EAAEG,QAAQ;EAAEC;AAAS,CAAC,GAAGJ,OAAO;AAE/B,MAAMK,iBAAiB,GAAGF,QAAQ;;AAEzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAlCAD,OAAA,CAAAG,iBAAA,GAAAA,iBAAA;AAAA,IAAAC,QAAA,GAmCeF,QAAQ;AAAAF,OAAA,CAAAK,OAAA,GAAAD,QAAA"}
|
|
@@ -38,8 +38,8 @@ var _useRegistry = _interopRequireDefault(require("../registry-provider/use-regi
|
|
|
38
38
|
* action.
|
|
39
39
|
*
|
|
40
40
|
* ```jsx
|
|
41
|
+
* import { useCallback } from 'react';
|
|
41
42
|
* import { useDispatch, useSelect } from '@wordpress/data';
|
|
42
|
-
* import { useCallback } from '@wordpress/element';
|
|
43
43
|
* import { store as myCustomStore } from 'my-custom-store';
|
|
44
44
|
*
|
|
45
45
|
* function Button( { onClick, children } ) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_useRegistry","_interopRequireDefault","require","useDispatch","storeNameOrDescriptor","dispatch","useRegistry","_default","exports","default"],"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor\n * @template {import('../../types').AnyConfig} StoreConfig\n */\n/**\n * @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn\n * @template StoreNameOrDescriptor\n */\n\n/**\n * A custom react hook returning the current registry dispatch actions creators.\n *\n * Note: The component using this hook must be within the context of a\n * RegistryProvider.\n *\n * @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor\n * @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the\n * store or its descriptor from which to\n * retrieve action creators. If not\n * provided, the registry.dispatch\n * function is returned instead.\n *\n * @example\n * This illustrates a pattern where you may need to retrieve dynamic data from\n * the server via the `useSelect` hook to use in combination with the dispatch\n * action.\n *\n * ```jsx\n * import {
|
|
1
|
+
{"version":3,"names":["_useRegistry","_interopRequireDefault","require","useDispatch","storeNameOrDescriptor","dispatch","useRegistry","_default","exports","default"],"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor\n * @template {import('../../types').AnyConfig} StoreConfig\n */\n/**\n * @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn\n * @template StoreNameOrDescriptor\n */\n\n/**\n * A custom react hook returning the current registry dispatch actions creators.\n *\n * Note: The component using this hook must be within the context of a\n * RegistryProvider.\n *\n * @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor\n * @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the\n * store or its descriptor from which to\n * retrieve action creators. If not\n * provided, the registry.dispatch\n * function is returned instead.\n *\n * @example\n * This illustrates a pattern where you may need to retrieve dynamic data from\n * the server via the `useSelect` hook to use in combination with the dispatch\n * action.\n *\n * ```jsx\n * import { useCallback } from 'react';\n * import { useDispatch, useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>\n * }\n *\n * const SaleButton = ( { children } ) => {\n * const { stockNumber } = useSelect(\n * ( select ) => select( myCustomStore ).getStockNumber(),\n * []\n * );\n * const { startSale } = useDispatch( myCustomStore );\n * const onClick = useCallback( () => {\n * const discountPercent = stockNumber > 50 ? 10: 20;\n * startSale( discountPercent );\n * }, [ stockNumber ] );\n * return <Button onClick={ onClick }>{ children }</Button>\n * }\n *\n * // Rendered somewhere in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n * @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook.\n */\nconst useDispatch = ( storeNameOrDescriptor ) => {\n\tconst { dispatch } = useRegistry();\n\treturn storeNameOrDescriptor === void 0\n\t\t? dispatch\n\t\t: dispatch( storeNameOrDescriptor );\n};\n\nexport default useDispatch;\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAKC,qBAAqB,IAAM;EAChD,MAAM;IAAEC;EAAS,CAAC,GAAG,IAAAC,oBAAW,EAAC,CAAC;EAClC,OAAOF,qBAAqB,KAAK,KAAK,CAAC,GACpCC,QAAQ,GACRA,QAAQ,CAAED,qBAAsB,CAAC;AACrC,CAAC;AAAC,IAAAG,QAAA,GAEaJ,WAAW;AAAAK,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _react = require("react");
|
|
8
8
|
var _compose = require("@wordpress/compose");
|
|
9
9
|
var _useDispatch = require("../use-dispatch");
|
|
10
10
|
/**
|
|
@@ -15,7 +15,7 @@ var _useDispatch = require("../use-dispatch");
|
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
/** @typedef {import('
|
|
18
|
+
/** @typedef {import('react').ComponentType} ComponentType */
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Higher-order component used to add dispatch props using registered action
|
|
@@ -96,12 +96,12 @@ var _useDispatch = require("../use-dispatch");
|
|
|
96
96
|
* returns an object with the same keys. For example, it should not contain
|
|
97
97
|
* conditions under which a different value would be returned.
|
|
98
98
|
*
|
|
99
|
-
* @return {
|
|
99
|
+
* @return {ComponentType} Enhanced component with merged dispatcher props.
|
|
100
100
|
*/
|
|
101
101
|
const withDispatch = mapDispatchToProps => (0, _compose.createHigherOrderComponent)(WrappedComponent => ownProps => {
|
|
102
102
|
const mapDispatch = (dispatch, registry) => mapDispatchToProps(dispatch, ownProps, registry);
|
|
103
103
|
const dispatchProps = (0, _useDispatch.useDispatchWithMap)(mapDispatch, []);
|
|
104
|
-
return (0,
|
|
104
|
+
return (0, _react.createElement)(WrappedComponent, {
|
|
105
105
|
...ownProps,
|
|
106
106
|
...dispatchProps
|
|
107
107
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_compose","require","_useDispatch","withDispatch","mapDispatchToProps","createHigherOrderComponent","WrappedComponent","ownProps","mapDispatch","dispatch","registry","dispatchProps","useDispatchWithMap","
|
|
1
|
+
{"version":3,"names":["_compose","require","_useDispatch","withDispatch","mapDispatchToProps","createHigherOrderComponent","WrappedComponent","ownProps","mapDispatch","dispatch","registry","dispatchProps","useDispatchWithMap","_react","createElement","_default","exports","default"],"sources":["@wordpress/data/src/components/with-dispatch/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { useDispatchWithMap } from '../use-dispatch';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to add dispatch props using registered action\n * creators.\n *\n * @param {Function} mapDispatchToProps A function of returning an object of\n * prop names where value is a\n * dispatch-bound action creator, or a\n * function to be called with the\n * component's props and returning an\n * action creator.\n *\n * @example\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps ) => {\n * const { startSale } = dispatch( myCustomStore );\n * const { discountPercent } = ownProps;\n *\n * return {\n * onClick() {\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton discountPercent=\"20\">Start Sale!</SaleButton>\n * ```\n *\n * @example\n * In the majority of cases, it will be sufficient to use only two first params\n * passed to `mapDispatchToProps` as illustrated in the previous example.\n * However, there might be some very advanced use cases where using the\n * `registry` object might be used as a tool to optimize the performance of\n * your component. Using `select` function from the registry might be useful\n * when you need to fetch some dynamic data from the store at the time when the\n * event is fired, but at the same time, you never use it to render your\n * component. In such scenario, you can avoid using the `withSelect` higher\n * order component to compute such prop, which might lead to unnecessary\n * re-renders of your component caused by its frequent value change.\n * Keep in mind, that `mapDispatchToProps` must return an object with functions\n * only.\n *\n * ```jsx\n * function Button( { onClick, children } ) {\n * return <button type=\"button\" onClick={ onClick }>{ children }</button>;\n * }\n *\n * import { withDispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {\n * // Stock number changes frequently.\n * const { getStockNumber } = select( myCustomStore );\n * const { startSale } = dispatch( myCustomStore );\n * return {\n * onClick() {\n * const discountPercent = getStockNumber() > 50 ? 10 : 20;\n * startSale( discountPercent );\n * },\n * };\n * } )( Button );\n *\n * // Rendered in the application:\n * //\n * // <SaleButton>Start Sale!</SaleButton>\n * ```\n *\n * _Note:_ It is important that the `mapDispatchToProps` function always\n * returns an object with the same keys. For example, it should not contain\n * conditions under which a different value would be returned.\n *\n * @return {ComponentType} Enhanced component with merged dispatcher props.\n */\nconst withDispatch = ( mapDispatchToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) => ( ownProps ) => {\n\t\t\tconst mapDispatch = ( dispatch, registry ) =>\n\t\t\t\tmapDispatchToProps( dispatch, ownProps, registry );\n\t\t\tconst dispatchProps = useDispatchWithMap( mapDispatch, [] );\n\t\t\treturn <WrappedComponent { ...ownProps } { ...dispatchProps } />;\n\t\t},\n\t\t'withDispatch'\n\t);\n\nexport default withDispatch;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,YAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,YAAY,GAAKC,kBAAkB,IACxC,IAAAC,mCAA0B,EACvBC,gBAAgB,IAAQC,QAAQ,IAAM;EACvC,MAAMC,WAAW,GAAGA,CAAEC,QAAQ,EAAEC,QAAQ,KACvCN,kBAAkB,CAAEK,QAAQ,EAAEF,QAAQ,EAAEG,QAAS,CAAC;EACnD,MAAMC,aAAa,GAAG,IAAAC,+BAAkB,EAAEJ,WAAW,EAAE,EAAG,CAAC;EAC3D,OAAO,IAAAK,MAAA,CAAAC,aAAA,EAACR,gBAAgB;IAAA,GAAMC,QAAQ;IAAA,GAAQI;EAAa,CAAI,CAAC;AACjE,CAAC,EACD,cACD,CAAC;AAAC,IAAAI,QAAA,GAEYZ,YAAY;AAAAa,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _react = require("react");
|
|
8
8
|
var _compose = require("@wordpress/compose");
|
|
9
9
|
var _registryProvider = require("../registry-provider");
|
|
10
10
|
/**
|
|
@@ -19,11 +19,11 @@ var _registryProvider = require("../registry-provider");
|
|
|
19
19
|
* Higher-order component which renders the original component with the current
|
|
20
20
|
* registry context passed as its `registry` prop.
|
|
21
21
|
*
|
|
22
|
-
* @param {
|
|
22
|
+
* @param {Component} OriginalComponent Original component.
|
|
23
23
|
*
|
|
24
|
-
* @return {
|
|
24
|
+
* @return {Component} Enhanced component.
|
|
25
25
|
*/
|
|
26
|
-
const withRegistry = (0, _compose.createHigherOrderComponent)(OriginalComponent => props => (0,
|
|
26
|
+
const withRegistry = (0, _compose.createHigherOrderComponent)(OriginalComponent => props => (0, _react.createElement)(_registryProvider.RegistryConsumer, null, registry => (0, _react.createElement)(OriginalComponent, {
|
|
27
27
|
...props,
|
|
28
28
|
registry: registry
|
|
29
29
|
})), 'withRegistry');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_compose","require","_registryProvider","withRegistry","createHigherOrderComponent","OriginalComponent","props","
|
|
1
|
+
{"version":3,"names":["_compose","require","_registryProvider","withRegistry","createHigherOrderComponent","OriginalComponent","props","_react","createElement","RegistryConsumer","registry","_default","exports","default"],"sources":["@wordpress/data/src/components/with-registry/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { RegistryConsumer } from '../registry-provider';\n\n/**\n * Higher-order component which renders the original component with the current\n * registry context passed as its `registry` prop.\n *\n * @param {Component} OriginalComponent Original component.\n *\n * @return {Component} Enhanced component.\n */\nconst withRegistry = createHigherOrderComponent(\n\t( OriginalComponent ) => ( props ) => (\n\t\t<RegistryConsumer>\n\t\t\t{ ( registry ) => (\n\t\t\t\t<OriginalComponent { ...props } registry={ registry } />\n\t\t\t) }\n\t\t</RegistryConsumer>\n\t),\n\t'withRegistry'\n);\n\nexport default withRegistry;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,iBAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,YAAY,GAAG,IAAAC,mCAA0B,EAC5CC,iBAAiB,IAAQC,KAAK,IAC/B,IAAAC,MAAA,CAAAC,aAAA,EAACN,iBAAA,CAAAO,gBAAgB,QACZC,QAAQ,IACX,IAAAH,MAAA,CAAAC,aAAA,EAACH,iBAAiB;EAAA,GAAMC,KAAK;EAAGI,QAAQ,EAAGA;AAAU,CAAE,CAEvC,CAClB,EACD,cACD,CAAC;AAAC,IAAAC,QAAA,GAEaR,YAAY;AAAAS,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var
|
|
8
|
+
var _react = require("react");
|
|
9
9
|
var _compose = require("@wordpress/compose");
|
|
10
10
|
var _useSelect = _interopRequireDefault(require("../use-select"));
|
|
11
11
|
/**
|
|
@@ -16,7 +16,7 @@ var _useSelect = _interopRequireDefault(require("../use-select"));
|
|
|
16
16
|
* Internal dependencies
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
-
/** @typedef {import('
|
|
19
|
+
/** @typedef {import('react').ComponentType} ComponentType */
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Higher-order component used to inject state-derived props using registered
|
|
@@ -56,12 +56,12 @@ var _useSelect = _interopRequireDefault(require("../use-select"));
|
|
|
56
56
|
* component and update automatically if the price of a hammer ever changes in
|
|
57
57
|
* the store.
|
|
58
58
|
*
|
|
59
|
-
* @return {
|
|
59
|
+
* @return {ComponentType} Enhanced component with merged state data props.
|
|
60
60
|
*/
|
|
61
61
|
const withSelect = mapSelectToProps => (0, _compose.createHigherOrderComponent)(WrappedComponent => (0, _compose.pure)(ownProps => {
|
|
62
62
|
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
|
|
63
63
|
const mergeProps = (0, _useSelect.default)(mapSelect);
|
|
64
|
-
return (0,
|
|
64
|
+
return (0, _react.createElement)(WrappedComponent, {
|
|
65
65
|
...ownProps,
|
|
66
66
|
...mergeProps
|
|
67
67
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_compose","require","_useSelect","_interopRequireDefault","withSelect","mapSelectToProps","createHigherOrderComponent","WrappedComponent","pure","ownProps","mapSelect","select","registry","mergeProps","useSelect","
|
|
1
|
+
{"version":3,"names":["_compose","require","_useSelect","_interopRequireDefault","withSelect","mapSelectToProps","createHigherOrderComponent","WrappedComponent","pure","ownProps","mapSelect","select","registry","mergeProps","useSelect","_react","createElement","_default","exports","default"],"sources":["@wordpress/data/src/components/with-select/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, pure } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param {Function} mapSelectToProps Function called on every state change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @example\n * ```js\n * import { withSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function PriceDisplay( { price, currency } ) {\n * \treturn new Intl.NumberFormat( 'en-US', {\n * \t\tstyle: 'currency',\n * \t\tcurrency,\n * \t} ).format( price );\n * }\n *\n * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {\n * \tconst { getPrice } = select( myCustomStore );\n * \tconst { currency } = ownProps;\n *\n * \treturn {\n * \t\tprice: getPrice( 'hammer', currency ),\n * \t};\n * } )( PriceDisplay );\n *\n * // Rendered in the application:\n * //\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, it will pass the price into the underlying `PriceDisplay`\n * component and update automatically if the price of a hammer ever changes in\n * the store.\n *\n * @return {ComponentType} Enhanced component with merged state data props.\n */\nconst withSelect = ( mapSelectToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tpure( ( ownProps ) => {\n\t\t\t\tconst mapSelect = ( select, registry ) =>\n\t\t\t\t\tmapSelectToProps( select, ownProps, registry );\n\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\treturn <WrappedComponent { ...ownProps } { ...mergeProps } />;\n\t\t\t} ),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"],"mappings":";;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,UAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,UAAU,GAAKC,gBAAgB,IACpC,IAAAC,mCAA0B,EACvBC,gBAAgB,IACjB,IAAAC,aAAI,EAAIC,QAAQ,IAAM;EACrB,MAAMC,SAAS,GAAGA,CAAEC,MAAM,EAAEC,QAAQ,KACnCP,gBAAgB,CAAEM,MAAM,EAAEF,QAAQ,EAAEG,QAAS,CAAC;EAC/C,MAAMC,UAAU,GAAG,IAAAC,kBAAS,EAAEJ,SAAU,CAAC;EACzC,OAAO,IAAAK,MAAA,CAAAC,aAAA,EAACT,gBAAgB;IAAA,GAAME,QAAQ;IAAA,GAAQI;EAAU,CAAI,CAAC;AAC9D,CAAE,CAAC,EACJ,YACD,CAAC;AAAC,IAAAI,QAAA,GAEYb,UAAU;AAAAc,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
package/build/index.js
CHANGED
|
@@ -22,7 +22,12 @@ Object.defineProperty(exports, "RegistryProvider", {
|
|
|
22
22
|
return _registryProvider.RegistryProvider;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
exports
|
|
25
|
+
Object.defineProperty(exports, "combineReducers", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _reduxStore.combineReducers;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
26
31
|
Object.defineProperty(exports, "controls", {
|
|
27
32
|
enumerable: true,
|
|
28
33
|
get: function () {
|
|
@@ -109,7 +114,6 @@ Object.defineProperty(exports, "withSelect", {
|
|
|
109
114
|
return _withSelect.default;
|
|
110
115
|
}
|
|
111
116
|
});
|
|
112
|
-
var _turboCombineReducers = _interopRequireDefault(require("turbo-combine-reducers"));
|
|
113
117
|
var _defaultRegistry = _interopRequireDefault(require("./default-registry"));
|
|
114
118
|
var plugins = _interopRequireWildcard(require("./plugins"));
|
|
115
119
|
exports.plugins = plugins;
|
|
@@ -123,15 +127,11 @@ var _asyncModeProvider = require("./components/async-mode-provider");
|
|
|
123
127
|
var _registry = require("./registry");
|
|
124
128
|
var _factory = require("./factory");
|
|
125
129
|
var _controls = require("./controls");
|
|
126
|
-
var _reduxStore =
|
|
130
|
+
var _reduxStore = _interopRequireWildcard(require("./redux-store"));
|
|
127
131
|
var _dispatch = require("./dispatch");
|
|
128
132
|
var _select = require("./select");
|
|
129
133
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
130
134
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
131
|
-
/**
|
|
132
|
-
* External dependencies
|
|
133
|
-
*/
|
|
134
|
-
|
|
135
135
|
/**
|
|
136
136
|
* Internal dependencies
|
|
137
137
|
*/
|
|
@@ -185,7 +185,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
185
185
|
* @return {Function} A reducer that invokes every reducer inside the reducers
|
|
186
186
|
* object, and constructs a state object with the same shape.
|
|
187
187
|
*/
|
|
188
|
-
const combineReducers = _turboCombineReducers.default;
|
|
189
188
|
|
|
190
189
|
/**
|
|
191
190
|
* Given a store descriptor, returns an object containing the store's selectors pre-bound to state
|
|
@@ -206,7 +205,6 @@ const combineReducers = _turboCombineReducers.default;
|
|
|
206
205
|
*
|
|
207
206
|
* @return {Object} Object containing the store's promise-wrapped selectors.
|
|
208
207
|
*/
|
|
209
|
-
exports.combineReducers = combineReducers;
|
|
210
208
|
const resolveSelect = _defaultRegistry.default.resolveSelect;
|
|
211
209
|
|
|
212
210
|
/**
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_turboCombineReducers","_interopRequireDefault","require","_defaultRegistry","plugins","_interopRequireWildcard","exports","_withSelect","_withDispatch","_withRegistry","_registryProvider","_useSelect","_useDispatch","_asyncModeProvider","_registry","_factory","_controls","_reduxStore","_dispatch","_select","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","combineReducers","turboCombineReducers","resolveSelect","defaultRegistry","suspendSelect","subscribe","registerGenericStore","registerStore","use","register"],"sources":["@wordpress/data/src/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport turboCombineReducers from 'turbo-combine-reducers';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n *\n * @type {Object}\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport const combineReducers = turboCombineReducers;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they return promises\n * that resolve to their eventual values, after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = defaultRegistry.resolveSelect;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = defaultRegistry.suspendSelect;\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = defaultRegistry.subscribe;\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore = defaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = defaultRegistry.register;\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"names":["_defaultRegistry","_interopRequireDefault","require","plugins","_interopRequireWildcard","exports","_withSelect","_withDispatch","_withRegistry","_registryProvider","_useSelect","_useDispatch","_asyncModeProvider","_registry","_factory","_controls","_reduxStore","_dispatch","_select","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","resolveSelect","defaultRegistry","suspendSelect","subscribe","registerGenericStore","registerStore","use","register"],"sources":["@wordpress/data/src/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n *\n * @type {Object}\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @type {import('./types').combineReducers}\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport { combineReducers } from './redux-store';\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they return promises\n * that resolve to their eventual values, after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = defaultRegistry.resolveSelect;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = defaultRegistry.suspendSelect;\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = defaultRegistry.subscribe;\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore = defaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = defaultRegistry.register;\n"],"mappings":"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"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.combineReducers = combineReducers;
|
|
7
|
+
function combineReducers(reducers) {
|
|
8
|
+
const keys = Object.keys(reducers);
|
|
9
|
+
return function combinedReducer(state = {}, action) {
|
|
10
|
+
const nextState = {};
|
|
11
|
+
let hasChanged = false;
|
|
12
|
+
for (const key of keys) {
|
|
13
|
+
const reducer = reducers[key];
|
|
14
|
+
const prevStateForKey = state[key];
|
|
15
|
+
const nextStateForKey = reducer(prevStateForKey, action);
|
|
16
|
+
nextState[key] = nextStateForKey;
|
|
17
|
+
hasChanged = hasChanged || nextStateForKey !== prevStateForKey;
|
|
18
|
+
}
|
|
19
|
+
return hasChanged ? nextState : state;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=combine-reducers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["combineReducers","reducers","keys","Object","combinedReducer","state","action","nextState","hasChanged","key","reducer","prevStateForKey","nextStateForKey"],"sources":["@wordpress/data/src/redux-store/combine-reducers.js"],"sourcesContent":["export function combineReducers( reducers ) {\n\tconst keys = Object.keys( reducers );\n\n\treturn function combinedReducer( state = {}, action ) {\n\t\tconst nextState = {};\n\t\tlet hasChanged = false;\n\t\tfor ( const key of keys ) {\n\t\t\tconst reducer = reducers[ key ];\n\t\t\tconst prevStateForKey = state[ key ];\n\t\t\tconst nextStateForKey = reducer( prevStateForKey, action );\n\t\t\tnextState[ key ] = nextStateForKey;\n\t\t\thasChanged = hasChanged || nextStateForKey !== prevStateForKey;\n\t\t}\n\n\t\treturn hasChanged ? nextState : state;\n\t};\n}\n"],"mappings":";;;;;;AAAO,SAASA,eAAeA,CAAEC,QAAQ,EAAG;EAC3C,MAAMC,IAAI,GAAGC,MAAM,CAACD,IAAI,CAAED,QAAS,CAAC;EAEpC,OAAO,SAASG,eAAeA,CAAEC,KAAK,GAAG,CAAC,CAAC,EAAEC,MAAM,EAAG;IACrD,MAAMC,SAAS,GAAG,CAAC,CAAC;IACpB,IAAIC,UAAU,GAAG,KAAK;IACtB,KAAM,MAAMC,GAAG,IAAIP,IAAI,EAAG;MACzB,MAAMQ,OAAO,GAAGT,QAAQ,CAAEQ,GAAG,CAAE;MAC/B,MAAME,eAAe,GAAGN,KAAK,CAAEI,GAAG,CAAE;MACpC,MAAMG,eAAe,GAAGF,OAAO,CAAEC,eAAe,EAAEL,MAAO,CAAC;MAC1DC,SAAS,CAAEE,GAAG,CAAE,GAAGG,eAAe;MAClCJ,UAAU,GAAGA,UAAU,IAAII,eAAe,KAAKD,eAAe;IAC/D;IAEA,OAAOH,UAAU,GAAGD,SAAS,GAAGF,KAAK;EACtC,CAAC;AACF"}
|
|
@@ -4,12 +4,18 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
+
Object.defineProperty(exports, "combineReducers", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return _combineReducers.combineReducers;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
7
13
|
exports.default = createReduxStore;
|
|
8
14
|
var _redux = require("redux");
|
|
9
|
-
var _turboCombineReducers = _interopRequireDefault(require("turbo-combine-reducers"));
|
|
10
15
|
var _equivalentKeyMap = _interopRequireDefault(require("equivalent-key-map"));
|
|
11
16
|
var _reduxRoutine = _interopRequireDefault(require("@wordpress/redux-routine"));
|
|
12
17
|
var _compose = require("@wordpress/compose");
|
|
18
|
+
var _combineReducers = require("./combine-reducers");
|
|
13
19
|
var _controls = require("../controls");
|
|
14
20
|
var _lockUnlock = require("../lock-unlock");
|
|
15
21
|
var _promiseMiddleware = _interopRequireDefault(require("../promise-middleware"));
|
|
@@ -41,7 +47,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
41
47
|
/**
|
|
42
48
|
* @typedef {import('../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
|
|
43
49
|
* @template State
|
|
44
|
-
* @template {Record<string,import('
|
|
50
|
+
* @template {Record<string,import('../types').ActionCreator>} Actions
|
|
45
51
|
* @template Selectors
|
|
46
52
|
*/
|
|
47
53
|
|
|
@@ -128,7 +134,7 @@ function createBindingCache(bind) {
|
|
|
128
134
|
* ```
|
|
129
135
|
*
|
|
130
136
|
* @template State
|
|
131
|
-
* @template {Record<string,import('
|
|
137
|
+
* @template {Record<string,import('../types').ActionCreator>} Actions
|
|
132
138
|
* @template Selectors
|
|
133
139
|
* @param {string} key Unique namespace identifier.
|
|
134
140
|
* @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties
|
|
@@ -334,7 +340,7 @@ function instantiateReduxStore(key, options, registry, thunkArgs) {
|
|
|
334
340
|
reducer,
|
|
335
341
|
initialState
|
|
336
342
|
} = options;
|
|
337
|
-
const enhancedReducer = (0,
|
|
343
|
+
const enhancedReducer = (0, _combineReducers.combineReducers)({
|
|
338
344
|
metadata: _reducer.default,
|
|
339
345
|
root: reducer
|
|
340
346
|
});
|