@wordpress/data 10.32.0 → 10.32.1-next.b8c8708f3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/async-mode-provider/context.js +35 -54
- package/build/components/async-mode-provider/context.js.map +7 -1
- package/build/components/async-mode-provider/index.js +40 -25
- package/build/components/async-mode-provider/index.js.map +7 -1
- package/build/components/async-mode-provider/use-async-mode.js +25 -16
- package/build/components/async-mode-provider/use-async-mode.js.map +7 -1
- package/build/components/registry-provider/context.js +46 -64
- package/build/components/registry-provider/context.js.map +7 -1
- package/build/components/registry-provider/index.js +40 -25
- package/build/components/registry-provider/index.js.map +7 -1
- package/build/components/registry-provider/use-registry.js +25 -55
- package/build/components/registry-provider/use-registry.js.map +7 -1
- package/build/components/use-dispatch/index.js +38 -17
- package/build/components/use-dispatch/index.js.map +7 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +59 -44
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
- package/build/components/use-dispatch/use-dispatch.js +36 -71
- package/build/components/use-dispatch/use-dispatch.js.map +7 -1
- package/build/components/use-select/index.js +79 -208
- package/build/components/use-select/index.js.map +7 -1
- package/build/components/with-dispatch/index.js +34 -107
- package/build/components/with-dispatch/index.js.map +7 -1
- package/build/components/with-registry/index.js +30 -30
- package/build/components/with-registry/index.js.map +7 -1
- package/build/components/with-select/index.js +44 -67
- package/build/components/with-select/index.js.map +7 -1
- package/build/controls.js +49 -110
- package/build/controls.js.map +7 -1
- package/build/create-selector.js +36 -11
- package/build/create-selector.js.map +7 -1
- package/build/default-registry.js +24 -10
- package/build/default-registry.js.map +7 -1
- package/build/dispatch.js +38 -31
- package/build/dispatch.js.map +7 -1
- package/build/factory.js +29 -85
- package/build/factory.js.map +7 -1
- package/build/index.js +114 -301
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/plugins/index.js +36 -11
- package/build/plugins/index.js.map +7 -1
- package/build/plugins/persistence/index.js +74 -139
- package/build/plugins/persistence/index.js.map +7 -1
- package/build/plugins/persistence/storage/default.js +37 -18
- package/build/plugins/persistence/storage/default.js.map +7 -1
- package/build/plugins/persistence/storage/object.js +24 -7
- package/build/plugins/persistence/storage/object.js.map +7 -1
- package/build/promise-middleware.js +37 -20
- package/build/promise-middleware.js.map +7 -1
- package/build/redux-store/combine-reducers.js +26 -5
- package/build/redux-store/combine-reducers.js.map +7 -1
- package/build/redux-store/index.js +221 -331
- package/build/redux-store/index.js.map +7 -1
- package/build/redux-store/metadata/actions.js +51 -112
- package/build/redux-store/metadata/actions.js.map +7 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js +1 -1
- package/build/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
- package/build/redux-store/metadata/reducer.js +111 -115
- package/build/redux-store/metadata/reducer.js.map +7 -1
- package/build/redux-store/metadata/selectors.js +109 -181
- package/build/redux-store/metadata/selectors.js.map +7 -1
- package/build/redux-store/metadata/utils.js +32 -35
- package/build/redux-store/metadata/utils.js.map +7 -1
- package/build/redux-store/thunk-middleware.js +24 -7
- package/build/redux-store/thunk-middleware.js.map +7 -1
- package/build/registry.js +94 -198
- package/build/registry.js.map +7 -1
- package/build/resolvers-cache-middleware.js +26 -27
- package/build/resolvers-cache-middleware.js.map +7 -1
- package/build/select.js +38 -31
- package/build/select.js.map +7 -1
- package/build/store/index.js +52 -16
- package/build/store/index.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/emitter.js +33 -16
- package/build/utils/emitter.js.map +7 -1
- package/build-module/components/async-mode-provider/context.js +12 -49
- package/build-module/components/async-mode-provider/context.js.map +7 -1
- package/build-module/components/async-mode-provider/index.js +8 -3
- package/build-module/components/async-mode-provider/index.js.map +7 -1
- package/build-module/components/async-mode-provider/use-async-mode.js +7 -11
- package/build-module/components/async-mode-provider/use-async-mode.js.map +7 -1
- package/build-module/components/registry-provider/context.js +13 -58
- package/build-module/components/registry-provider/context.js.map +7 -1
- package/build-module/components/registry-provider/index.js +8 -3
- package/build-module/components/registry-provider/index.js.map +7 -1
- package/build-module/components/registry-provider/use-registry.js +7 -51
- package/build-module/components/registry-provider/use-registry.js.map +7 -1
- package/build-module/components/use-dispatch/index.js +7 -3
- package/build-module/components/use-dispatch/index.js.map +7 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +27 -35
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +7 -1
- package/build-module/components/use-dispatch/use-dispatch.js +8 -66
- package/build-module/components/use-dispatch/use-dispatch.js.map +7 -1
- package/build-module/components/use-select/index.js +45 -193
- package/build-module/components/use-select/index.js.map +7 -1
- package/build-module/components/with-dispatch/index.js +16 -104
- package/build-module/components/with-dispatch/index.js.map +7 -1
- package/build-module/components/with-registry/index.js +12 -27
- package/build-module/components/with-registry/index.js.map +7 -1
- package/build-module/components/with-select/index.js +16 -63
- package/build-module/components/with-select/index.js.map +7 -1
- package/build-module/controls.js +25 -105
- package/build-module/controls.js.map +7 -1
- package/build-module/create-selector.js +5 -8
- package/build-module/create-selector.js.map +7 -1
- package/build-module/default-registry.js +6 -6
- package/build-module/default-registry.js.map +7 -1
- package/build-module/dispatch.js +6 -27
- package/build-module/dispatch.js.map +7 -1
- package/build-module/factory.js +8 -82
- package/build-module/factory.js.map +7 -1
- package/build-module/index.js +62 -185
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/plugins/index.js +5 -2
- package/build-module/plugins/index.js.map +7 -1
- package/build-module/plugins/persistence/index.js +38 -129
- package/build-module/plugins/persistence/index.js.map +7 -1
- package/build-module/plugins/persistence/storage/default.js +8 -11
- package/build-module/plugins/persistence/storage/default.js.map +7 -1
- package/build-module/plugins/persistence/storage/object.js +6 -3
- package/build-module/plugins/persistence/storage/object.js.map +7 -1
- package/build-module/promise-middleware.js +8 -14
- package/build-module/promise-middleware.js.map +7 -1
- package/build-module/redux-store/combine-reducers.js +5 -2
- package/build-module/redux-store/combine-reducers.js.map +7 -1
- package/build-module/redux-store/index.js +180 -310
- package/build-module/redux-store/index.js.map +7 -1
- package/build-module/redux-store/metadata/actions.js +30 -109
- package/build-module/redux-store/metadata/actions.js.map +7 -1
- package/build-module/redux-store/metadata/equivalent-key-map.d.js +1 -2
- package/build-module/redux-store/metadata/equivalent-key-map.d.js.map +7 -1
- package/build-module/redux-store/metadata/reducer.js +83 -108
- package/build-module/redux-store/metadata/reducer.js.map +7 -1
- package/build-module/redux-store/metadata/selectors.js +76 -175
- package/build-module/redux-store/metadata/selectors.js.map +7 -1
- package/build-module/redux-store/metadata/utils.js +10 -30
- package/build-module/redux-store/metadata/utils.js.map +7 -1
- package/build-module/redux-store/thunk-middleware.js +7 -4
- package/build-module/redux-store/thunk-middleware.js.map +7 -1
- package/build-module/registry.js +56 -187
- package/build-module/registry.js.map +7 -1
- package/build-module/resolvers-cache-middleware.js +8 -23
- package/build-module/resolvers-cache-middleware.js.map +7 -1
- package/build-module/select.js +6 -27
- package/build-module/select.js.map +7 -1
- package/build-module/store/index.js +34 -12
- package/build-module/store/index.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/emitter.js +12 -13
- package/build-module/utils/emitter.js.map +7 -1
- package/package.json +17 -10
|
@@ -1,51 +1,66 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var use_dispatch_with_map_exports = {};
|
|
30
|
+
__export(use_dispatch_with_map_exports, {
|
|
31
|
+
default: () => use_dispatch_with_map_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
/**
|
|
12
|
-
* WordPress dependencies
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Internal dependencies
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Custom react hook for returning aggregate dispatch actions using the provided
|
|
21
|
-
* dispatchMap.
|
|
22
|
-
*
|
|
23
|
-
* Currently this is an internal api only and is implemented by `withDispatch`
|
|
24
|
-
*
|
|
25
|
-
* @param {Function} dispatchMap Receives the `registry.dispatch` function as
|
|
26
|
-
* the first argument and the `registry` object
|
|
27
|
-
* as the second argument. Should return an
|
|
28
|
-
* object mapping props to functions.
|
|
29
|
-
* @param {Array} deps An array of dependencies for the hook.
|
|
30
|
-
* @return {Object} An object mapping props to functions created by the passed
|
|
31
|
-
* in dispatchMap.
|
|
32
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(use_dispatch_with_map_exports);
|
|
34
|
+
var import_element = require("@wordpress/element");
|
|
35
|
+
var import_compose = require("@wordpress/compose");
|
|
36
|
+
var import_use_registry = __toESM(require("../registry-provider/use-registry"));
|
|
33
37
|
const useDispatchWithMap = (dispatchMap, deps) => {
|
|
34
|
-
const registry = (0,
|
|
35
|
-
const currentDispatchMapRef = (0,
|
|
36
|
-
(0,
|
|
38
|
+
const registry = (0, import_use_registry.default)();
|
|
39
|
+
const currentDispatchMapRef = (0, import_element.useRef)(dispatchMap);
|
|
40
|
+
(0, import_compose.useIsomorphicLayoutEffect)(() => {
|
|
37
41
|
currentDispatchMapRef.current = dispatchMap;
|
|
38
42
|
});
|
|
39
|
-
return (0,
|
|
40
|
-
const currentDispatchProps = currentDispatchMapRef.current(
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
return (0, import_element.useMemo)(() => {
|
|
44
|
+
const currentDispatchProps = currentDispatchMapRef.current(
|
|
45
|
+
registry.dispatch,
|
|
46
|
+
registry
|
|
47
|
+
);
|
|
48
|
+
return Object.fromEntries(
|
|
49
|
+
Object.entries(currentDispatchProps).map(
|
|
50
|
+
([propName, dispatcher]) => {
|
|
51
|
+
if (typeof dispatcher !== "function") {
|
|
52
|
+
console.warn(
|
|
53
|
+
`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return [
|
|
57
|
+
propName,
|
|
58
|
+
(...args) => currentDispatchMapRef.current(registry.dispatch, registry)[propName](...args)
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
)
|
|
62
|
+
);
|
|
48
63
|
}, [registry, ...deps]);
|
|
49
64
|
};
|
|
50
|
-
var
|
|
51
|
-
//# sourceMappingURL=use-dispatch-with-map.js.map
|
|
65
|
+
var use_dispatch_with_map_default = useDispatchWithMap;
|
|
66
|
+
//# sourceMappingURL=use-dispatch-with-map.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/use-dispatch/use-dispatch-with-map.js"],
|
|
4
|
+
"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 currentDispatchMapRef = useRef( dispatchMap );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tcurrentDispatchMapRef.current = dispatchMap;\n\t} );\n\n\treturn useMemo( () => {\n\t\tconst currentDispatchProps = currentDispatchMapRef.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\tcurrentDispatchMapRef\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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAgC;AAChC,qBAA0C;AAK1C,0BAAwB;AAgBxB,MAAM,qBAAqB,CAAE,aAAa,SAAU;AACnD,QAAM,eAAW,oBAAAA,SAAY;AAC7B,QAAM,4BAAwB,uBAAQ,WAAY;AAElD,gDAA2B,MAAM;AAChC,0BAAsB,UAAU;AAAA,EACjC,CAAE;AAEF,aAAO,wBAAS,MAAM;AACrB,UAAM,uBAAuB,sBAAsB;AAAA,MAClD,SAAS;AAAA,MACT;AAAA,IACD;AACA,WAAO,OAAO;AAAA,MACb,OAAO,QAAS,oBAAqB,EAAE;AAAA,QACtC,CAAE,CAAE,UAAU,UAAW,MAAO;AAC/B,cAAK,OAAO,eAAe,YAAa;AAEvC,oBAAQ;AAAA,cACP,YAAa,QAAS;AAAA,YACvB;AAAA,UACD;AACA,iBAAO;AAAA,YACN;AAAA,YACA,IAAK,SACJ,sBACE,QAAS,SAAS,UAAU,QAAS,EACpC,QAAS,EAAG,GAAG,IAAK;AAAA,UACzB;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG,CAAE,UAAU,GAAG,IAAK,CAAE;AAC1B;AAEA,IAAO,gCAAQ;",
|
|
6
|
+
"names": ["useRegistry"]
|
|
7
|
+
}
|
|
@@ -1,75 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var use_dispatch_exports = {};
|
|
30
|
+
__export(use_dispatch_exports, {
|
|
31
|
+
default: () => use_dispatch_default
|
|
6
32
|
});
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor
|
|
15
|
-
* @template {import('../../types').AnyConfig} StoreConfig
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn
|
|
19
|
-
* @template StoreNameOrDescriptor
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* A custom react hook returning the current registry dispatch actions creators.
|
|
24
|
-
*
|
|
25
|
-
* Note: The component using this hook must be within the context of a
|
|
26
|
-
* RegistryProvider.
|
|
27
|
-
*
|
|
28
|
-
* @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor
|
|
29
|
-
* @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the
|
|
30
|
-
* store or its descriptor from which to
|
|
31
|
-
* retrieve action creators. If not
|
|
32
|
-
* provided, the registry.dispatch
|
|
33
|
-
* function is returned instead.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* This illustrates a pattern where you may need to retrieve dynamic data from
|
|
37
|
-
* the server via the `useSelect` hook to use in combination with the dispatch
|
|
38
|
-
* action.
|
|
39
|
-
*
|
|
40
|
-
* ```jsx
|
|
41
|
-
* import { useCallback } from 'react';
|
|
42
|
-
* import { useDispatch, useSelect } from '@wordpress/data';
|
|
43
|
-
* import { store as myCustomStore } from 'my-custom-store';
|
|
44
|
-
*
|
|
45
|
-
* function Button( { onClick, children } ) {
|
|
46
|
-
* return <button type="button" onClick={ onClick }>{ children }</button>
|
|
47
|
-
* }
|
|
48
|
-
*
|
|
49
|
-
* const SaleButton = ( { children } ) => {
|
|
50
|
-
* const { stockNumber } = useSelect(
|
|
51
|
-
* ( select ) => select( myCustomStore ).getStockNumber(),
|
|
52
|
-
* []
|
|
53
|
-
* );
|
|
54
|
-
* const { startSale } = useDispatch( myCustomStore );
|
|
55
|
-
* const onClick = useCallback( () => {
|
|
56
|
-
* const discountPercent = stockNumber > 50 ? 10: 20;
|
|
57
|
-
* startSale( discountPercent );
|
|
58
|
-
* }, [ stockNumber ] );
|
|
59
|
-
* return <Button onClick={ onClick }>{ children }</Button>
|
|
60
|
-
* }
|
|
61
|
-
*
|
|
62
|
-
* // Rendered somewhere in the application:
|
|
63
|
-
* //
|
|
64
|
-
* // <SaleButton>Start Sale!</SaleButton>
|
|
65
|
-
* ```
|
|
66
|
-
* @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook.
|
|
67
|
-
*/
|
|
68
|
-
const useDispatch = storeNameOrDescriptor => {
|
|
69
|
-
const {
|
|
70
|
-
dispatch
|
|
71
|
-
} = (0, _useRegistry.default)();
|
|
33
|
+
module.exports = __toCommonJS(use_dispatch_exports);
|
|
34
|
+
var import_use_registry = __toESM(require("../registry-provider/use-registry"));
|
|
35
|
+
const useDispatch = (storeNameOrDescriptor) => {
|
|
36
|
+
const { dispatch } = (0, import_use_registry.default)();
|
|
72
37
|
return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor);
|
|
73
38
|
};
|
|
74
|
-
var
|
|
75
|
-
//# sourceMappingURL=use-dispatch.js.map
|
|
39
|
+
var use_dispatch_default = useDispatch;
|
|
40
|
+
//# sourceMappingURL=use-dispatch.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/use-dispatch/use-dispatch.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAwB;AAyDxB,MAAM,cAAc,CAAE,0BAA2B;AAChD,QAAM,EAAE,SAAS,QAAI,oBAAAA,SAAY;AACjC,SAAO,0BAA0B,SAC9B,WACA,SAAU,qBAAsB;AACpC;AAEA,IAAO,uBAAQ;",
|
|
6
|
+
"names": ["useRegistry"]
|
|
7
|
+
}
|
|
@@ -1,51 +1,53 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
Object.
|
|
5
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var use_select_exports = {};
|
|
30
|
+
__export(use_select_exports, {
|
|
31
|
+
default: () => useSelect,
|
|
32
|
+
useSuspenseSelect: () => useSuspenseSelect
|
|
6
33
|
});
|
|
7
|
-
exports
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* WordPress dependencies
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Internal dependencies
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
const renderQueue = (0, _priorityQueue.createQueue)();
|
|
34
|
+
module.exports = __toCommonJS(use_select_exports);
|
|
35
|
+
var import_priority_queue = require("@wordpress/priority-queue");
|
|
36
|
+
var import_element = require("@wordpress/element");
|
|
37
|
+
var import_is_shallow_equal = __toESM(require("@wordpress/is-shallow-equal"));
|
|
38
|
+
var import_use_registry = __toESM(require("../registry-provider/use-registry"));
|
|
39
|
+
var import_use_async_mode = __toESM(require("../async-mode-provider/use-async-mode"));
|
|
40
|
+
const renderQueue = (0, import_priority_queue.createQueue)();
|
|
23
41
|
function warnOnUnstableReference(a, b) {
|
|
24
42
|
if (!a || !b) {
|
|
25
43
|
return;
|
|
26
44
|
}
|
|
27
|
-
const keys = typeof a ===
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
45
|
+
const keys = typeof a === "object" && typeof b === "object" ? Object.keys(a).filter((k) => a[k] !== b[k]) : [];
|
|
46
|
+
console.warn(
|
|
47
|
+
"The `useSelect` hook returns different values when called with the same state and parameters.\nThis can lead to unnecessary re-renders and performance issues if not fixed.\n\nNon-equal value keys: %s\n\n",
|
|
48
|
+
keys.join(", ")
|
|
49
|
+
);
|
|
31
50
|
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor
|
|
35
|
-
* @template {import('../../types').AnyConfig} C
|
|
36
|
-
*/
|
|
37
|
-
/**
|
|
38
|
-
* @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig
|
|
39
|
-
* @template State
|
|
40
|
-
* @template {Record<string,import('../../types').ActionCreator>} Actions
|
|
41
|
-
* @template Selectors
|
|
42
|
-
*/
|
|
43
|
-
/** @typedef {import('../../types').MapSelect} MapSelect */
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn
|
|
46
|
-
* @template {MapSelect|StoreDescriptor<any>} T
|
|
47
|
-
*/
|
|
48
|
-
|
|
49
51
|
function Store(registry, suspense) {
|
|
50
52
|
const select = suspense ? registry.suspendSelect : registry.select;
|
|
51
53
|
const queueContext = {};
|
|
@@ -55,31 +57,14 @@ function Store(registry, suspense) {
|
|
|
55
57
|
let lastIsAsync;
|
|
56
58
|
let subscriber;
|
|
57
59
|
let didWarnUnstableReference;
|
|
58
|
-
const storeStatesOnMount = new Map();
|
|
60
|
+
const storeStatesOnMount = /* @__PURE__ */ new Map();
|
|
59
61
|
function getStoreState(name) {
|
|
60
|
-
|
|
61
|
-
// If there's no store property (custom generic store), return an empty
|
|
62
|
-
// object. When comparing the state, the empty objects will cause the
|
|
63
|
-
// equality check to fail, setting `lastMapResultValid` to false.
|
|
64
|
-
return (_registry$stores$name = registry.stores[name]?.store?.getState?.()) !== null && _registry$stores$name !== void 0 ? _registry$stores$name : {};
|
|
62
|
+
return registry.stores[name]?.store?.getState?.() ?? {};
|
|
65
63
|
}
|
|
66
|
-
const createSubscriber = stores => {
|
|
67
|
-
// The set of stores the `subscribe` function is supposed to subscribe to. Here it is
|
|
68
|
-
// initialized, and then the `updateStores` function can add new stores to it.
|
|
64
|
+
const createSubscriber = (stores) => {
|
|
69
65
|
const activeStores = [...stores];
|
|
70
|
-
|
|
71
|
-
// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could
|
|
72
|
-
// be called multiple times to establish multiple subscriptions. That's why we need to
|
|
73
|
-
// keep a set of active subscriptions;
|
|
74
|
-
const activeSubscriptions = new Set();
|
|
66
|
+
const activeSubscriptions = /* @__PURE__ */ new Set();
|
|
75
67
|
function subscribe(listener) {
|
|
76
|
-
// Maybe invalidate the value right after subscription was created.
|
|
77
|
-
// React will call `getValue` after subscribing, to detect store
|
|
78
|
-
// updates that happened in the interval between the `getValue` call
|
|
79
|
-
// during render and creating the subscription, which is slightly
|
|
80
|
-
// delayed. We need to ensure that this second `getValue` call will
|
|
81
|
-
// compute a fresh value only if any of the store states have
|
|
82
|
-
// changed in the meantime.
|
|
83
68
|
if (lastMapResultValid) {
|
|
84
69
|
for (const name of activeStores) {
|
|
85
70
|
if (storeStatesOnMount.get(name) !== getStoreState(name)) {
|
|
@@ -89,7 +74,6 @@ function Store(registry, suspense) {
|
|
|
89
74
|
}
|
|
90
75
|
storeStatesOnMount.clear();
|
|
91
76
|
const onStoreChange = () => {
|
|
92
|
-
// Invalidate the value on store update, so that a fresh value is computed.
|
|
93
77
|
lastMapResultValid = false;
|
|
94
78
|
listener();
|
|
95
79
|
};
|
|
@@ -111,51 +95,38 @@ function Store(registry, suspense) {
|
|
|
111
95
|
return () => {
|
|
112
96
|
activeSubscriptions.delete(subscribeStore);
|
|
113
97
|
for (const unsub of unsubs.values()) {
|
|
114
|
-
// The return value of the subscribe function could be undefined if the store is a custom generic store.
|
|
115
98
|
unsub?.();
|
|
116
99
|
}
|
|
117
|
-
// Cancel existing store updates that were already scheduled.
|
|
118
100
|
renderQueue.cancel(queueContext);
|
|
119
101
|
};
|
|
120
102
|
}
|
|
121
|
-
|
|
122
|
-
// Check if `newStores` contains some stores we're not subscribed to yet, and add them.
|
|
123
103
|
function updateStores(newStores) {
|
|
124
104
|
for (const newStore of newStores) {
|
|
125
105
|
if (activeStores.includes(newStore)) {
|
|
126
106
|
continue;
|
|
127
107
|
}
|
|
128
|
-
|
|
129
|
-
// New `subscribe` calls will subscribe to `newStore`, too.
|
|
130
108
|
activeStores.push(newStore);
|
|
131
|
-
|
|
132
|
-
// Add `newStore` to existing subscriptions.
|
|
133
109
|
for (const subscription of activeSubscriptions) {
|
|
134
110
|
subscription(newStore);
|
|
135
111
|
}
|
|
136
112
|
}
|
|
137
113
|
}
|
|
138
|
-
return {
|
|
139
|
-
subscribe,
|
|
140
|
-
updateStores
|
|
141
|
-
};
|
|
114
|
+
return { subscribe, updateStores };
|
|
142
115
|
};
|
|
143
116
|
return (mapSelect, isAsync) => {
|
|
144
117
|
function updateValue() {
|
|
145
|
-
// If the last value is valid, and the `mapSelect` callback hasn't changed,
|
|
146
|
-
// then we can safely return the cached value. The value can change only on
|
|
147
|
-
// store update, and in that case value will be invalidated by the listener.
|
|
148
118
|
if (lastMapResultValid && mapSelect === lastMapSelect) {
|
|
149
119
|
return lastMapResult;
|
|
150
120
|
}
|
|
151
|
-
const listeningStores = {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
121
|
+
const listeningStores = { current: null };
|
|
122
|
+
const mapResult = registry.__unstableMarkListeningStores(
|
|
123
|
+
() => mapSelect(select, registry),
|
|
124
|
+
listeningStores
|
|
125
|
+
);
|
|
155
126
|
if (globalThis.SCRIPT_DEBUG) {
|
|
156
127
|
if (!didWarnUnstableReference) {
|
|
157
128
|
const secondMapResult = mapSelect(select, registry);
|
|
158
|
-
if (!(0,
|
|
129
|
+
if (!(0, import_is_shallow_equal.default)(mapResult, secondMapResult)) {
|
|
159
130
|
warnOnUnstableReference(mapResult, secondMapResult);
|
|
160
131
|
didWarnUnstableReference = true;
|
|
161
132
|
}
|
|
@@ -169,158 +140,58 @@ function Store(registry, suspense) {
|
|
|
169
140
|
} else {
|
|
170
141
|
subscriber.updateStores(listeningStores.current);
|
|
171
142
|
}
|
|
172
|
-
|
|
173
|
-
// If the new value is shallow-equal to the old one, keep the old one so
|
|
174
|
-
// that we don't trigger unwanted updates that do a `===` check.
|
|
175
|
-
if (!(0, _isShallowEqual.default)(lastMapResult, mapResult)) {
|
|
143
|
+
if (!(0, import_is_shallow_equal.default)(lastMapResult, mapResult)) {
|
|
176
144
|
lastMapResult = mapResult;
|
|
177
145
|
}
|
|
178
146
|
lastMapSelect = mapSelect;
|
|
179
147
|
lastMapResultValid = true;
|
|
180
148
|
}
|
|
181
149
|
function getValue() {
|
|
182
|
-
// Update the value in case it's been invalidated or `mapSelect` has changed.
|
|
183
150
|
updateValue();
|
|
184
151
|
return lastMapResult;
|
|
185
152
|
}
|
|
186
|
-
|
|
187
|
-
// When transitioning from async to sync mode, cancel existing store updates
|
|
188
|
-
// that have been scheduled, and invalidate the value so that it's freshly
|
|
189
|
-
// computed. It might have been changed by the update we just cancelled.
|
|
190
153
|
if (lastIsAsync && !isAsync) {
|
|
191
154
|
lastMapResultValid = false;
|
|
192
155
|
renderQueue.cancel(queueContext);
|
|
193
156
|
}
|
|
194
157
|
updateValue();
|
|
195
158
|
lastIsAsync = isAsync;
|
|
196
|
-
|
|
197
|
-
// Return a pair of functions that can be passed to `useSyncExternalStore`.
|
|
198
|
-
return {
|
|
199
|
-
subscribe: subscriber.subscribe,
|
|
200
|
-
getValue
|
|
201
|
-
};
|
|
159
|
+
return { subscribe: subscriber.subscribe, getValue };
|
|
202
160
|
};
|
|
203
161
|
}
|
|
204
162
|
function _useStaticSelect(storeName) {
|
|
205
|
-
return (0,
|
|
163
|
+
return (0, import_use_registry.default)().select(storeName);
|
|
206
164
|
}
|
|
207
165
|
function _useMappingSelect(suspense, mapSelect, deps) {
|
|
208
|
-
const registry = (0,
|
|
209
|
-
const isAsync = (0,
|
|
210
|
-
const store = (0,
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const selector = (0,
|
|
215
|
-
const {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
} = store(selector, isAsync);
|
|
219
|
-
const result = (0, _element.useSyncExternalStore)(subscribe, getValue, getValue);
|
|
220
|
-
(0, _element.useDebugValue)(result);
|
|
166
|
+
const registry = (0, import_use_registry.default)();
|
|
167
|
+
const isAsync = (0, import_use_async_mode.default)();
|
|
168
|
+
const store = (0, import_element.useMemo)(
|
|
169
|
+
() => Store(registry, suspense),
|
|
170
|
+
[registry, suspense]
|
|
171
|
+
);
|
|
172
|
+
const selector = (0, import_element.useCallback)(mapSelect, deps);
|
|
173
|
+
const { subscribe, getValue } = store(selector, isAsync);
|
|
174
|
+
const result = (0, import_element.useSyncExternalStore)(subscribe, getValue, getValue);
|
|
175
|
+
(0, import_element.useDebugValue)(result);
|
|
221
176
|
return result;
|
|
222
177
|
}
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
* Custom react hook for retrieving props from registered selectors.
|
|
226
|
-
*
|
|
227
|
-
* In general, this custom React hook follows the
|
|
228
|
-
* [rules of hooks](https://react.dev/reference/rules/rules-of-hooks).
|
|
229
|
-
*
|
|
230
|
-
* @template {MapSelect | StoreDescriptor<any>} T
|
|
231
|
-
* @param {T} mapSelect Function called on every state change. The returned value is
|
|
232
|
-
* exposed to the component implementing this hook. The function
|
|
233
|
-
* receives the `registry.select` method on the first argument
|
|
234
|
-
* and the `registry` on the second argument.
|
|
235
|
-
* When a store key is passed, all selectors for the store will be
|
|
236
|
-
* returned. This is only meant for usage of these selectors in event
|
|
237
|
-
* callbacks, not for data needed to create the element tree.
|
|
238
|
-
* @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is
|
|
239
|
-
* invoked on every state change unless the dependencies change.
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```js
|
|
243
|
-
* import { useSelect } from '@wordpress/data';
|
|
244
|
-
* import { store as myCustomStore } from 'my-custom-store';
|
|
245
|
-
*
|
|
246
|
-
* function HammerPriceDisplay( { currency } ) {
|
|
247
|
-
* const price = useSelect( ( select ) => {
|
|
248
|
-
* return select( myCustomStore ).getPrice( 'hammer', currency );
|
|
249
|
-
* }, [ currency ] );
|
|
250
|
-
* return new Intl.NumberFormat( 'en-US', {
|
|
251
|
-
* style: 'currency',
|
|
252
|
-
* currency,
|
|
253
|
-
* } ).format( price );
|
|
254
|
-
* }
|
|
255
|
-
*
|
|
256
|
-
* // Rendered in the application:
|
|
257
|
-
* // <HammerPriceDisplay currency="USD" />
|
|
258
|
-
* ```
|
|
259
|
-
*
|
|
260
|
-
* In the above example, when `HammerPriceDisplay` is rendered into an
|
|
261
|
-
* application, the price will be retrieved from the store state using the
|
|
262
|
-
* `mapSelect` callback on `useSelect`. If the currency prop changes then
|
|
263
|
-
* any price in the state for that currency is retrieved. If the currency prop
|
|
264
|
-
* doesn't change and other props are passed in that do change, the price will
|
|
265
|
-
* not change because the dependency is just the currency.
|
|
266
|
-
*
|
|
267
|
-
* When data is only used in an event callback, the data should not be retrieved
|
|
268
|
-
* on render, so it may be useful to get the selectors function instead.
|
|
269
|
-
*
|
|
270
|
-
* **Don't use `useSelect` this way when calling the selectors in the render
|
|
271
|
-
* function because your component won't re-render on a data change.**
|
|
272
|
-
*
|
|
273
|
-
* ```js
|
|
274
|
-
* import { useSelect } from '@wordpress/data';
|
|
275
|
-
* import { store as myCustomStore } from 'my-custom-store';
|
|
276
|
-
*
|
|
277
|
-
* function Paste( { children } ) {
|
|
278
|
-
* const { getSettings } = useSelect( myCustomStore );
|
|
279
|
-
* function onPaste() {
|
|
280
|
-
* // Do something with the settings.
|
|
281
|
-
* const settings = getSettings();
|
|
282
|
-
* }
|
|
283
|
-
* return <div onPaste={ onPaste }>{ children }</div>;
|
|
284
|
-
* }
|
|
285
|
-
* ```
|
|
286
|
-
* @return {UseSelectReturn<T>} A custom react hook.
|
|
287
|
-
*/
|
|
288
178
|
function useSelect(mapSelect, deps) {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const staticSelectMode = typeof mapSelect !== 'function';
|
|
292
|
-
const staticSelectModeRef = (0, _element.useRef)(staticSelectMode);
|
|
179
|
+
const staticSelectMode = typeof mapSelect !== "function";
|
|
180
|
+
const staticSelectModeRef = (0, import_element.useRef)(staticSelectMode);
|
|
293
181
|
if (staticSelectMode !== staticSelectModeRef.current) {
|
|
294
|
-
const prevMode = staticSelectModeRef.current ?
|
|
295
|
-
const nextMode = staticSelectMode ?
|
|
296
|
-
throw new Error(
|
|
182
|
+
const prevMode = staticSelectModeRef.current ? "static" : "mapping";
|
|
183
|
+
const nextMode = staticSelectMode ? "static" : "mapping";
|
|
184
|
+
throw new Error(
|
|
185
|
+
`Switching useSelect from ${prevMode} to ${nextMode} is not allowed`
|
|
186
|
+
);
|
|
297
187
|
}
|
|
298
|
-
|
|
299
|
-
// `staticSelectMode` is not allowed to change during the hook instance's,
|
|
300
|
-
// lifetime, so the rules of hooks are not really violated.
|
|
301
188
|
return staticSelectMode ? _useStaticSelect(mapSelect) : _useMappingSelect(false, mapSelect, deps);
|
|
302
189
|
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* A variant of the `useSelect` hook that has the same API, but is a compatible
|
|
306
|
-
* Suspense-enabled data source.
|
|
307
|
-
*
|
|
308
|
-
* @template {MapSelect} T
|
|
309
|
-
* @param {T} mapSelect Function called on every state change. The
|
|
310
|
-
* returned value is exposed to the component
|
|
311
|
-
* using this hook. The function receives the
|
|
312
|
-
* `registry.suspendSelect` method as the first
|
|
313
|
-
* argument and the `registry` as the second one.
|
|
314
|
-
* @param {Array} deps A dependency array used to memoize the `mapSelect`
|
|
315
|
-
* so that the same `mapSelect` is invoked on every
|
|
316
|
-
* state change unless the dependencies change.
|
|
317
|
-
*
|
|
318
|
-
* @throws {Promise} A suspense Promise that is thrown if any of the called
|
|
319
|
-
* selectors is in an unresolved state.
|
|
320
|
-
*
|
|
321
|
-
* @return {ReturnType<T>} Data object returned by the `mapSelect` function.
|
|
322
|
-
*/
|
|
323
190
|
function useSuspenseSelect(mapSelect, deps) {
|
|
324
191
|
return _useMappingSelect(true, mapSelect, deps);
|
|
325
192
|
}
|
|
326
|
-
|
|
193
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
194
|
+
0 && (module.exports = {
|
|
195
|
+
useSuspenseSelect
|
|
196
|
+
});
|
|
197
|
+
//# sourceMappingURL=index.js.map
|