@wordpress/data 9.9.0 → 9.10.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/build/components/async-mode-provider/context.js +2 -3
- package/build/components/async-mode-provider/context.js.map +1 -1
- package/build/components/async-mode-provider/index.js +0 -5
- package/build/components/async-mode-provider/index.js.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.js +1 -3
- package/build/components/async-mode-provider/use-async-mode.js.map +1 -1
- package/build/components/registry-provider/context.js +3 -6
- package/build/components/registry-provider/context.js.map +1 -1
- package/build/components/registry-provider/index.js +0 -5
- package/build/components/registry-provider/index.js.map +1 -1
- package/build/components/registry-provider/use-registry.js +0 -3
- package/build/components/registry-provider/use-registry.js.map +1 -1
- package/build/components/use-dispatch/index.js +0 -3
- package/build/components/use-dispatch/index.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +0 -7
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +0 -5
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/use-select/index.js +35 -53
- package/build/components/use-select/index.js.map +1 -1
- package/build/components/with-dispatch/index.js +2 -7
- package/build/components/with-dispatch/index.js.map +1 -1
- package/build/components/with-registry/index.js +2 -5
- package/build/components/with-registry/index.js.map +1 -1
- package/build/components/with-select/index.js +2 -8
- package/build/components/with-select/index.js.map +1 -1
- package/build/controls.js +4 -10
- package/build/controls.js.map +1 -1
- package/build/default-registry.js +0 -3
- package/build/default-registry.js.map +1 -1
- package/build/dispatch.js +0 -3
- package/build/dispatch.js.map +1 -1
- package/build/factory.js +2 -5
- package/build/factory.js.map +1 -1
- package/build/index.js +7 -28
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/plugins/index.js +0 -2
- package/build/plugins/index.js.map +1 -1
- package/build/plugins/persistence/index.js +13 -37
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/plugins/persistence/storage/default.js +1 -5
- package/build/plugins/persistence/storage/default.js.map +1 -1
- package/build/plugins/persistence/storage/object.js +0 -5
- package/build/plugins/persistence/storage/object.js.map +1 -1
- package/build/promise-middleware.js +0 -5
- package/build/promise-middleware.js.map +1 -1
- package/build/redux-store/index.js +36 -117
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/actions.js +8 -17
- package/build/redux-store/metadata/actions.js.map +1 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js.map +1 -1
- package/build/redux-store/metadata/reducer.js +1 -23
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +8 -22
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +6 -14
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/redux-store/thunk-middleware.js +0 -2
- package/build/redux-store/thunk-middleware.js.map +1 -1
- package/build/registry.js +29 -73
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +2 -8
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/select.js +0 -3
- package/build/select.js.map +1 -1
- package/build/store/index.js +0 -7
- package/build/store/index.js.map +1 -1
- package/build/types.js.map +1 -1
- package/build/utils/emitter.js +2 -11
- package/build/utils/emitter.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/async-mode-provider/index.js.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.js +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.js.map +1 -1
- package/build-module/components/registry-provider/context.js +3 -3
- package/build-module/components/registry-provider/context.js.map +1 -1
- package/build-module/components/registry-provider/index.js.map +1 -1
- package/build-module/components/registry-provider/use-registry.js +2 -2
- package/build-module/components/registry-provider/use-registry.js.map +1 -1
- package/build-module/components/use-dispatch/index.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +2 -4
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +1 -3
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/use-select/index.js +35 -46
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/components/with-dispatch/index.js +4 -6
- package/build-module/components/with-dispatch/index.js.map +1 -1
- package/build-module/components/with-registry/index.js +4 -4
- package/build-module/components/with-registry/index.js.map +1 -1
- package/build-module/components/with-select/index.js +4 -6
- package/build-module/components/with-select/index.js.map +1 -1
- package/build-module/controls.js +4 -8
- package/build-module/controls.js.map +1 -1
- package/build-module/default-registry.js.map +1 -1
- package/build-module/dispatch.js +2 -1
- package/build-module/dispatch.js.map +1 -1
- package/build-module/factory.js +2 -3
- package/build-module/factory.js.map +1 -1
- package/build-module/index.js +11 -10
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/plugins/index.js.map +1 -1
- package/build-module/plugins/persistence/index.js +15 -30
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/plugins/persistence/storage/default.js +0 -2
- package/build-module/plugins/persistence/storage/default.js.map +1 -1
- package/build-module/plugins/persistence/storage/object.js +0 -5
- package/build-module/plugins/persistence/storage/object.js.map +1 -1
- package/build-module/promise-middleware.js +1 -3
- package/build-module/promise-middleware.js.map +1 -1
- package/build-module/redux-store/index.js +38 -101
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/actions.js +8 -8
- package/build-module/redux-store/metadata/actions.js.map +1 -1
- package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +1 -21
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +9 -13
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +6 -11
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/redux-store/thunk-middleware.js +0 -1
- package/build-module/redux-store/thunk-middleware.js.map +1 -1
- package/build-module/registry.js +30 -67
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +3 -6
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/select.js +2 -1
- package/build-module/select.js.map +1 -1
- package/build-module/store/index.js +0 -7
- package/build-module/store/index.js.map +1 -1
- package/build-module/types.js.map +1 -1
- package/build-module/utils/emitter.js +2 -10
- package/build-module/utils/emitter.js.map +1 -1
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/index.d.ts.map +1 -1
- package/build-types/private-apis.d.ts +3 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/store/index.d.ts +1 -1
- package/package.json +9 -9
- package/src/components/use-select/index.js +14 -0
- package/src/plugins/persistence/index.js +0 -1
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 9.10.0 (2023-08-16)
|
|
6
|
+
|
|
7
|
+
### Enhancements
|
|
8
|
+
|
|
9
|
+
- Warn if the `useSelect` hook returns different values when called with the same state and parameters ([#53666](https://github.com/WordPress/gutenberg/pull/53666)).
|
|
10
|
+
|
|
5
11
|
## 9.9.0 (2023-08-10)
|
|
6
12
|
|
|
7
13
|
### Bug Fix
|
|
@@ -4,12 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = exports.Context = exports.AsyncModeConsumer = void 0;
|
|
7
|
-
|
|
8
7
|
var _element = require("@wordpress/element");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* WordPress dependencies
|
|
12
10
|
*/
|
|
11
|
+
|
|
13
12
|
const Context = (0, _element.createContext)(false);
|
|
14
13
|
exports.Context = Context;
|
|
15
14
|
const {
|
|
@@ -17,6 +16,7 @@ const {
|
|
|
17
16
|
Provider
|
|
18
17
|
} = Context;
|
|
19
18
|
const AsyncModeConsumer = Consumer;
|
|
19
|
+
|
|
20
20
|
/**
|
|
21
21
|
* Context Provider Component used to switch the data module component rerendering
|
|
22
22
|
* between Sync and Async modes.
|
|
@@ -52,7 +52,6 @@ const AsyncModeConsumer = Consumer;
|
|
|
52
52
|
* @param {boolean} props.value Enable Async Mode.
|
|
53
53
|
* @return {WPComponent} The component to be rendered.
|
|
54
54
|
*/
|
|
55
|
-
|
|
56
55
|
exports.AsyncModeConsumer = AsyncModeConsumer;
|
|
57
56
|
var _default = Provider;
|
|
58
57
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 {WPComponent} 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"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -23,12 +22,8 @@ Object.defineProperty(exports, "useAsyncMode", {
|
|
|
23
22
|
return _useAsyncMode.default;
|
|
24
23
|
}
|
|
25
24
|
});
|
|
26
|
-
|
|
27
25
|
var _useAsyncMode = _interopRequireDefault(require("./use-async-mode"));
|
|
28
|
-
|
|
29
26
|
var _context = _interopRequireWildcard(require("./context"));
|
|
30
|
-
|
|
31
27
|
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); }
|
|
32
|
-
|
|
33
28
|
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; }
|
|
34
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/async-mode-provider/index.js"],"
|
|
1
|
+
{"version":3,"names":["_useAsyncMode","_interopRequireDefault","require","_context","_interopRequireWildcard","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sources":["@wordpress/data/src/components/async-mode-provider/index.js"],"sourcesContent":["export { default as useAsyncMode } from './use-async-mode';\nexport { default as AsyncModeProvider, AsyncModeConsumer } from './context';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAC,uBAAA,CAAAF,OAAA;AAA4E,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAF,wBAAAM,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA"}
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = useAsyncMode;
|
|
7
|
-
|
|
8
7
|
var _element = require("@wordpress/element");
|
|
9
|
-
|
|
10
8
|
var _context = require("./context");
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* WordPress dependencies
|
|
14
11
|
*/
|
|
@@ -16,6 +13,7 @@ var _context = require("./context");
|
|
|
16
13
|
/**
|
|
17
14
|
* Internal dependencies
|
|
18
15
|
*/
|
|
16
|
+
|
|
19
17
|
function useAsyncMode() {
|
|
20
18
|
return (0, _element.useContext)(_context.Context);
|
|
21
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/async-mode-provider/use-async-mode.js"],"
|
|
1
|
+
{"version":3,"names":["_element","require","_context","useAsyncMode","useContext","Context"],"sources":["@wordpress/data/src/components/async-mode-provider/use-async-mode.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\n\nexport default function useAsyncMode() {\n\treturn useContext( Context );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGe,SAASE,YAAYA,CAAA,EAAG;EACtC,OAAO,IAAAC,mBAAU,EAAEC,gBAAQ,CAAC;AAC7B"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = exports.RegistryConsumer = exports.Context = void 0;
|
|
9
|
-
|
|
10
8
|
var _element = require("@wordpress/element");
|
|
11
|
-
|
|
12
9
|
var _defaultRegistry = _interopRequireDefault(require("../../default-registry"));
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* WordPress dependencies
|
|
16
12
|
*/
|
|
@@ -18,12 +14,14 @@ var _defaultRegistry = _interopRequireDefault(require("../../default-registry"))
|
|
|
18
14
|
/**
|
|
19
15
|
* Internal dependencies
|
|
20
16
|
*/
|
|
17
|
+
|
|
21
18
|
const Context = (0, _element.createContext)(_defaultRegistry.default);
|
|
22
19
|
exports.Context = Context;
|
|
23
20
|
const {
|
|
24
21
|
Consumer,
|
|
25
22
|
Provider
|
|
26
23
|
} = Context;
|
|
24
|
+
|
|
27
25
|
/**
|
|
28
26
|
* A custom react Context consumer exposing the provided `registry` to
|
|
29
27
|
* children components. Used along with the RegistryProvider.
|
|
@@ -55,8 +53,8 @@ const {
|
|
|
55
53
|
* }
|
|
56
54
|
* ```
|
|
57
55
|
*/
|
|
58
|
-
|
|
59
56
|
const RegistryConsumer = Consumer;
|
|
57
|
+
|
|
60
58
|
/**
|
|
61
59
|
* A custom Context provider for exposing the provided `registry` to children
|
|
62
60
|
* components via a consumer.
|
|
@@ -64,7 +62,6 @@ const RegistryConsumer = Consumer;
|
|
|
64
62
|
* See <a name="#RegistryConsumer">RegistryConsumer</a> documentation for
|
|
65
63
|
* example.
|
|
66
64
|
*/
|
|
67
|
-
|
|
68
65
|
exports.RegistryConsumer = RegistryConsumer;
|
|
69
66
|
var _default = Provider;
|
|
70
67
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_element","require","_defaultRegistry","_interopRequireDefault","Context","createContext","defaultRegistry","exports","Consumer","Provider","RegistryConsumer","_default","default"],"sources":["@wordpress/data/src/components/registry-provider/context.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from '../../default-registry';\n\nexport const Context = createContext( defaultRegistry );\n\nconst { Consumer, Provider } = Context;\n\n/**\n * A custom react Context consumer exposing the provided `registry` to\n * children components. Used along with the RegistryProvider.\n *\n * You can read more about the react context api here:\n * https://reactjs.org/docs/context.html#contextprovider\n *\n * @example\n * ```js\n * import {\n * RegistryProvider,\n * RegistryConsumer,\n * createRegistry\n * } from '@wordpress/data';\n *\n * const registry = createRegistry( {} );\n *\n * const App = ( { props } ) => {\n * return <RegistryProvider value={ registry }>\n * <div>Hello There</div>\n * <RegistryConsumer>\n * { ( registry ) => (\n * <ComponentUsingRegistry\n * \t\t{ ...props }\n * \t registry={ registry }\n * ) }\n * </RegistryConsumer>\n * </RegistryProvider>\n * }\n * ```\n */\nexport const RegistryConsumer = Consumer;\n\n/**\n * A custom Context provider for exposing the provided `registry` to children\n * components via a consumer.\n *\n * See <a name=\"#RegistryConsumer\">RegistryConsumer</a> documentation for\n * example.\n */\nexport default Provider;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,gBAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGO,MAAMG,OAAO,GAAG,IAAAC,sBAAa,EAAEC,wBAAgB,CAAC;AAACC,OAAA,CAAAH,OAAA,GAAAA,OAAA;AAExD,MAAM;EAAEI,QAAQ;EAAEC;AAAS,CAAC,GAAGL,OAAO;;AAEtC;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;AACO,MAAMM,gBAAgB,GAAGF,QAAQ;;AAExC;AACA;AACA;AACA;AACA;AACA;AACA;AANAD,OAAA,CAAAG,gBAAA,GAAAA,gBAAA;AAAA,IAAAC,QAAA,GAOeF,QAAQ;AAAAF,OAAA,CAAAK,OAAA,GAAAD,QAAA"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -23,12 +22,8 @@ Object.defineProperty(exports, "useRegistry", {
|
|
|
23
22
|
return _useRegistry.default;
|
|
24
23
|
}
|
|
25
24
|
});
|
|
26
|
-
|
|
27
25
|
var _context = _interopRequireWildcard(require("./context"));
|
|
28
|
-
|
|
29
26
|
var _useRegistry = _interopRequireDefault(require("./use-registry"));
|
|
30
|
-
|
|
31
27
|
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); }
|
|
32
|
-
|
|
33
28
|
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; }
|
|
34
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/registry-provider/index.js"],"
|
|
1
|
+
{"version":3,"names":["_context","_interopRequireWildcard","require","_useRegistry","_interopRequireDefault","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set"],"sources":["@wordpress/data/src/components/registry-provider/index.js"],"sourcesContent":["export { default as RegistryProvider, RegistryConsumer } from './context';\nexport { default as useRegistry } from './use-registry';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,QAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAwD,SAAAG,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAL,wBAAAS,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/registry-provider/use-registry.js"],"
|
|
1
|
+
{"version":3,"names":["_element","require","_context","useRegistry","useContext","Context"],"sources":["@wordpress/data/src/components/registry-provider/use-registry.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { Context } from './context';\n\n/**\n * A custom react hook exposing the registry context for use.\n *\n * This exposes the `registry` value provided via the\n * <a href=\"#RegistryProvider\">Registry Provider</a> to a component implementing\n * this hook.\n *\n * It acts similarly to the `useContext` react hook.\n *\n * Note: Generally speaking, `useRegistry` is a low level hook that in most cases\n * won't be needed for implementation. Most interactions with the `@wordpress/data`\n * API can be performed via the `useSelect` hook, or the `withSelect` and\n * `withDispatch` higher order components.\n *\n * @example\n * ```js\n * import {\n * RegistryProvider,\n * createRegistry,\n * useRegistry,\n * } from '@wordpress/data';\n *\n * const registry = createRegistry( {} );\n *\n * const SomeChildUsingRegistry = ( props ) => {\n * const registry = useRegistry();\n * // ...logic implementing the registry in other react hooks.\n * };\n *\n *\n * const ParentProvidingRegistry = ( props ) => {\n * return <RegistryProvider value={ registry }>\n * <SomeChildUsingRegistry { ...props } />\n * </RegistryProvider>\n * };\n * ```\n *\n * @return {Function} A custom react hook exposing the registry context value.\n */\nexport default function useRegistry() {\n\treturn useContext( Context );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;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;AACe,SAASE,WAAWA,CAAA,EAAG;EACrC,OAAO,IAAAC,mBAAU,EAAEC,gBAAQ,CAAC;AAC7B"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -17,8 +16,6 @@ Object.defineProperty(exports, "useDispatchWithMap", {
|
|
|
17
16
|
return _useDispatchWithMap.default;
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
|
-
|
|
21
19
|
var _useDispatch = _interopRequireDefault(require("./use-dispatch"));
|
|
22
|
-
|
|
23
20
|
var _useDispatchWithMap = _interopRequireDefault(require("./use-dispatch-with-map"));
|
|
24
21
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/use-dispatch/index.js"],"
|
|
1
|
+
{"version":3,"names":["_useDispatch","_interopRequireDefault","require","_useDispatchWithMap"],"sources":["@wordpress/data/src/components/use-dispatch/index.js"],"sourcesContent":["export { default as useDispatch } from './use-dispatch';\nexport { default as useDispatchWithMap } from './use-dispatch-with-map';\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAF,sBAAA,CAAAC,OAAA"}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _element = require("@wordpress/element");
|
|
11
|
-
|
|
12
9
|
var _compose = require("@wordpress/compose");
|
|
13
|
-
|
|
14
10
|
var _useRegistry = _interopRequireDefault(require("../registry-provider/use-registry"));
|
|
15
|
-
|
|
16
11
|
/**
|
|
17
12
|
* WordPress dependencies
|
|
18
13
|
*/
|
|
@@ -48,12 +43,10 @@ const useDispatchWithMap = (dispatchMap, deps) => {
|
|
|
48
43
|
// eslint-disable-next-line no-console
|
|
49
44
|
console.warn(`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`);
|
|
50
45
|
}
|
|
51
|
-
|
|
52
46
|
return [propName, (...args) => currentDispatchMap.current(registry.dispatch, registry)[propName](...args)];
|
|
53
47
|
}));
|
|
54
48
|
}, [registry, ...deps]);
|
|
55
49
|
};
|
|
56
|
-
|
|
57
50
|
var _default = useDispatchWithMap;
|
|
58
51
|
exports.default = _default;
|
|
59
52
|
//# sourceMappingURL=use-dispatch-with-map.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_element","require","_compose","_useRegistry","_interopRequireDefault","useDispatchWithMap","dispatchMap","deps","registry","useRegistry","currentDispatchMap","useRef","useIsomorphicLayoutEffect","current","useMemo","currentDispatchProps","dispatch","Object","fromEntries","entries","map","propName","dispatcher","console","warn","args","_default","exports","default"],"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch-with-map.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useRef } from '@wordpress/element';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * Custom react hook for returning aggregate dispatch actions using the provided\n * dispatchMap.\n *\n * Currently this is an internal api only and is implemented by `withDispatch`\n *\n * @param {Function} dispatchMap Receives the `registry.dispatch` function as\n * the first argument and the `registry` object\n * as the second argument. Should return an\n * object mapping props to functions.\n * @param {Array} deps An array of dependencies for the hook.\n * @return {Object} An object mapping props to functions created by the passed\n * in dispatchMap.\n */\nconst useDispatchWithMap = ( dispatchMap, deps ) => {\n\tconst registry = useRegistry();\n\tconst currentDispatchMap = useRef( dispatchMap );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tcurrentDispatchMap.current = dispatchMap;\n\t} );\n\n\treturn useMemo( () => {\n\t\tconst currentDispatchProps = currentDispatchMap.current(\n\t\t\tregistry.dispatch,\n\t\t\tregistry\n\t\t);\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( currentDispatchProps ).map(\n\t\t\t\t( [ propName, dispatcher ] ) => {\n\t\t\t\t\tif ( typeof dispatcher !== 'function' ) {\n\t\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`Property ${ propName } returned from dispatchMap in useDispatchWithMap must be a function.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn [\n\t\t\t\t\t\tpropName,\n\t\t\t\t\t\t( ...args ) =>\n\t\t\t\t\t\t\tcurrentDispatchMap\n\t\t\t\t\t\t\t\t.current( registry.dispatch, registry )\n\t\t\t\t\t\t\t\t[ propName ]( ...args ),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\t}, [ registry, ...deps ] );\n};\n\nexport default useDispatchWithMap;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,YAAA,GAAAC,sBAAA,CAAAH,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,kBAAkB,GAAGA,CAAEC,WAAW,EAAEC,IAAI,KAAM;EACnD,MAAMC,QAAQ,GAAG,IAAAC,oBAAW,EAAC,CAAC;EAC9B,MAAMC,kBAAkB,GAAG,IAAAC,eAAM,EAAEL,WAAY,CAAC;EAEhD,IAAAM,kCAAyB,EAAE,MAAM;IAChCF,kBAAkB,CAACG,OAAO,GAAGP,WAAW;EACzC,CAAE,CAAC;EAEH,OAAO,IAAAQ,gBAAO,EAAE,MAAM;IACrB,MAAMC,oBAAoB,GAAGL,kBAAkB,CAACG,OAAO,CACtDL,QAAQ,CAACQ,QAAQ,EACjBR,QACD,CAAC;IACD,OAAOS,MAAM,CAACC,WAAW,CACxBD,MAAM,CAACE,OAAO,CAAEJ,oBAAqB,CAAC,CAACK,GAAG,CACzC,CAAE,CAAEC,QAAQ,EAAEC,UAAU,CAAE,KAAM;MAC/B,IAAK,OAAOA,UAAU,KAAK,UAAU,EAAG;QACvC;QACAC,OAAO,CAACC,IAAI,CACV,YAAYH,QAAU,sEACxB,CAAC;MACF;MACA,OAAO,CACNA,QAAQ,EACR,CAAE,GAAGI,IAAI,KACRf,kBAAkB,CAChBG,OAAO,CAAEL,QAAQ,CAACQ,QAAQ,EAAER,QAAS,CAAC,CACrCa,QAAQ,CAAE,CAAE,GAAGI,IAAK,CAAC,CACzB;IACF,CACD,CACD,CAAC;EACF,CAAC,EAAE,CAAEjB,QAAQ,EAAE,GAAGD,IAAI,CAAG,CAAC;AAC3B,CAAC;AAAC,IAAAmB,QAAA,GAEarB,kBAAkB;AAAAsB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
|
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _useRegistry = _interopRequireDefault(require("../registry-provider/use-registry"));
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* Internal dependencies
|
|
14
11
|
*/
|
|
@@ -17,7 +14,6 @@ var _useRegistry = _interopRequireDefault(require("../registry-provider/use-regi
|
|
|
17
14
|
* @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor
|
|
18
15
|
* @template {import('../../types').AnyConfig} StoreConfig
|
|
19
16
|
*/
|
|
20
|
-
|
|
21
17
|
/**
|
|
22
18
|
* @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn
|
|
23
19
|
* @template StoreNameOrDescriptor
|
|
@@ -75,7 +71,6 @@ const useDispatch = storeNameOrDescriptor => {
|
|
|
75
71
|
} = (0, _useRegistry.default)();
|
|
76
72
|
return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor);
|
|
77
73
|
};
|
|
78
|
-
|
|
79
74
|
var _default = useDispatch;
|
|
80
75
|
exports.default = _default;
|
|
81
76
|
//# sourceMappingURL=use-dispatch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 { useDispatch, useSelect } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\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"}
|
|
@@ -1,23 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = useSelect;
|
|
9
8
|
exports.useSuspenseSelect = useSuspenseSelect;
|
|
10
|
-
|
|
11
9
|
var _priorityQueue = require("@wordpress/priority-queue");
|
|
12
|
-
|
|
13
10
|
var _element = require("@wordpress/element");
|
|
14
|
-
|
|
15
11
|
var _isShallowEqual = _interopRequireDefault(require("@wordpress/is-shallow-equal"));
|
|
16
|
-
|
|
17
12
|
var _useRegistry = _interopRequireDefault(require("../registry-provider/use-registry"));
|
|
18
|
-
|
|
19
13
|
var _useAsyncMode = _interopRequireDefault(require("../async-mode-provider/use-async-mode"));
|
|
20
|
-
|
|
21
14
|
/**
|
|
22
15
|
* WordPress dependencies
|
|
23
16
|
*/
|
|
@@ -25,21 +18,20 @@ var _useAsyncMode = _interopRequireDefault(require("../async-mode-provider/use-a
|
|
|
25
18
|
/**
|
|
26
19
|
* Internal dependencies
|
|
27
20
|
*/
|
|
21
|
+
|
|
28
22
|
const renderQueue = (0, _priorityQueue.createQueue)();
|
|
23
|
+
|
|
29
24
|
/**
|
|
30
25
|
* @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor
|
|
31
26
|
* @template {import('../../types').AnyConfig} C
|
|
32
27
|
*/
|
|
33
|
-
|
|
34
28
|
/**
|
|
35
29
|
* @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
|
|
36
30
|
* @template State
|
|
37
31
|
* @template {Record<string,import('../../types').ActionCreator>} Actions
|
|
38
32
|
* @template Selectors
|
|
39
33
|
*/
|
|
40
|
-
|
|
41
34
|
/** @typedef {import('../../types').MapSelect} MapSelect */
|
|
42
|
-
|
|
43
35
|
/**
|
|
44
36
|
* @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn
|
|
45
37
|
* @template {MapSelect|StoreDescriptor<any>} T
|
|
@@ -53,16 +45,16 @@ function Store(registry, suspense) {
|
|
|
53
45
|
let lastMapResultValid = false;
|
|
54
46
|
let lastIsAsync;
|
|
55
47
|
let subscriber;
|
|
56
|
-
|
|
48
|
+
let didWarnUnstableReference;
|
|
57
49
|
const createSubscriber = stores => {
|
|
58
50
|
// The set of stores the `subscribe` function is supposed to subscribe to. Here it is
|
|
59
51
|
// initialized, and then the `updateStores` function can add new stores to it.
|
|
60
|
-
const activeStores = [...stores];
|
|
52
|
+
const activeStores = [...stores];
|
|
53
|
+
|
|
54
|
+
// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could
|
|
61
55
|
// be called multiple times to establish multiple subscriptions. That's why we need to
|
|
62
56
|
// keep a set of active subscriptions;
|
|
63
|
-
|
|
64
57
|
const activeSubscriptions = new Set();
|
|
65
|
-
|
|
66
58
|
function subscribe(listener) {
|
|
67
59
|
// Invalidate the value right after subscription was created. React will
|
|
68
60
|
// call `getValue` after subscribing, to detect store updates that happened
|
|
@@ -70,13 +62,11 @@ function Store(registry, suspense) {
|
|
|
70
62
|
// the subscription, which is slightly delayed. We need to ensure that this
|
|
71
63
|
// second `getValue` call will compute a fresh value.
|
|
72
64
|
lastMapResultValid = false;
|
|
73
|
-
|
|
74
65
|
const onStoreChange = () => {
|
|
75
66
|
// Invalidate the value on store update, so that a fresh value is computed.
|
|
76
67
|
lastMapResultValid = false;
|
|
77
68
|
listener();
|
|
78
69
|
};
|
|
79
|
-
|
|
80
70
|
const onChange = () => {
|
|
81
71
|
if (lastIsAsync) {
|
|
82
72
|
renderQueue.add(queueContext, onStoreChange);
|
|
@@ -84,53 +74,46 @@ function Store(registry, suspense) {
|
|
|
84
74
|
onStoreChange();
|
|
85
75
|
}
|
|
86
76
|
};
|
|
87
|
-
|
|
88
77
|
const unsubs = [];
|
|
89
|
-
|
|
90
78
|
function subscribeStore(storeName) {
|
|
91
79
|
unsubs.push(registry.subscribe(onChange, storeName));
|
|
92
80
|
}
|
|
93
|
-
|
|
94
81
|
for (const storeName of activeStores) {
|
|
95
82
|
subscribeStore(storeName);
|
|
96
83
|
}
|
|
97
|
-
|
|
98
84
|
activeSubscriptions.add(subscribeStore);
|
|
99
85
|
return () => {
|
|
100
86
|
activeSubscriptions.delete(subscribeStore);
|
|
101
|
-
|
|
102
87
|
for (const unsub of unsubs.values()) {
|
|
103
88
|
// The return value of the subscribe function could be undefined if the store is a custom generic store.
|
|
104
89
|
unsub?.();
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
90
|
+
}
|
|
91
|
+
// Cancel existing store updates that were already scheduled.
|
|
108
92
|
renderQueue.cancel(queueContext);
|
|
109
93
|
};
|
|
110
|
-
}
|
|
111
|
-
|
|
94
|
+
}
|
|
112
95
|
|
|
96
|
+
// Check if `newStores` contains some stores we're not subscribed to yet, and add them.
|
|
113
97
|
function updateStores(newStores) {
|
|
114
98
|
for (const newStore of newStores) {
|
|
115
99
|
if (activeStores.includes(newStore)) {
|
|
116
100
|
continue;
|
|
117
|
-
}
|
|
118
|
-
|
|
101
|
+
}
|
|
119
102
|
|
|
120
|
-
|
|
103
|
+
// New `subscribe` calls will subscribe to `newStore`, too.
|
|
104
|
+
activeStores.push(newStore);
|
|
121
105
|
|
|
106
|
+
// Add `newStore` to existing subscriptions.
|
|
122
107
|
for (const subscription of activeSubscriptions) {
|
|
123
108
|
subscription(newStore);
|
|
124
109
|
}
|
|
125
110
|
}
|
|
126
111
|
}
|
|
127
|
-
|
|
128
112
|
return {
|
|
129
113
|
subscribe,
|
|
130
114
|
updateStores
|
|
131
115
|
};
|
|
132
116
|
};
|
|
133
|
-
|
|
134
117
|
return (mapSelect, isAsync) => {
|
|
135
118
|
function updateValue() {
|
|
136
119
|
// If the last value is valid, and the `mapSelect` callback hasn't changed,
|
|
@@ -139,57 +122,60 @@ function Store(registry, suspense) {
|
|
|
139
122
|
if (lastMapResultValid && mapSelect === lastMapSelect) {
|
|
140
123
|
return lastMapResult;
|
|
141
124
|
}
|
|
142
|
-
|
|
143
125
|
const listeningStores = {
|
|
144
126
|
current: null
|
|
145
127
|
};
|
|
146
|
-
|
|
147
128
|
const mapResult = registry.__unstableMarkListeningStores(() => mapSelect(select, registry), listeningStores);
|
|
148
|
-
|
|
129
|
+
if (process.env.NODE_ENV === 'development') {
|
|
130
|
+
if (!didWarnUnstableReference) {
|
|
131
|
+
const secondMapResult = mapSelect(select, registry);
|
|
132
|
+
if (!(0, _isShallowEqual.default)(mapResult, secondMapResult)) {
|
|
133
|
+
// eslint-disable-next-line no-console
|
|
134
|
+
console.warn(`The 'useSelect' hook returns different values when called with the same state and parameters. This can lead to unnecessary rerenders.`);
|
|
135
|
+
didWarnUnstableReference = true;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
149
139
|
if (!subscriber) {
|
|
150
140
|
subscriber = createSubscriber(listeningStores.current);
|
|
151
141
|
} else {
|
|
152
142
|
subscriber.updateStores(listeningStores.current);
|
|
153
|
-
}
|
|
154
|
-
// that we don't trigger unwanted updates that do a `===` check.
|
|
155
|
-
|
|
143
|
+
}
|
|
156
144
|
|
|
145
|
+
// If the new value is shallow-equal to the old one, keep the old one so
|
|
146
|
+
// that we don't trigger unwanted updates that do a `===` check.
|
|
157
147
|
if (!(0, _isShallowEqual.default)(lastMapResult, mapResult)) {
|
|
158
148
|
lastMapResult = mapResult;
|
|
159
149
|
}
|
|
160
|
-
|
|
161
150
|
lastMapSelect = mapSelect;
|
|
162
151
|
lastMapResultValid = true;
|
|
163
152
|
}
|
|
164
|
-
|
|
165
153
|
function getValue() {
|
|
166
154
|
// Update the value in case it's been invalidated or `mapSelect` has changed.
|
|
167
155
|
updateValue();
|
|
168
156
|
return lastMapResult;
|
|
169
|
-
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// When transitioning from async to sync mode, cancel existing store updates
|
|
170
160
|
// that have been scheduled, and invalidate the value so that it's freshly
|
|
171
161
|
// computed. It might have been changed by the update we just cancelled.
|
|
172
|
-
|
|
173
|
-
|
|
174
162
|
if (lastIsAsync && !isAsync) {
|
|
175
163
|
lastMapResultValid = false;
|
|
176
164
|
renderQueue.cancel(queueContext);
|
|
177
165
|
}
|
|
178
|
-
|
|
179
166
|
updateValue();
|
|
180
|
-
lastIsAsync = isAsync;
|
|
167
|
+
lastIsAsync = isAsync;
|
|
181
168
|
|
|
169
|
+
// Return a pair of functions that can be passed to `useSyncExternalStore`.
|
|
182
170
|
return {
|
|
183
171
|
subscribe: subscriber.subscribe,
|
|
184
172
|
getValue
|
|
185
173
|
};
|
|
186
174
|
};
|
|
187
175
|
}
|
|
188
|
-
|
|
189
176
|
function useStaticSelect(storeName) {
|
|
190
177
|
return (0, _useRegistry.default)().select(storeName);
|
|
191
178
|
}
|
|
192
|
-
|
|
193
179
|
function useMappingSelect(suspense, mapSelect, deps) {
|
|
194
180
|
const registry = (0, _useRegistry.default)();
|
|
195
181
|
const isAsync = (0, _useAsyncMode.default)();
|
|
@@ -203,6 +189,7 @@ function useMappingSelect(suspense, mapSelect, deps) {
|
|
|
203
189
|
(0, _element.useDebugValue)(result);
|
|
204
190
|
return result;
|
|
205
191
|
}
|
|
192
|
+
|
|
206
193
|
/**
|
|
207
194
|
* Custom react hook for retrieving props from registered selectors.
|
|
208
195
|
*
|
|
@@ -267,27 +254,24 @@ function useMappingSelect(suspense, mapSelect, deps) {
|
|
|
267
254
|
* ```
|
|
268
255
|
* @return {UseSelectReturn<T>} A custom react hook.
|
|
269
256
|
*/
|
|
270
|
-
|
|
271
|
-
|
|
272
257
|
function useSelect(mapSelect, deps) {
|
|
273
258
|
// On initial call, on mount, determine the mode of this `useSelect` call
|
|
274
259
|
// and then never allow it to change on subsequent updates.
|
|
275
260
|
const staticSelectMode = typeof mapSelect !== 'function';
|
|
276
261
|
const staticSelectModeRef = (0, _element.useRef)(staticSelectMode);
|
|
277
|
-
|
|
278
262
|
if (staticSelectMode !== staticSelectModeRef.current) {
|
|
279
263
|
const prevMode = staticSelectModeRef.current ? 'static' : 'mapping';
|
|
280
264
|
const nextMode = staticSelectMode ? 'static' : 'mapping';
|
|
281
265
|
throw new Error(`Switching useSelect from ${prevMode} to ${nextMode} is not allowed`);
|
|
282
266
|
}
|
|
267
|
+
|
|
283
268
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
284
269
|
// `staticSelectMode` is not allowed to change during the hook instance's,
|
|
285
270
|
// lifetime, so the rules of hooks are not really violated.
|
|
286
|
-
|
|
287
|
-
|
|
288
271
|
return staticSelectMode ? useStaticSelect(mapSelect) : useMappingSelect(false, mapSelect, deps);
|
|
289
272
|
/* eslint-enable react-hooks/rules-of-hooks */
|
|
290
273
|
}
|
|
274
|
+
|
|
291
275
|
/**
|
|
292
276
|
* A variant of the `useSelect` hook that has the same API, but will throw a
|
|
293
277
|
* suspense Promise if any of the called selectors is in an unresolved state.
|
|
@@ -303,8 +287,6 @@ function useSelect(mapSelect, deps) {
|
|
|
303
287
|
*
|
|
304
288
|
* @return {Object} Data object returned by the `mapSelect` function.
|
|
305
289
|
*/
|
|
306
|
-
|
|
307
|
-
|
|
308
290
|
function useSuspenseSelect(mapSelect, deps) {
|
|
309
291
|
return useMappingSelect(true, mapSelect, deps);
|
|
310
292
|
}
|