@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,63 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @param {Function} mapSelectToProps Function called on every state change,
|
|
18
|
-
* expected to return object of props to
|
|
19
|
-
* merge with the component's own props.
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```js
|
|
23
|
-
* import { withSelect } from '@wordpress/data';
|
|
24
|
-
* import { store as myCustomStore } from 'my-custom-store';
|
|
25
|
-
*
|
|
26
|
-
* function PriceDisplay( { price, currency } ) {
|
|
27
|
-
* return new Intl.NumberFormat( 'en-US', {
|
|
28
|
-
* style: 'currency',
|
|
29
|
-
* currency,
|
|
30
|
-
* } ).format( price );
|
|
31
|
-
* }
|
|
32
|
-
*
|
|
33
|
-
* const HammerPriceDisplay = withSelect( ( select, ownProps ) => {
|
|
34
|
-
* const { getPrice } = select( myCustomStore );
|
|
35
|
-
* const { currency } = ownProps;
|
|
36
|
-
*
|
|
37
|
-
* return {
|
|
38
|
-
* price: getPrice( 'hammer', currency ),
|
|
39
|
-
* };
|
|
40
|
-
* } )( PriceDisplay );
|
|
41
|
-
*
|
|
42
|
-
* // Rendered in the application:
|
|
43
|
-
* //
|
|
44
|
-
* // <HammerPriceDisplay currency="USD" />
|
|
45
|
-
* ```
|
|
46
|
-
* In the above example, when `HammerPriceDisplay` is rendered into an
|
|
47
|
-
* application, it will pass the price into the underlying `PriceDisplay`
|
|
48
|
-
* component and update automatically if the price of a hammer ever changes in
|
|
49
|
-
* the store.
|
|
50
|
-
*
|
|
51
|
-
* @return {ComponentType} Enhanced component with merged state data props.
|
|
52
|
-
*/
|
|
53
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
54
|
-
const withSelect = mapSelectToProps => createHigherOrderComponent(WrappedComponent => pure(ownProps => {
|
|
55
|
-
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
|
|
56
|
-
const mergeProps = useSelect(mapSelect);
|
|
57
|
-
return /*#__PURE__*/_jsx(WrappedComponent, {
|
|
58
|
-
...ownProps,
|
|
59
|
-
...mergeProps
|
|
60
|
-
});
|
|
61
|
-
}), 'withSelect');
|
|
62
|
-
export default withSelect;
|
|
63
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createHigherOrderComponent, pure } from "@wordpress/compose";
|
|
3
|
+
import useSelect from "../use-select";
|
|
4
|
+
const withSelect = (mapSelectToProps) => createHigherOrderComponent(
|
|
5
|
+
(WrappedComponent) => pure((ownProps) => {
|
|
6
|
+
const mapSelect = (select, registry) => mapSelectToProps(select, ownProps, registry);
|
|
7
|
+
const mergeProps = useSelect(mapSelect);
|
|
8
|
+
return /* @__PURE__ */ jsx(WrappedComponent, { ...ownProps, ...mergeProps });
|
|
9
|
+
}),
|
|
10
|
+
"withSelect"
|
|
11
|
+
);
|
|
12
|
+
var with_select_default = withSelect;
|
|
13
|
+
export {
|
|
14
|
+
with_select_default as default
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/with-select/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent, pure } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useSelect from '../use-select';\n\n/** @typedef {import('react').ComponentType} ComponentType */\n\n/**\n * Higher-order component used to inject state-derived props using registered\n * selectors.\n *\n * @param {Function} mapSelectToProps Function called on every state change,\n * expected to return object of props to\n * merge with the component's own props.\n *\n * @example\n * ```js\n * import { withSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function PriceDisplay( { price, currency } ) {\n * \treturn new Intl.NumberFormat( 'en-US', {\n * \t\tstyle: 'currency',\n * \t\tcurrency,\n * \t} ).format( price );\n * }\n *\n * const HammerPriceDisplay = withSelect( ( select, ownProps ) => {\n * \tconst { getPrice } = select( myCustomStore );\n * \tconst { currency } = ownProps;\n *\n * \treturn {\n * \t\tprice: getPrice( 'hammer', currency ),\n * \t};\n * } )( PriceDisplay );\n *\n * // Rendered in the application:\n * //\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, it will pass the price into the underlying `PriceDisplay`\n * component and update automatically if the price of a hammer ever changes in\n * the store.\n *\n * @return {ComponentType} Enhanced component with merged state data props.\n */\nconst withSelect = ( mapSelectToProps ) =>\n\tcreateHigherOrderComponent(\n\t\t( WrappedComponent ) =>\n\t\t\tpure( ( ownProps ) => {\n\t\t\t\tconst mapSelect = ( select, registry ) =>\n\t\t\t\t\tmapSelectToProps( select, ownProps, registry );\n\t\t\t\tconst mergeProps = useSelect( mapSelect );\n\t\t\t\treturn <WrappedComponent { ...ownProps } { ...mergeProps } />;\n\t\t\t} ),\n\t\t'withSelect'\n\t);\n\nexport default withSelect;\n"],
|
|
5
|
+
"mappings": "AA2DW;AAxDX,SAAS,4BAA4B,YAAY;AAKjD,OAAO,eAAe;AA4CtB,MAAM,aAAa,CAAE,qBACpB;AAAA,EACC,CAAE,qBACD,KAAM,CAAE,aAAc;AACrB,UAAM,YAAY,CAAE,QAAQ,aAC3B,iBAAkB,QAAQ,UAAU,QAAS;AAC9C,UAAM,aAAa,UAAW,SAAU;AACxC,WAAO,oBAAC,oBAAmB,GAAG,UAAa,GAAG,YAAa;AAAA,EAC5D,CAAE;AAAA,EACH;AACD;AAED,IAAO,sBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/controls.js
CHANGED
|
@@ -1,40 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
7
|
-
|
|
8
|
-
const SELECT = '@@data/SELECT';
|
|
9
|
-
const RESOLVE_SELECT = '@@data/RESOLVE_SELECT';
|
|
10
|
-
const DISPATCH = '@@data/DISPATCH';
|
|
1
|
+
import { createRegistryControl } from "./factory";
|
|
2
|
+
const SELECT = "@@data/SELECT";
|
|
3
|
+
const RESOLVE_SELECT = "@@data/RESOLVE_SELECT";
|
|
4
|
+
const DISPATCH = "@@data/DISPATCH";
|
|
11
5
|
function isObject(object) {
|
|
12
|
-
return object !== null && typeof object ===
|
|
6
|
+
return object !== null && typeof object === "object";
|
|
13
7
|
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Dispatches a control action for triggering a synchronous registry select.
|
|
17
|
-
*
|
|
18
|
-
* Note: This control synchronously returns the current selector value, triggering the
|
|
19
|
-
* resolution, but not waiting for it.
|
|
20
|
-
*
|
|
21
|
-
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
22
|
-
* @param {string} selectorName The name of the selector.
|
|
23
|
-
* @param {Array} args Arguments for the selector.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```js
|
|
27
|
-
* import { controls } from '@wordpress/data';
|
|
28
|
-
*
|
|
29
|
-
* // Action generator using `select`.
|
|
30
|
-
* export function* myAction() {
|
|
31
|
-
* const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );
|
|
32
|
-
* // Do stuff with the result from the `select`.
|
|
33
|
-
* }
|
|
34
|
-
* ```
|
|
35
|
-
*
|
|
36
|
-
* @return {Object} The control descriptor.
|
|
37
|
-
*/
|
|
38
8
|
function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
39
9
|
return {
|
|
40
10
|
type: SELECT,
|
|
@@ -43,31 +13,6 @@ function select(storeNameOrDescriptor, selectorName, ...args) {
|
|
|
43
13
|
args
|
|
44
14
|
};
|
|
45
15
|
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Dispatches a control action for triggering and resolving a registry select.
|
|
49
|
-
*
|
|
50
|
-
* Note: when this control action is handled, it automatically considers
|
|
51
|
-
* selectors that may have a resolver. In such case, it will return a `Promise` that resolves
|
|
52
|
-
* after the selector finishes resolving, with the final result value.
|
|
53
|
-
*
|
|
54
|
-
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
55
|
-
* @param {string} selectorName The name of the selector
|
|
56
|
-
* @param {Array} args Arguments for the selector.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
* ```js
|
|
60
|
-
* import { controls } from '@wordpress/data';
|
|
61
|
-
*
|
|
62
|
-
* // Action generator using resolveSelect
|
|
63
|
-
* export function* myAction() {
|
|
64
|
-
* const isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );
|
|
65
|
-
* // do stuff with the result from the select.
|
|
66
|
-
* }
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* @return {Object} The control descriptor.
|
|
70
|
-
*/
|
|
71
16
|
function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
72
17
|
return {
|
|
73
18
|
type: RESOLVE_SELECT,
|
|
@@ -76,27 +21,6 @@ function resolveSelect(storeNameOrDescriptor, selectorName, ...args) {
|
|
|
76
21
|
args
|
|
77
22
|
};
|
|
78
23
|
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Dispatches a control action for triggering a registry dispatch.
|
|
82
|
-
*
|
|
83
|
-
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
84
|
-
* @param {string} actionName The name of the action to dispatch
|
|
85
|
-
* @param {Array} args Arguments for the dispatch action.
|
|
86
|
-
*
|
|
87
|
-
* @example
|
|
88
|
-
* ```js
|
|
89
|
-
* import { controls } from '@wordpress/data-controls';
|
|
90
|
-
*
|
|
91
|
-
* // Action generator using dispatch
|
|
92
|
-
* export function* myAction() {
|
|
93
|
-
* yield controls.dispatch( 'core/editor', 'togglePublishSidebar' );
|
|
94
|
-
* // do some other things.
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* @return {Object} The control descriptor.
|
|
99
|
-
*/
|
|
100
24
|
function dispatch(storeNameOrDescriptor, actionName, ...args) {
|
|
101
25
|
return {
|
|
102
26
|
type: DISPATCH,
|
|
@@ -105,29 +29,25 @@ function dispatch(storeNameOrDescriptor, actionName, ...args) {
|
|
|
105
29
|
args
|
|
106
30
|
};
|
|
107
31
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
32
|
+
const controls = { select, resolveSelect, dispatch };
|
|
33
|
+
const builtinControls = {
|
|
34
|
+
[SELECT]: createRegistryControl(
|
|
35
|
+
(registry) => ({ storeKey, selectorName, args }) => registry.select(storeKey)[selectorName](...args)
|
|
36
|
+
),
|
|
37
|
+
[RESOLVE_SELECT]: createRegistryControl(
|
|
38
|
+
(registry) => ({ storeKey, selectorName, args }) => {
|
|
39
|
+
const method = registry.select(storeKey)[selectorName].hasResolver ? "resolveSelect" : "select";
|
|
40
|
+
return registry[method](storeKey)[selectorName](
|
|
41
|
+
...args
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
),
|
|
45
|
+
[DISPATCH]: createRegistryControl(
|
|
46
|
+
(registry) => ({ storeKey, actionName, args }) => registry.dispatch(storeKey)[actionName](...args)
|
|
47
|
+
)
|
|
112
48
|
};
|
|
113
|
-
export
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
selectorName,
|
|
117
|
-
args
|
|
118
|
-
}) => registry.select(storeKey)[selectorName](...args)),
|
|
119
|
-
[RESOLVE_SELECT]: createRegistryControl(registry => ({
|
|
120
|
-
storeKey,
|
|
121
|
-
selectorName,
|
|
122
|
-
args
|
|
123
|
-
}) => {
|
|
124
|
-
const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select';
|
|
125
|
-
return registry[method](storeKey)[selectorName](...args);
|
|
126
|
-
}),
|
|
127
|
-
[DISPATCH]: createRegistryControl(registry => ({
|
|
128
|
-
storeKey,
|
|
129
|
-
actionName,
|
|
130
|
-
args
|
|
131
|
-
}) => registry.dispatch(storeKey)[actionName](...args))
|
|
49
|
+
export {
|
|
50
|
+
builtinControls,
|
|
51
|
+
controls
|
|
132
52
|
};
|
|
133
|
-
//# sourceMappingURL=controls.js.map
|
|
53
|
+
//# sourceMappingURL=controls.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/controls.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\nfunction isObject( object ) {\n\treturn object !== null && typeof object === 'object';\n}\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/editor', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDescriptor, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) =>\n\t\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) => {\n\t\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t\t.hasResolver\n\t\t\t\t\t? 'resolveSelect'\n\t\t\t\t\t: 'select';\n\t\t\t\treturn registry[ method ]( storeKey )[ selectorName ](\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, actionName, args } ) =>\n\t\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,6BAA6B;AAItC,MAAM,SAAS;AACf,MAAM,iBAAiB;AACvB,MAAM,WAAW;AAEjB,SAAS,SAAU,QAAS;AAC3B,SAAO,WAAW,QAAQ,OAAO,WAAW;AAC7C;AAyBA,SAAS,OAAQ,uBAAuB,iBAAiB,MAAO;AAC/D,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,SAAU,qBAAsB,IACvC,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AA0BA,SAAS,cAAe,uBAAuB,iBAAiB,MAAO;AACtE,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,SAAU,qBAAsB,IACvC,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AAsBA,SAAS,SAAU,uBAAuB,eAAe,MAAO;AAC/D,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU,SAAU,qBAAsB,IACvC,sBAAsB,OACtB;AAAA,IACH;AAAA,IACA;AAAA,EACD;AACD;AAEO,MAAM,WAAW,EAAE,QAAQ,eAAe,SAAS;AAEnD,MAAM,kBAAkB;AAAA,EAC9B,CAAE,MAAO,GAAG;AAAA,IACX,CAAE,aACD,CAAE,EAAE,UAAU,cAAc,KAAK,MAChC,SAAS,OAAQ,QAAS,EAAG,YAAa,EAAG,GAAG,IAAK;AAAA,EACxD;AAAA,EACA,CAAE,cAAe,GAAG;AAAA,IACnB,CAAE,aACD,CAAE,EAAE,UAAU,cAAc,KAAK,MAAO;AACvC,YAAM,SAAS,SAAS,OAAQ,QAAS,EAAG,YAAa,EACvD,cACC,kBACA;AACH,aAAO,SAAU,MAAO,EAAG,QAAS,EAAG,YAAa;AAAA,QACnD,GAAG;AAAA,MACJ;AAAA,IACD;AAAA,EACF;AAAA,EACA,CAAE,QAAS,GAAG;AAAA,IACb,CAAE,aACD,CAAE,EAAE,UAAU,YAAY,KAAK,MAC9B,SAAS,SAAU,QAAS,EAAG,UAAW,EAAG,GAAG,IAAK;AAAA,EACxD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
7
|
-
export { default as createSelector } from 'rememo';
|
|
8
|
-
//# sourceMappingURL=create-selector.js.map
|
|
1
|
+
import { default as default2 } from "rememo";
|
|
2
|
+
export {
|
|
3
|
+
default2 as createSelector
|
|
4
|
+
};
|
|
5
|
+
//# sourceMappingURL=create-selector.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/create-selector.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Creates a memoized selector that caches the computed values according to the array of \"dependants\"\n * and the selector parameters, and recomputes the values only when any of them changes.\n *\n * @see The documentation for the `rememo` package from which the `createSelector` function is reexported.\n */\nexport { default as createSelector } from 'rememo';\n"],
|
|
5
|
+
"mappings": "AAMA,SAAoB,WAAXA,gBAAiC;",
|
|
6
|
+
"names": ["default"]
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//# sourceMappingURL=default-registry.js.map
|
|
1
|
+
import { createRegistry } from "./registry";
|
|
2
|
+
var default_registry_default = createRegistry();
|
|
3
|
+
export {
|
|
4
|
+
default_registry_default as default
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=default-registry.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/default-registry.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { createRegistry } from './registry';\n\nexport default createRegistry();\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,sBAAsB;AAE/B,IAAO,2BAAQ,eAAe;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/dispatch.js
CHANGED
|
@@ -1,29 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import defaultRegistry from './default-registry';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Given a store descriptor, returns an object of the store's action creators.
|
|
9
|
-
* Calling an action creator will cause it to be dispatched, updating the state value accordingly.
|
|
10
|
-
*
|
|
11
|
-
* Note: Action creators returned by the dispatch will return a promise when
|
|
12
|
-
* they are called.
|
|
13
|
-
*
|
|
14
|
-
* @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing
|
|
15
|
-
* the store name is also supported.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```js
|
|
19
|
-
* import { dispatch } from '@wordpress/data';
|
|
20
|
-
* import { store as myCustomStore } from 'my-custom-store';
|
|
21
|
-
*
|
|
22
|
-
* dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );
|
|
23
|
-
* ```
|
|
24
|
-
* @return Object containing the action creators.
|
|
25
|
-
*/
|
|
26
|
-
export function dispatch(storeNameOrDescriptor) {
|
|
1
|
+
import defaultRegistry from "./default-registry";
|
|
2
|
+
function dispatch(storeNameOrDescriptor) {
|
|
27
3
|
return defaultRegistry.dispatch(storeNameOrDescriptor);
|
|
28
4
|
}
|
|
29
|
-
|
|
5
|
+
export {
|
|
6
|
+
dispatch
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=dispatch.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/dispatch.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, StoreDescriptor, DispatchReturn } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, returns an object of the store's action creators.\n * Calling an action creator will cause it to be dispatched, updating the state value accordingly.\n *\n * Note: Action creators returned by the dispatch will return a promise when\n * they are called.\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing\n * the store name is also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return Object containing the action creators.\n */\nexport function dispatch<\n\tStoreNameOrDescriptor extends StoreDescriptor< AnyConfig > | string,\n>(\n\tstoreNameOrDescriptor: StoreNameOrDescriptor\n): DispatchReturn< StoreNameOrDescriptor > {\n\treturn defaultRegistry.dispatch( storeNameOrDescriptor );\n}\n"],
|
|
5
|
+
"mappings": "AAIA,OAAO,qBAAqB;AAqBrB,SAAS,SAGf,uBAC0C;AAC1C,SAAO,gBAAgB,SAAU,qBAAsB;AACxD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/factory.js
CHANGED
|
@@ -1,96 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Creates a selector function that takes additional curried argument with the
|
|
7
|
-
* registry `select` function. While a regular selector has signature
|
|
8
|
-
* ```js
|
|
9
|
-
* ( state, ...selectorArgs ) => ( result )
|
|
10
|
-
* ```
|
|
11
|
-
* that allows to select data from the store's `state`, a registry selector
|
|
12
|
-
* has signature:
|
|
13
|
-
* ```js
|
|
14
|
-
* ( select ) => ( state, ...selectorArgs ) => ( result )
|
|
15
|
-
* ```
|
|
16
|
-
* that supports also selecting from other registered stores.
|
|
17
|
-
*
|
|
18
|
-
* @example
|
|
19
|
-
* ```js
|
|
20
|
-
* import { store as coreStore } from '@wordpress/core-data';
|
|
21
|
-
* import { store as editorStore } from '@wordpress/editor';
|
|
22
|
-
*
|
|
23
|
-
* const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {
|
|
24
|
-
* return select( editorStore ).getCurrentPostId();
|
|
25
|
-
* } );
|
|
26
|
-
*
|
|
27
|
-
* const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
|
|
28
|
-
* // calling another registry selector just like any other function
|
|
29
|
-
* const postType = getCurrentPostType( state );
|
|
30
|
-
* const postId = getCurrentPostId( state );
|
|
31
|
-
* return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );
|
|
32
|
-
* } );
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* Note how the `getCurrentPostId` selector can be called just like any other function,
|
|
36
|
-
* (it works even inside a regular non-registry selector) and we don't need to pass the
|
|
37
|
-
* registry as argument. The registry binding happens automatically when registering the selector
|
|
38
|
-
* with a store.
|
|
39
|
-
*
|
|
40
|
-
* @param registrySelector Function receiving a registry `select`
|
|
41
|
-
* function and returning a state selector.
|
|
42
|
-
*
|
|
43
|
-
* @return Registry selector that can be registered with a store.
|
|
44
|
-
*/
|
|
45
|
-
export function createRegistrySelector(registrySelector) {
|
|
46
|
-
const selectorsByRegistry = new WeakMap();
|
|
47
|
-
// Create a selector function that is bound to the registry referenced by `selector.registry`
|
|
48
|
-
// and that has the same API as a regular selector. Binding it in such a way makes it
|
|
49
|
-
// possible to call the selector directly from another selector.
|
|
1
|
+
function createRegistrySelector(registrySelector) {
|
|
2
|
+
const selectorsByRegistry = /* @__PURE__ */ new WeakMap();
|
|
50
3
|
const wrappedSelector = (...args) => {
|
|
51
4
|
let selector = selectorsByRegistry.get(wrappedSelector.registry);
|
|
52
|
-
// We want to make sure the cache persists even when new registry
|
|
53
|
-
// instances are created. For example patterns create their own editors
|
|
54
|
-
// with their own core/block-editor stores, so we should keep track of
|
|
55
|
-
// the cache for each registry instance.
|
|
56
5
|
if (!selector) {
|
|
57
6
|
selector = registrySelector(wrappedSelector.registry.select);
|
|
58
7
|
selectorsByRegistry.set(wrappedSelector.registry, selector);
|
|
59
8
|
}
|
|
60
9
|
return selector(...args);
|
|
61
10
|
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Flag indicating that the selector is a registry selector that needs the correct registry
|
|
65
|
-
* reference to be assigned to `selector.registry` to make it work correctly.
|
|
66
|
-
* be mapped as a registry selector.
|
|
67
|
-
*/
|
|
68
11
|
wrappedSelector.isRegistrySelector = true;
|
|
69
12
|
return wrappedSelector;
|
|
70
13
|
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Creates a control function that takes additional curried argument with the `registry` object.
|
|
74
|
-
* While a regular control has signature
|
|
75
|
-
* ```js
|
|
76
|
-
* ( action ) => ( iteratorOrPromise )
|
|
77
|
-
* ```
|
|
78
|
-
* where the control works with the `action` that it's bound to, a registry control has signature:
|
|
79
|
-
* ```js
|
|
80
|
-
* ( registry ) => ( action ) => ( iteratorOrPromise )
|
|
81
|
-
* ```
|
|
82
|
-
* A registry control is typically used to select data or dispatch an action to a registered
|
|
83
|
-
* store.
|
|
84
|
-
*
|
|
85
|
-
* When registering a control created with `createRegistryControl` with a store, the store
|
|
86
|
-
* knows which calling convention to use when executing the control.
|
|
87
|
-
*
|
|
88
|
-
* @param registryControl Function receiving a registry object and returning a control.
|
|
89
|
-
*
|
|
90
|
-
* @return Registry control that can be registered with a store.
|
|
91
|
-
*/
|
|
92
|
-
export function createRegistryControl(registryControl) {
|
|
14
|
+
function createRegistryControl(registryControl) {
|
|
93
15
|
registryControl.isRegistryControl = true;
|
|
94
16
|
return registryControl;
|
|
95
17
|
}
|
|
96
|
-
|
|
18
|
+
export {
|
|
19
|
+
createRegistryControl,
|
|
20
|
+
createRegistrySelector
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=factory.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/factory.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { select as globalSelect } from './select';\n\ntype RegistrySelector< Selector extends ( ...args: any[] ) => any > = {\n\t( ...args: Parameters< Selector > ): ReturnType< Selector >;\n\tisRegistrySelector?: boolean;\n\tregistry?: any;\n};\n\n/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector<\n\tSelector extends ( ...args: any[] ) => any,\n>(\n\tregistrySelector: ( select: typeof globalSelect ) => Selector\n): RegistrySelector< Selector > {\n\tconst selectorsByRegistry = new WeakMap();\n\t// Create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst wrappedSelector: RegistrySelector< Selector > = ( ...args ) => {\n\t\tlet selector = selectorsByRegistry.get( wrappedSelector.registry );\n\t\t// We want to make sure the cache persists even when new registry\n\t\t// instances are created. For example patterns create their own editors\n\t\t// with their own core/block-editor stores, so we should keep track of\n\t\t// the cache for each registry instance.\n\t\tif ( ! selector ) {\n\t\t\tselector = registrySelector( wrappedSelector.registry.select );\n\t\t\tselectorsByRegistry.set( wrappedSelector.registry, selector );\n\t\t}\n\t\treturn selector( ...args );\n\t};\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t */\n\twrappedSelector.isRegistrySelector = true;\n\n\treturn wrappedSelector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param registryControl Function receiving a registry object and returning a control.\n *\n * @return Registry control that can be registered with a store.\n */\nexport function createRegistryControl< T extends ( ...args: any ) => any >(\n\tregistryControl: T & { isRegistryControl?: boolean }\n) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"],
|
|
5
|
+
"mappings": "AAmDO,SAAS,uBAGf,kBAC+B;AAC/B,QAAM,sBAAsB,oBAAI,QAAQ;AAIxC,QAAM,kBAAgD,IAAK,SAAU;AACpE,QAAI,WAAW,oBAAoB,IAAK,gBAAgB,QAAS;AAKjE,QAAK,CAAE,UAAW;AACjB,iBAAW,iBAAkB,gBAAgB,SAAS,MAAO;AAC7D,0BAAoB,IAAK,gBAAgB,UAAU,QAAS;AAAA,IAC7D;AACA,WAAO,SAAU,GAAG,IAAK;AAAA,EAC1B;AAOA,kBAAgB,qBAAqB;AAErC,SAAO;AACR;AAsBO,SAAS,sBACf,iBACC;AACD,kBAAgB,oBAAoB;AAEpC,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|