@wordpress/data 6.12.0 → 6.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +39 -27
- package/build/components/async-mode-provider/context.js +2 -1
- package/build/components/async-mode-provider/context.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +3 -2
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/use-select/index.js +5 -2
- package/build/components/use-select/index.js.map +1 -1
- package/build/components/with-dispatch/index.js +5 -3
- package/build/components/with-dispatch/index.js.map +1 -1
- package/build/components/with-select/index.js +2 -1
- package/build/components/with-select/index.js.map +1 -1
- package/build/controls.js +8 -9
- package/build/controls.js.map +1 -1
- package/build/factory.js +5 -2
- package/build/factory.js.map +1 -1
- package/build/index.js +26 -20
- package/build/index.js.map +1 -1
- package/build/registry.js +21 -16
- package/build/registry.js.map +1 -1
- package/build-module/components/async-mode-provider/context.js +2 -1
- package/build-module/components/async-mode-provider/context.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +3 -2
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/use-select/index.js +6 -3
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/components/with-dispatch/index.js +5 -3
- package/build-module/components/with-dispatch/index.js.map +1 -1
- package/build-module/components/with-select/index.js +2 -1
- package/build-module/components/with-select/index.js.map +1 -1
- package/build-module/controls.js +5 -5
- package/build-module/controls.js.map +1 -1
- package/build-module/factory.js +5 -2
- package/build-module/factory.js.map +1 -1
- package/build-module/index.js +26 -20
- package/build-module/index.js.map +1 -1
- package/build-module/registry.js +17 -12
- package/build-module/registry.js.map +1 -1
- package/build-types/components/async-mode-provider/context.d.ts +5 -0
- package/build-types/components/async-mode-provider/context.d.ts.map +1 -0
- package/build-types/components/async-mode-provider/index.d.ts +3 -0
- package/build-types/components/async-mode-provider/index.d.ts.map +1 -0
- package/build-types/components/async-mode-provider/use-async-mode.d.ts +2 -0
- package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -0
- package/build-types/components/registry-provider/context.d.ts +36 -0
- package/build-types/components/registry-provider/context.d.ts.map +1 -0
- package/build-types/components/registry-provider/index.d.ts +3 -0
- package/build-types/components/registry-provider/index.d.ts.map +1 -0
- package/build-types/components/registry-provider/use-registry.d.ts +41 -0
- package/build-types/components/registry-provider/use-registry.d.ts.map +1 -0
- package/build-types/components/use-dispatch/index.d.ts +3 -0
- package/build-types/components/use-dispatch/index.d.ts.map +1 -0
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +17 -0
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -0
- package/build-types/components/use-dispatch/use-dispatch.d.ts +50 -0
- package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -0
- package/build-types/components/use-select/index.d.ts +99 -0
- package/build-types/components/use-select/index.d.ts.map +1 -0
- package/build-types/components/with-dispatch/index.d.ts +84 -0
- package/build-types/components/with-dispatch/index.d.ts.map +1 -0
- package/build-types/components/with-registry/index.d.ts +11 -0
- package/build-types/components/with-registry/index.d.ts.map +1 -0
- package/build-types/components/with-select/index.d.ts +43 -0
- package/build-types/components/with-select/index.d.ts.map +1 -0
- package/build-types/controls.d.ts +83 -0
- package/build-types/controls.d.ts.map +1 -0
- package/build-types/default-registry.d.ts +3 -0
- package/build-types/default-registry.d.ts.map +1 -0
- package/build-types/factory.d.ts +63 -0
- package/build-types/factory.d.ts.map +1 -0
- package/build-types/index.d.ts +156 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/plugins/index.d.ts +2 -0
- package/build-types/plugins/index.d.ts.map +1 -0
- package/build-types/plugins/persistence/index.d.ts +41 -0
- package/build-types/plugins/persistence/index.d.ts.map +1 -0
- package/build-types/plugins/persistence/storage/default.d.ts +3 -0
- package/build-types/plugins/persistence/storage/default.d.ts.map +1 -0
- package/build-types/plugins/persistence/storage/object.d.ts +10 -0
- package/build-types/plugins/persistence/storage/object.d.ts.map +1 -0
- package/build-types/redux-store/index.d.ts +29 -0
- package/build-types/redux-store/index.d.ts.map +1 -0
- package/build-types/redux-store/thunk-middleware.d.ts +2 -0
- package/build-types/redux-store/thunk-middleware.d.ts.map +1 -0
- package/build-types/registry.d.ts +56 -0
- package/build-types/registry.d.ts.map +1 -0
- package/build-types/resolvers-cache-middleware.d.ts +15 -0
- package/build-types/resolvers-cache-middleware.d.ts.map +1 -0
- package/build-types/store/index.d.ts +23 -0
- package/build-types/store/index.d.ts.map +1 -0
- package/package.json +8 -8
- package/src/components/async-mode-provider/context.js +2 -1
- package/src/components/use-dispatch/use-dispatch.js +3 -2
- package/src/components/use-select/index.js +13 -3
- package/src/components/with-dispatch/index.js +5 -3
- package/src/components/with-select/index.js +2 -1
- package/src/controls.js +4 -5
- package/src/factory.js +5 -2
- package/src/index.js +26 -20
- package/src/registry.js +17 -12
- package/tsconfig.json +4 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
export { default as withSelect } from "./components/with-select";
|
|
2
|
+
export { default as withDispatch } from "./components/with-dispatch";
|
|
3
|
+
export { default as withRegistry } from "./components/with-registry";
|
|
4
|
+
export { useDispatch } from "./components/use-dispatch";
|
|
5
|
+
export { AsyncModeProvider } from "./components/async-mode-provider";
|
|
6
|
+
export { createRegistry } from "./registry";
|
|
7
|
+
export { controls } from "./controls";
|
|
8
|
+
export { default as createReduxStore } from "./redux-store";
|
|
9
|
+
/**
|
|
10
|
+
* Given a store descriptor, returns an object of the store's selectors.
|
|
11
|
+
* The selector functions are been pre-bound to pass the current state automatically.
|
|
12
|
+
* As a consumer, you need only pass arguments of the selector, if applicable.
|
|
13
|
+
*
|
|
14
|
+
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
15
|
+
* convention of passing the store name is
|
|
16
|
+
* also supported.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```js
|
|
20
|
+
* import { select } from '@wordpress/data';
|
|
21
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
22
|
+
*
|
|
23
|
+
* select( myCustomStore ).getPrice( 'hammer' );
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @return {Object} Object containing the store's selectors.
|
|
27
|
+
*/
|
|
28
|
+
export const select: Function;
|
|
29
|
+
/**
|
|
30
|
+
* Given a store descriptor, returns an object containing the store's selectors pre-bound to state
|
|
31
|
+
* so that you only need to supply additional arguments, and modified so that they return promises
|
|
32
|
+
* that resolve to their eventual values, after any resolvers have ran.
|
|
33
|
+
*
|
|
34
|
+
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
35
|
+
* convention of passing the store name is
|
|
36
|
+
* also supported.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```js
|
|
40
|
+
* import { resolveSelect } from '@wordpress/data';
|
|
41
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
42
|
+
*
|
|
43
|
+
* resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @return {Object} Object containing the store's promise-wrapped selectors.
|
|
47
|
+
*/
|
|
48
|
+
export const resolveSelect: any;
|
|
49
|
+
/**
|
|
50
|
+
* Given a store descriptor, returns an object containing the store's selectors pre-bound to state
|
|
51
|
+
* so that you only need to supply additional arguments, and modified so that they throw promises
|
|
52
|
+
* in case the selector is not resolved yet.
|
|
53
|
+
*
|
|
54
|
+
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
55
|
+
* convention of passing the store name is
|
|
56
|
+
* also supported.
|
|
57
|
+
*
|
|
58
|
+
* @return {Object} Object containing the store's suspense-wrapped selectors.
|
|
59
|
+
*/
|
|
60
|
+
export const suspendSelect: any;
|
|
61
|
+
/**
|
|
62
|
+
* Given a store descriptor, returns an object of the store's action creators.
|
|
63
|
+
* Calling an action creator will cause it to be dispatched, updating the state value accordingly.
|
|
64
|
+
*
|
|
65
|
+
* Note: Action creators returned by the dispatch will return a promise when
|
|
66
|
+
* they are called.
|
|
67
|
+
*
|
|
68
|
+
* @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling
|
|
69
|
+
* convention of passing the store name is
|
|
70
|
+
* also supported.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```js
|
|
74
|
+
* import { dispatch } from '@wordpress/data';
|
|
75
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
76
|
+
*
|
|
77
|
+
* dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );
|
|
78
|
+
* ```
|
|
79
|
+
* @return {Object} Object containing the action creators.
|
|
80
|
+
*/
|
|
81
|
+
export const dispatch: Function;
|
|
82
|
+
/**
|
|
83
|
+
* Given a listener function, the function will be called any time the state value
|
|
84
|
+
* of one of the registered stores has changed. This function returns a `unsubscribe`
|
|
85
|
+
* function used to stop the subscription.
|
|
86
|
+
*
|
|
87
|
+
* @param {Function} listener Callback function.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```js
|
|
91
|
+
* import { subscribe } from '@wordpress/data';
|
|
92
|
+
*
|
|
93
|
+
* const unsubscribe = subscribe( () => {
|
|
94
|
+
* // You could use this opportunity to test whether the derived result of a
|
|
95
|
+
* // selector has subsequently changed as the result of a state update.
|
|
96
|
+
* } );
|
|
97
|
+
*
|
|
98
|
+
* // Later, if necessary...
|
|
99
|
+
* unsubscribe();
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export const subscribe: Function;
|
|
103
|
+
/**
|
|
104
|
+
* Registers a generic store instance.
|
|
105
|
+
*
|
|
106
|
+
* @deprecated Use `register( storeDescriptor )` instead.
|
|
107
|
+
*
|
|
108
|
+
* @param {string} name Store registry name.
|
|
109
|
+
* @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).
|
|
110
|
+
*/
|
|
111
|
+
export const registerGenericStore: Function;
|
|
112
|
+
/**
|
|
113
|
+
* Registers a standard `@wordpress/data` store.
|
|
114
|
+
*
|
|
115
|
+
* @deprecated Use `register` instead.
|
|
116
|
+
*
|
|
117
|
+
* @param {string} storeName Unique namespace identifier for the store.
|
|
118
|
+
* @param {Object} options Store description (reducer, actions, selectors, resolvers).
|
|
119
|
+
*
|
|
120
|
+
* @return {Object} Registered store object.
|
|
121
|
+
*/
|
|
122
|
+
export const registerStore: Function;
|
|
123
|
+
/**
|
|
124
|
+
* Extends a registry to inherit functionality provided by a given plugin. A
|
|
125
|
+
* plugin is an object with properties aligning to that of a registry, merged
|
|
126
|
+
* to extend the default registry behavior.
|
|
127
|
+
*
|
|
128
|
+
* @param {Object} plugin Plugin object.
|
|
129
|
+
*/
|
|
130
|
+
export const use: any;
|
|
131
|
+
/**
|
|
132
|
+
* Registers a standard `@wordpress/data` store descriptor.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```js
|
|
136
|
+
* import { createReduxStore, register } from '@wordpress/data';
|
|
137
|
+
*
|
|
138
|
+
* const store = createReduxStore( 'demo', {
|
|
139
|
+
* reducer: ( state = 'OK' ) => state,
|
|
140
|
+
* selectors: {
|
|
141
|
+
* getValue: ( state ) => state,
|
|
142
|
+
* },
|
|
143
|
+
* } );
|
|
144
|
+
* register( store );
|
|
145
|
+
* ```
|
|
146
|
+
*
|
|
147
|
+
* @param {StoreDescriptor} store Store descriptor.
|
|
148
|
+
*/
|
|
149
|
+
export const register: any;
|
|
150
|
+
export type StoreDescriptor = import("./types").StoreDescriptor<any>;
|
|
151
|
+
import * as plugins from "./plugins";
|
|
152
|
+
export { plugins, combineReducers };
|
|
153
|
+
export { RegistryProvider, RegistryConsumer, useRegistry } from "./components/registry-provider";
|
|
154
|
+
export { default as useSelect, useSuspenseSelect } from "./components/use-select";
|
|
155
|
+
export { createRegistrySelector, createRegistryControl } from "./factory";
|
|
156
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;AAiFA;;;;;;;;;;;;;;;;;;GAkBG;AACH,8BAA6C;AAE7C;;;;;;;;;;;;;;;;;;GAkBG;AACH,gCAA2D;AAE3D;;;;;;;;;;GAUG;AACH,gCAA2D;AAE3D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,gCAAiD;AAEjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,iCAAmD;AAEnD;;;;;;;GAOG;AACH,4CAAyE;AAEzE;;;;;;;;;GASG;AACH,qCAA2D;AAE3D;;;;;;GAMG;AACH,sBAAuC;AAEvC;;;;;;;;;;;;;;;;;GAiBG;AACH,2BAAiD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a persistence interface, exposing getter and setter methods (`get`
|
|
3
|
+
* and `set` respectively).
|
|
4
|
+
*
|
|
5
|
+
* @param {WPDataPersistencePluginOptions} options Plugin options.
|
|
6
|
+
*
|
|
7
|
+
* @return {Object} Persistence interface.
|
|
8
|
+
*/
|
|
9
|
+
export function createPersistenceInterface(options: WPDataPersistencePluginOptions): Object;
|
|
10
|
+
export function withLazySameState(reducer: Function): Function;
|
|
11
|
+
export default persistencePlugin;
|
|
12
|
+
export type WPDataRegistry = import('../../registry').WPDataRegistry;
|
|
13
|
+
export type WPDataPlugin = import('../../registry').WPDataPlugin;
|
|
14
|
+
/**
|
|
15
|
+
* Persistence plugin options.
|
|
16
|
+
*/
|
|
17
|
+
export type WPDataPersistencePluginOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* Persistent storage implementation. This must
|
|
20
|
+
* at least implement `getItem` and `setItem` of
|
|
21
|
+
* the Web Storage API.
|
|
22
|
+
*/
|
|
23
|
+
storage: Storage;
|
|
24
|
+
/**
|
|
25
|
+
* Key on which to set in persistent storage.
|
|
26
|
+
*/
|
|
27
|
+
storageKey: string;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Data plugin to persist store state into a single storage key.
|
|
31
|
+
*
|
|
32
|
+
* @param {WPDataRegistry} registry Data registry.
|
|
33
|
+
* @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.
|
|
34
|
+
*
|
|
35
|
+
* @return {WPDataPlugin} Data plugin.
|
|
36
|
+
*/
|
|
37
|
+
declare function persistencePlugin(registry: WPDataRegistry, pluginOptions: WPDataPersistencePluginOptions | null): WPDataPlugin;
|
|
38
|
+
declare namespace persistencePlugin {
|
|
39
|
+
function __unstableMigrate(): void;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/persistence/index.js"],"names":[],"mappings":"AAwDA;;;;;;;GAOG;AACH,oDAJW,8BAA8B,GAE7B,MAAM,CAiDjB;AA/DM,+DAMN;;6BA3Ca,OAAO,gBAAgB,EAAE,cAAc;2BAEvC,OAAO,gBAAgB,EAAE,YAAY;;;;;;;;;;aAKrC,OAAO;;;;gBAGP,MAAM;;AA4FpB;;;;;;;GAOG;AACH,6CALW,cAAc,iBACb,8BAA8B,UAE9B,YAAY,CAqGvB;;IAED,mCAA8C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../src/plugins/persistence/storage/default.js"],"names":[],"mappings":";AAKA,yBAAY"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export default storage;
|
|
2
|
+
declare namespace storage {
|
|
3
|
+
function getItem(key: any): any;
|
|
4
|
+
function getItem(key: any): any;
|
|
5
|
+
function setItem(key: any, value: any): void;
|
|
6
|
+
function setItem(key: any, value: any): void;
|
|
7
|
+
function clear(): void;
|
|
8
|
+
function clear(): void;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object.d.ts","sourceRoot":"","sources":["../../../../src/plugins/persistence/storage/object.js"],"names":[],"mappings":";;IAGC,gCAMC;IAND,gCAMC;IACD,6CAMC;IAND,6CAMC;IACD,uBAEC;IAFD,uBAEC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a data store descriptor for the provided Redux store configuration containing
|
|
3
|
+
* properties describing reducer, actions, selectors, controls and resolvers.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```js
|
|
7
|
+
* import { createReduxStore } from '@wordpress/data';
|
|
8
|
+
*
|
|
9
|
+
* const store = createReduxStore( 'demo', {
|
|
10
|
+
* reducer: ( state = 'OK' ) => state,
|
|
11
|
+
* selectors: {
|
|
12
|
+
* getValue: ( state ) => state,
|
|
13
|
+
* },
|
|
14
|
+
* } );
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @template State,Actions,Selectors
|
|
18
|
+
* @param {string} key Unique namespace identifier.
|
|
19
|
+
* @param {ReduxStoreConfig<State,Actions,Selectors>} options Registered store options, with properties
|
|
20
|
+
* describing reducer, actions, selectors,
|
|
21
|
+
* and resolvers.
|
|
22
|
+
*
|
|
23
|
+
* @return {StoreDescriptor<ReduxStoreConfig<State,Actions,Selectors>>} Store Object.
|
|
24
|
+
*/
|
|
25
|
+
export default function createReduxStore<State, Actions, Selectors>(key: string, options: import("../types").ReduxStoreConfig<State, Actions, Selectors>): import("../types").StoreDescriptor<import("../types").ReduxStoreConfig<State, Actions, Selectors>>;
|
|
26
|
+
export type DataRegistry = import('../types').DataRegistry;
|
|
27
|
+
export type StoreDescriptor<C> = import('../types').StoreDescriptor<C>;
|
|
28
|
+
export type ReduxStoreConfig<State, Actions, Selectors> = import('../types').ReduxStoreConfig<State, Actions, Selectors>;
|
|
29
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redux-store/index.js"],"names":[],"mappings":"AA2EA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,yEAPW,MAAM,+KA8HhB;2BAlMa,OAAO,UAAU,EAAE,YAAY;iCAEhC,OAAO,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC;0DAIrC,OAAO,UAAU,EAAE,gBAAgB,CAAC,KAAK,EAAC,OAAO,EAAC,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"thunk-middleware.d.ts","sourceRoot":"","sources":["../../src/redux-store/thunk-middleware.js"],"names":[],"mappings":"AAAA,oGAQC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new store registry, given an optional object of initial store
|
|
3
|
+
* configurations.
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} storeConfigs Initial store configurations.
|
|
6
|
+
* @param {Object?} parent Parent registry.
|
|
7
|
+
*
|
|
8
|
+
* @return {WPDataRegistry} Data registry.
|
|
9
|
+
*/
|
|
10
|
+
export function createRegistry(storeConfigs?: Object, parent?: Object | null): WPDataRegistry;
|
|
11
|
+
export type StoreDescriptor = import("./types").StoreDescriptor<any>;
|
|
12
|
+
/**
|
|
13
|
+
* An isolated orchestrator of store registrations.
|
|
14
|
+
*/
|
|
15
|
+
export type WPDataRegistry = {
|
|
16
|
+
/**
|
|
17
|
+
* Given a namespace key and settings
|
|
18
|
+
* object, registers a new generic
|
|
19
|
+
* store.
|
|
20
|
+
*/
|
|
21
|
+
registerGenericStore: Function;
|
|
22
|
+
/**
|
|
23
|
+
* Given a namespace key and settings
|
|
24
|
+
* object, registers a new namespace
|
|
25
|
+
* store.
|
|
26
|
+
*/
|
|
27
|
+
registerStore: Function;
|
|
28
|
+
/**
|
|
29
|
+
* Given a function callback, invokes
|
|
30
|
+
* the callback on any change to state
|
|
31
|
+
* within any registered store.
|
|
32
|
+
*/
|
|
33
|
+
subscribe: Function;
|
|
34
|
+
/**
|
|
35
|
+
* Given a namespace key, returns an
|
|
36
|
+
* object of the store's registered
|
|
37
|
+
* selectors.
|
|
38
|
+
*/
|
|
39
|
+
select: Function;
|
|
40
|
+
/**
|
|
41
|
+
* Given a namespace key, returns an
|
|
42
|
+
* object of the store's registered
|
|
43
|
+
* action dispatchers.
|
|
44
|
+
*/
|
|
45
|
+
dispatch: Function;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* An object of registry function overrides.
|
|
49
|
+
*/
|
|
50
|
+
export type WPDataPlugin = {
|
|
51
|
+
/**
|
|
52
|
+
* registers store.
|
|
53
|
+
*/
|
|
54
|
+
registerStore: Function;
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.js"],"names":[],"mappings":"AAiDA;;;;;;;;GAQG;AACH,8CALW,MAAM,WACN,MAAM,UAEL,cAAc,CAiSzB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export default createResolversCacheMiddleware;
|
|
2
|
+
export type WPDataRegistry = import('./registry').WPDataRegistry;
|
|
3
|
+
/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */
|
|
4
|
+
/**
|
|
5
|
+
* Creates a middleware handling resolvers cache invalidation.
|
|
6
|
+
*
|
|
7
|
+
* @param {WPDataRegistry} registry The registry reference for which to create
|
|
8
|
+
* the middleware.
|
|
9
|
+
* @param {string} reducerKey The namespace for which to create the
|
|
10
|
+
* middleware.
|
|
11
|
+
*
|
|
12
|
+
* @return {Function} Middleware function.
|
|
13
|
+
*/
|
|
14
|
+
declare function createResolversCacheMiddleware(registry: WPDataRegistry, reducerKey: string): Function;
|
|
15
|
+
//# sourceMappingURL=resolvers-cache-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolvers-cache-middleware.d.ts","sourceRoot":"","sources":["../src/resolvers-cache-middleware.js"],"names":[],"mappings":";6BAUc,OAAO,YAAY,EAAE,cAAc;AAAjD,oEAAoE;AAEpE;;;;;;;;;GASG;AACH,0DAPW,cAAc,cAEd,MAAM,YAwCf"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default coreDataStore;
|
|
2
|
+
declare namespace coreDataStore {
|
|
3
|
+
const name: string;
|
|
4
|
+
function instantiate(registry: any): {
|
|
5
|
+
getSelectors(): {
|
|
6
|
+
[k: string]: (key: any, ...args: any[]) => any;
|
|
7
|
+
};
|
|
8
|
+
getActions(): {
|
|
9
|
+
[k: string]: (key: any, ...args: any[]) => any;
|
|
10
|
+
};
|
|
11
|
+
subscribe(): () => () => void;
|
|
12
|
+
};
|
|
13
|
+
function instantiate(registry: any): {
|
|
14
|
+
getSelectors(): {
|
|
15
|
+
[k: string]: (key: any, ...args: any[]) => any;
|
|
16
|
+
};
|
|
17
|
+
getActions(): {
|
|
18
|
+
[k: string]: (key: any, ...args: any[]) => any;
|
|
19
|
+
};
|
|
20
|
+
subscribe(): () => () => void;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/store/index.js"],"names":[],"mappings":";;;IAEC;;;;;;;;MAoDC;IApDD;;;;;;;;MAoDC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.13.0",
|
|
4
4
|
"description": "Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -28,12 +28,12 @@
|
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@babel/runtime": "^7.16.0",
|
|
31
|
-
"@wordpress/compose": "^5.
|
|
32
|
-
"@wordpress/deprecated": "^3.
|
|
33
|
-
"@wordpress/element": "^4.
|
|
34
|
-
"@wordpress/is-shallow-equal": "^4.
|
|
35
|
-
"@wordpress/priority-queue": "^2.
|
|
36
|
-
"@wordpress/redux-routine": "^4.
|
|
31
|
+
"@wordpress/compose": "^5.11.0",
|
|
32
|
+
"@wordpress/deprecated": "^3.13.0",
|
|
33
|
+
"@wordpress/element": "^4.11.0",
|
|
34
|
+
"@wordpress/is-shallow-equal": "^4.13.0",
|
|
35
|
+
"@wordpress/priority-queue": "^2.13.0",
|
|
36
|
+
"@wordpress/redux-routine": "^4.13.0",
|
|
37
37
|
"equivalent-key-map": "^0.2.2",
|
|
38
38
|
"is-promise": "^4.0.0",
|
|
39
39
|
"lodash": "^4.17.21",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "9d9d33bbdf317a4381b8ca1713e43bb50df653b3"
|
|
51
51
|
}
|
|
@@ -17,10 +17,11 @@ export const AsyncModeConsumer = Consumer;
|
|
|
17
17
|
*
|
|
18
18
|
* ```js
|
|
19
19
|
* import { useSelect, AsyncModeProvider } from '@wordpress/data';
|
|
20
|
+
* import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
20
21
|
*
|
|
21
22
|
* function BlockCount() {
|
|
22
23
|
* const count = useSelect( ( select ) => {
|
|
23
|
-
* return select(
|
|
24
|
+
* return select( blockEditorStore ).getBlockCount()
|
|
24
25
|
* }, [] );
|
|
25
26
|
*
|
|
26
27
|
* return count;
|
|
@@ -25,6 +25,7 @@ import useRegistry from '../registry-provider/use-registry';
|
|
|
25
25
|
* ```jsx
|
|
26
26
|
* import { useDispatch, useSelect } from '@wordpress/data';
|
|
27
27
|
* import { useCallback } from '@wordpress/element';
|
|
28
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
28
29
|
*
|
|
29
30
|
* function Button( { onClick, children } ) {
|
|
30
31
|
* return <button type="button" onClick={ onClick }>{ children }</button>
|
|
@@ -32,10 +33,10 @@ import useRegistry from '../registry-provider/use-registry';
|
|
|
32
33
|
*
|
|
33
34
|
* const SaleButton = ( { children } ) => {
|
|
34
35
|
* const { stockNumber } = useSelect(
|
|
35
|
-
* ( select ) => select(
|
|
36
|
+
* ( select ) => select( myCustomStore ).getStockNumber(),
|
|
36
37
|
* []
|
|
37
38
|
* );
|
|
38
|
-
* const { startSale } = useDispatch(
|
|
39
|
+
* const { startSale } = useDispatch( myCustomStore );
|
|
39
40
|
* const onClick = useCallback( () => {
|
|
40
41
|
* const discountPercent = stockNumber > 50 ? 10: 20;
|
|
41
42
|
* startSale( discountPercent );
|
|
@@ -7,7 +7,13 @@ import { useMemoOne } from 'use-memo-one';
|
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
9
9
|
import { createQueue } from '@wordpress/priority-queue';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
useRef,
|
|
12
|
+
useCallback,
|
|
13
|
+
useMemo,
|
|
14
|
+
useReducer,
|
|
15
|
+
useDebugValue,
|
|
16
|
+
} from '@wordpress/element';
|
|
11
17
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
12
18
|
import { useIsomorphicLayoutEffect } from '@wordpress/compose';
|
|
13
19
|
|
|
@@ -54,10 +60,11 @@ const renderQueue = createQueue();
|
|
|
54
60
|
* @example
|
|
55
61
|
* ```js
|
|
56
62
|
* import { useSelect } from '@wordpress/data';
|
|
63
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
57
64
|
*
|
|
58
65
|
* function HammerPriceDisplay( { currency } ) {
|
|
59
66
|
* const price = useSelect( ( select ) => {
|
|
60
|
-
* return select(
|
|
67
|
+
* return select( myCustomStore ).getPrice( 'hammer', currency );
|
|
61
68
|
* }, [ currency ] );
|
|
62
69
|
* return new Intl.NumberFormat( 'en-US', {
|
|
63
70
|
* style: 'currency',
|
|
@@ -84,9 +91,10 @@ const renderQueue = createQueue();
|
|
|
84
91
|
*
|
|
85
92
|
* ```js
|
|
86
93
|
* import { useSelect } from '@wordpress/data';
|
|
94
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
87
95
|
*
|
|
88
96
|
* function Paste( { children } ) {
|
|
89
|
-
* const { getSettings } = useSelect(
|
|
97
|
+
* const { getSettings } = useSelect( myCustomStore );
|
|
90
98
|
* function onPaste() {
|
|
91
99
|
* // Do something with the settings.
|
|
92
100
|
* const settings = getSettings();
|
|
@@ -246,6 +254,8 @@ export default function useSelect( mapSelect, deps ) {
|
|
|
246
254
|
// examining every individual value inside the `deps` array.
|
|
247
255
|
}, [ registry, wrapSelect, hasMappingFunction, depsChangedFlag ] );
|
|
248
256
|
|
|
257
|
+
useDebugValue( mapOutput );
|
|
258
|
+
|
|
249
259
|
return hasMappingFunction ? mapOutput : registry.select( mapSelect );
|
|
250
260
|
}
|
|
251
261
|
|
|
@@ -26,9 +26,10 @@ import { useDispatchWithMap } from '../use-dispatch';
|
|
|
26
26
|
* }
|
|
27
27
|
*
|
|
28
28
|
* import { withDispatch } from '@wordpress/data';
|
|
29
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
29
30
|
*
|
|
30
31
|
* const SaleButton = withDispatch( ( dispatch, ownProps ) => {
|
|
31
|
-
* const { startSale } = dispatch(
|
|
32
|
+
* const { startSale } = dispatch( myCustomStore );
|
|
32
33
|
* const { discountPercent } = ownProps;
|
|
33
34
|
*
|
|
34
35
|
* return {
|
|
@@ -63,11 +64,12 @@ import { useDispatchWithMap } from '../use-dispatch';
|
|
|
63
64
|
* }
|
|
64
65
|
*
|
|
65
66
|
* import { withDispatch } from '@wordpress/data';
|
|
67
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
66
68
|
*
|
|
67
69
|
* const SaleButton = withDispatch( ( dispatch, ownProps, { select } ) => {
|
|
68
70
|
* // Stock number changes frequently.
|
|
69
|
-
* const { getStockNumber } = select(
|
|
70
|
-
* const { startSale } = dispatch(
|
|
71
|
+
* const { getStockNumber } = select( myCustomStore );
|
|
72
|
+
* const { startSale } = dispatch( myCustomStore );
|
|
71
73
|
* return {
|
|
72
74
|
* onClick() {
|
|
73
75
|
* const discountPercent = getStockNumber() > 50 ? 10 : 20;
|
|
@@ -19,6 +19,7 @@ import useSelect from '../use-select';
|
|
|
19
19
|
* @example
|
|
20
20
|
* ```js
|
|
21
21
|
* import { withSelect } from '@wordpress/data';
|
|
22
|
+
* import { store as myCustomStore } from 'my-custom-store';
|
|
22
23
|
*
|
|
23
24
|
* function PriceDisplay( { price, currency } ) {
|
|
24
25
|
* return new Intl.NumberFormat( 'en-US', {
|
|
@@ -28,7 +29,7 @@ import useSelect from '../use-select';
|
|
|
28
29
|
* }
|
|
29
30
|
*
|
|
30
31
|
* const HammerPriceDisplay = withSelect( ( select, ownProps ) => {
|
|
31
|
-
* const { getPrice } = select(
|
|
32
|
+
* const { getPrice } = select( myCustomStore );
|
|
32
33
|
* const { currency } = ownProps;
|
|
33
34
|
*
|
|
34
35
|
* return {
|
package/src/controls.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { isObject } from 'lodash';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* Internal dependencies
|
|
8
3
|
*/
|
|
@@ -14,6 +9,10 @@ const SELECT = '@@data/SELECT';
|
|
|
14
9
|
const RESOLVE_SELECT = '@@data/RESOLVE_SELECT';
|
|
15
10
|
const DISPATCH = '@@data/DISPATCH';
|
|
16
11
|
|
|
12
|
+
function isObject( object ) {
|
|
13
|
+
return object !== null && typeof object === 'object';
|
|
14
|
+
}
|
|
15
|
+
|
|
17
16
|
/**
|
|
18
17
|
* Dispatches a control action for triggering a synchronous registry select.
|
|
19
18
|
*
|
package/src/factory.js
CHANGED
|
@@ -13,15 +13,18 @@
|
|
|
13
13
|
*
|
|
14
14
|
* @example
|
|
15
15
|
* ```js
|
|
16
|
+
* import { store as coreStore } from '@wordpress/core-data';
|
|
17
|
+
* import { store as editorStore } from '@wordpress/editor';
|
|
18
|
+
*
|
|
16
19
|
* const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {
|
|
17
|
-
* return select(
|
|
20
|
+
* return select( editorStore ).getCurrentPostId();
|
|
18
21
|
* } );
|
|
19
22
|
*
|
|
20
23
|
* const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {
|
|
21
24
|
* // calling another registry selector just like any other function
|
|
22
25
|
* const postType = getCurrentPostType( state );
|
|
23
26
|
* const postId = getCurrentPostId( state );
|
|
24
|
-
* return select(
|
|
27
|
+
* return select( coreStore ).getEntityRecordEdits( 'postType', postType, postId );
|
|
25
28
|
* } );
|
|
26
29
|
* ```
|
|
27
30
|
*
|