@wordpress/data 10.32.0 → 10.32.1-next.47f435fc9.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,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { default as default2 } from "./use-async-mode";
|
|
2
|
+
import { default as default3, AsyncModeConsumer } from "./context";
|
|
3
|
+
export {
|
|
4
|
+
AsyncModeConsumer,
|
|
5
|
+
default3 as AsyncModeProvider,
|
|
6
|
+
default2 as useAsyncMode
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/async-mode-provider/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default as useAsyncMode } from './use-async-mode';\nexport { default as AsyncModeProvider, AsyncModeConsumer } from './context';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA+B;AACxC,SAAoB,WAAXA,UAA8B,yBAAyB;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { useContext } from '@wordpress/element';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { Context } from './context';
|
|
10
|
-
export default function useAsyncMode() {
|
|
1
|
+
import { useContext } from "@wordpress/element";
|
|
2
|
+
import { Context } from "./context";
|
|
3
|
+
function useAsyncMode() {
|
|
11
4
|
return useContext(Context);
|
|
12
5
|
}
|
|
13
|
-
|
|
6
|
+
export {
|
|
7
|
+
useAsyncMode as default
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=use-async-mode.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/async-mode-provider/use-async-mode.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": "AAGA,SAAS,kBAAkB;AAK3B,SAAS,eAAe;AAET,SAAR,eAAgC;AACtC,SAAO,WAAY,OAAQ;AAC5B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,58 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Provider
|
|
15
|
-
} = Context;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A custom react Context consumer exposing the provided `registry` to
|
|
19
|
-
* children components. Used along with the RegistryProvider.
|
|
20
|
-
*
|
|
21
|
-
* You can read more about the react context api here:
|
|
22
|
-
* https://react.dev/learn/passing-data-deeply-with-context#step-3-provide-the-context
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* ```js
|
|
26
|
-
* import {
|
|
27
|
-
* RegistryProvider,
|
|
28
|
-
* RegistryConsumer,
|
|
29
|
-
* createRegistry
|
|
30
|
-
* } from '@wordpress/data';
|
|
31
|
-
*
|
|
32
|
-
* const registry = createRegistry( {} );
|
|
33
|
-
*
|
|
34
|
-
* const App = ( { props } ) => {
|
|
35
|
-
* return <RegistryProvider value={ registry }>
|
|
36
|
-
* <div>Hello There</div>
|
|
37
|
-
* <RegistryConsumer>
|
|
38
|
-
* { ( registry ) => (
|
|
39
|
-
* <ComponentUsingRegistry
|
|
40
|
-
* { ...props }
|
|
41
|
-
* registry={ registry }
|
|
42
|
-
* ) }
|
|
43
|
-
* </RegistryConsumer>
|
|
44
|
-
* </RegistryProvider>
|
|
45
|
-
* }
|
|
46
|
-
* ```
|
|
47
|
-
*/
|
|
48
|
-
export const RegistryConsumer = Consumer;
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* A custom Context provider for exposing the provided `registry` to children
|
|
52
|
-
* components via a consumer.
|
|
53
|
-
*
|
|
54
|
-
* See <a name="#RegistryConsumer">RegistryConsumer</a> documentation for
|
|
55
|
-
* example.
|
|
56
|
-
*/
|
|
57
|
-
export default Provider;
|
|
58
|
-
//# sourceMappingURL=context.js.map
|
|
1
|
+
import { createContext } from "@wordpress/element";
|
|
2
|
+
import defaultRegistry from "../../default-registry";
|
|
3
|
+
const Context = createContext(defaultRegistry);
|
|
4
|
+
Context.displayName = "RegistryProviderContext";
|
|
5
|
+
const { Consumer, Provider } = Context;
|
|
6
|
+
const RegistryConsumer = Consumer;
|
|
7
|
+
var context_default = Provider;
|
|
8
|
+
export {
|
|
9
|
+
Context,
|
|
10
|
+
RegistryConsumer,
|
|
11
|
+
context_default as default
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/registry-provider/context.js"],
|
|
4
|
+
"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 );\nContext.displayName = 'RegistryProviderContext';\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://react.dev/learn/passing-data-deeply-with-context#step-3-provide-the-context\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"],
|
|
5
|
+
"mappings": "AAGA,SAAS,qBAAqB;AAK9B,OAAO,qBAAqB;AAErB,MAAM,UAAU,cAAe,eAAgB;AACtD,QAAQ,cAAc;AAEtB,MAAM,EAAE,UAAU,SAAS,IAAI;AAiCxB,MAAM,mBAAmB;AAShC,IAAO,kBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { default as default2, RegistryConsumer } from "./context";
|
|
2
|
+
import { default as default3 } from "./use-registry";
|
|
3
|
+
export {
|
|
4
|
+
RegistryConsumer,
|
|
5
|
+
default2 as RegistryProvider,
|
|
6
|
+
default3 as useRegistry
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/registry-provider/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default as RegistryProvider, RegistryConsumer } from './context';\nexport { default as useRegistry } from './use-registry';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,UAA6B,wBAAwB;AAC9D,SAAoB,WAAXA,gBAA8B;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,53 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { useContext } from '@wordpress/element';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { Context } from './context';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* A custom react hook exposing the registry context for use.
|
|
13
|
-
*
|
|
14
|
-
* This exposes the `registry` value provided via the
|
|
15
|
-
* <a href="#RegistryProvider">Registry Provider</a> to a component implementing
|
|
16
|
-
* this hook.
|
|
17
|
-
*
|
|
18
|
-
* It acts similarly to the `useContext` react hook.
|
|
19
|
-
*
|
|
20
|
-
* Note: Generally speaking, `useRegistry` is a low level hook that in most cases
|
|
21
|
-
* won't be needed for implementation. Most interactions with the `@wordpress/data`
|
|
22
|
-
* API can be performed via the `useSelect` hook, or the `withSelect` and
|
|
23
|
-
* `withDispatch` higher order components.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```js
|
|
27
|
-
* import {
|
|
28
|
-
* RegistryProvider,
|
|
29
|
-
* createRegistry,
|
|
30
|
-
* useRegistry,
|
|
31
|
-
* } from '@wordpress/data';
|
|
32
|
-
*
|
|
33
|
-
* const registry = createRegistry( {} );
|
|
34
|
-
*
|
|
35
|
-
* const SomeChildUsingRegistry = ( props ) => {
|
|
36
|
-
* const registry = useRegistry();
|
|
37
|
-
* // ...logic implementing the registry in other react hooks.
|
|
38
|
-
* };
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* const ParentProvidingRegistry = ( props ) => {
|
|
42
|
-
* return <RegistryProvider value={ registry }>
|
|
43
|
-
* <SomeChildUsingRegistry { ...props } />
|
|
44
|
-
* </RegistryProvider>
|
|
45
|
-
* };
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @return {Function} A custom react hook exposing the registry context value.
|
|
49
|
-
*/
|
|
50
|
-
export default function useRegistry() {
|
|
1
|
+
import { useContext } from "@wordpress/element";
|
|
2
|
+
import { Context } from "./context";
|
|
3
|
+
function useRegistry() {
|
|
51
4
|
return useContext(Context);
|
|
52
5
|
}
|
|
53
|
-
|
|
6
|
+
export {
|
|
7
|
+
useRegistry as default
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=use-registry.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/registry-provider/use-registry.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": "AAGA,SAAS,kBAAkB;AAK3B,SAAS,eAAe;AAyCT,SAAR,cAA+B;AACrC,SAAO,WAAY,OAAQ;AAC5B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { default as default2 } from "./use-dispatch";
|
|
2
|
+
import { default as default3 } from "./use-dispatch-with-map";
|
|
3
|
+
export {
|
|
4
|
+
default2 as useDispatch,
|
|
5
|
+
default3 as useDispatchWithMap
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/use-dispatch/index.js"],
|
|
4
|
+
"sourcesContent": ["export { default as useDispatch } from './use-dispatch';\nexport { default as useDispatchWithMap } from './use-dispatch-with-map';\n"],
|
|
5
|
+
"mappings": "AAAA,SAAoB,WAAXA,gBAA8B;AACvC,SAAoB,WAAXA,gBAAqC;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,28 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { useMemo, useRef } from '@wordpress/element';
|
|
5
|
-
import { useIsomorphicLayoutEffect } from '@wordpress/compose';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import useRegistry from '../registry-provider/use-registry';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Custom react hook for returning aggregate dispatch actions using the provided
|
|
14
|
-
* dispatchMap.
|
|
15
|
-
*
|
|
16
|
-
* Currently this is an internal api only and is implemented by `withDispatch`
|
|
17
|
-
*
|
|
18
|
-
* @param {Function} dispatchMap Receives the `registry.dispatch` function as
|
|
19
|
-
* the first argument and the `registry` object
|
|
20
|
-
* as the second argument. Should return an
|
|
21
|
-
* object mapping props to functions.
|
|
22
|
-
* @param {Array} deps An array of dependencies for the hook.
|
|
23
|
-
* @return {Object} An object mapping props to functions created by the passed
|
|
24
|
-
* in dispatchMap.
|
|
25
|
-
*/
|
|
1
|
+
import { useMemo, useRef } from "@wordpress/element";
|
|
2
|
+
import { useIsomorphicLayoutEffect } from "@wordpress/compose";
|
|
3
|
+
import useRegistry from "../registry-provider/use-registry";
|
|
26
4
|
const useDispatchWithMap = (dispatchMap, deps) => {
|
|
27
5
|
const registry = useRegistry();
|
|
28
6
|
const currentDispatchMapRef = useRef(dispatchMap);
|
|
@@ -30,15 +8,29 @@ const useDispatchWithMap = (dispatchMap, deps) => {
|
|
|
30
8
|
currentDispatchMapRef.current = dispatchMap;
|
|
31
9
|
});
|
|
32
10
|
return useMemo(() => {
|
|
33
|
-
const currentDispatchProps = currentDispatchMapRef.current(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
11
|
+
const currentDispatchProps = currentDispatchMapRef.current(
|
|
12
|
+
registry.dispatch,
|
|
13
|
+
registry
|
|
14
|
+
);
|
|
15
|
+
return Object.fromEntries(
|
|
16
|
+
Object.entries(currentDispatchProps).map(
|
|
17
|
+
([propName, dispatcher]) => {
|
|
18
|
+
if (typeof dispatcher !== "function") {
|
|
19
|
+
console.warn(
|
|
20
|
+
`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return [
|
|
24
|
+
propName,
|
|
25
|
+
(...args) => currentDispatchMapRef.current(registry.dispatch, registry)[propName](...args)
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
);
|
|
41
30
|
}, [registry, ...deps]);
|
|
42
31
|
};
|
|
43
|
-
|
|
44
|
-
|
|
32
|
+
var use_dispatch_with_map_default = useDispatchWithMap;
|
|
33
|
+
export {
|
|
34
|
+
use_dispatch_with_map_default as default
|
|
35
|
+
};
|
|
36
|
+
//# 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": "AAGA,SAAS,SAAS,cAAc;AAChC,SAAS,iCAAiC;AAK1C,OAAO,iBAAiB;AAgBxB,MAAM,qBAAqB,CAAE,aAAa,SAAU;AACnD,QAAM,WAAW,YAAY;AAC7B,QAAM,wBAAwB,OAAQ,WAAY;AAElD,4BAA2B,MAAM;AAChC,0BAAsB,UAAU;AAAA,EACjC,CAAE;AAEF,SAAO,QAAS,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": []
|
|
7
|
+
}
|
|
@@ -1,68 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import useRegistry from '../registry-provider/use-registry';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {import('../../types').StoreDescriptor<StoreConfig>} StoreDescriptor
|
|
8
|
-
* @template {import('../../types').AnyConfig} StoreConfig
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* @typedef {import('../../types').UseDispatchReturn<StoreNameOrDescriptor>} UseDispatchReturn
|
|
12
|
-
* @template StoreNameOrDescriptor
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A custom react hook returning the current registry dispatch actions creators.
|
|
17
|
-
*
|
|
18
|
-
* Note: The component using this hook must be within the context of a
|
|
19
|
-
* RegistryProvider.
|
|
20
|
-
*
|
|
21
|
-
* @template {undefined | string | StoreDescriptor<any>} StoreNameOrDescriptor
|
|
22
|
-
* @param {StoreNameOrDescriptor} [storeNameOrDescriptor] Optionally provide the name of the
|
|
23
|
-
* store or its descriptor from which to
|
|
24
|
-
* retrieve action creators. If not
|
|
25
|
-
* provided, the registry.dispatch
|
|
26
|
-
* function is returned instead.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* This illustrates a pattern where you may need to retrieve dynamic data from
|
|
30
|
-
* the server via the `useSelect` hook to use in combination with the dispatch
|
|
31
|
-
* action.
|
|
32
|
-
*
|
|
33
|
-
* ```jsx
|
|
34
|
-
* import { useCallback } from 'react';
|
|
35
|
-
* import { useDispatch, useSelect } from '@wordpress/data';
|
|
36
|
-
* import { store as myCustomStore } from 'my-custom-store';
|
|
37
|
-
*
|
|
38
|
-
* function Button( { onClick, children } ) {
|
|
39
|
-
* return <button type="button" onClick={ onClick }>{ children }</button>
|
|
40
|
-
* }
|
|
41
|
-
*
|
|
42
|
-
* const SaleButton = ( { children } ) => {
|
|
43
|
-
* const { stockNumber } = useSelect(
|
|
44
|
-
* ( select ) => select( myCustomStore ).getStockNumber(),
|
|
45
|
-
* []
|
|
46
|
-
* );
|
|
47
|
-
* const { startSale } = useDispatch( myCustomStore );
|
|
48
|
-
* const onClick = useCallback( () => {
|
|
49
|
-
* const discountPercent = stockNumber > 50 ? 10: 20;
|
|
50
|
-
* startSale( discountPercent );
|
|
51
|
-
* }, [ stockNumber ] );
|
|
52
|
-
* return <Button onClick={ onClick }>{ children }</Button>
|
|
53
|
-
* }
|
|
54
|
-
*
|
|
55
|
-
* // Rendered somewhere in the application:
|
|
56
|
-
* //
|
|
57
|
-
* // <SaleButton>Start Sale!</SaleButton>
|
|
58
|
-
* ```
|
|
59
|
-
* @return {UseDispatchReturn<StoreNameOrDescriptor>} A custom react hook.
|
|
60
|
-
*/
|
|
61
|
-
const useDispatch = storeNameOrDescriptor => {
|
|
62
|
-
const {
|
|
63
|
-
dispatch
|
|
64
|
-
} = useRegistry();
|
|
1
|
+
import useRegistry from "../registry-provider/use-registry";
|
|
2
|
+
const useDispatch = (storeNameOrDescriptor) => {
|
|
3
|
+
const { dispatch } = useRegistry();
|
|
65
4
|
return storeNameOrDescriptor === void 0 ? dispatch : dispatch(storeNameOrDescriptor);
|
|
66
5
|
};
|
|
67
|
-
|
|
68
|
-
|
|
6
|
+
var use_dispatch_default = useDispatch;
|
|
7
|
+
export {
|
|
8
|
+
use_dispatch_default as default
|
|
9
|
+
};
|
|
10
|
+
//# 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": "AAGA,OAAO,iBAAiB;AAyDxB,MAAM,cAAc,CAAE,0BAA2B;AAChD,QAAM,EAAE,SAAS,IAAI,YAAY;AACjC,SAAO,0BAA0B,SAC9B,WACA,SAAU,qBAAsB;AACpC;AAEA,IAAO,uBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|