@wordpress/data 10.41.0 → 10.41.1-next.v.202603102151.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/README.md +20 -28
- package/build/components/async-mode-provider/context.cjs +1 -1
- package/build/components/async-mode-provider/context.cjs.map +3 -3
- package/build/components/async-mode-provider/index.cjs +1 -1
- package/build/components/async-mode-provider/index.cjs.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs.map +3 -3
- package/build/components/registry-provider/context.cjs +1 -1
- package/build/components/registry-provider/context.cjs.map +1 -1
- package/build/components/registry-provider/index.cjs +1 -1
- package/build/components/registry-provider/index.cjs.map +1 -1
- package/build/components/registry-provider/use-registry.cjs +1 -1
- package/build/components/registry-provider/use-registry.cjs.map +3 -3
- package/build/components/use-dispatch/index.cjs +1 -1
- package/build/components/use-dispatch/index.cjs.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs.map +3 -3
- package/build/components/use-dispatch/use-dispatch.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch.cjs.map +3 -3
- package/build/components/use-select/index.cjs +2 -2
- package/build/components/use-select/index.cjs.map +3 -3
- package/build/components/with-dispatch/index.cjs +1 -1
- package/build/components/with-dispatch/index.cjs.map +3 -3
- package/build/components/with-registry/index.cjs +1 -1
- package/build/components/with-registry/index.cjs.map +3 -3
- package/build/components/with-select/index.cjs +1 -1
- package/build/components/with-select/index.cjs.map +3 -3
- package/build/controls.cjs +7 -6
- package/build/controls.cjs.map +3 -3
- package/build/default-registry.cjs +3 -2
- package/build/default-registry.cjs.map +3 -3
- package/build/dispatch.cjs +3 -1
- package/build/dispatch.cjs.map +2 -2
- package/build/factory.cjs.map +2 -2
- package/build/index.cjs +9 -8
- package/build/index.cjs.map +3 -3
- package/build/plugins/index.cjs +1 -1
- package/build/plugins/index.cjs.map +1 -1
- package/build/plugins/persistence/index.cjs +13 -8
- package/build/plugins/persistence/index.cjs.map +3 -3
- package/build/plugins/persistence/storage/default.cjs +1 -1
- package/build/plugins/persistence/storage/default.cjs.map +3 -3
- package/build/plugins/persistence/storage/object.cjs +1 -1
- package/build/plugins/persistence/storage/object.cjs.map +3 -3
- package/build/promise-middleware.cjs +2 -1
- package/build/promise-middleware.cjs.map +3 -3
- package/build/redux-store/index.cjs +32 -16
- package/build/redux-store/index.cjs.map +3 -3
- package/build/redux-store/metadata/selectors.cjs +1 -1
- package/build/redux-store/metadata/selectors.cjs.map +3 -3
- package/build/redux-store/metadata/types.cjs +19 -0
- package/build/redux-store/metadata/types.cjs.map +7 -0
- package/build/registry.cjs +11 -7
- package/build/registry.cjs.map +3 -3
- package/build/resolvers-cache-middleware.cjs +6 -3
- package/build/resolvers-cache-middleware.cjs.map +3 -3
- package/build/select.cjs +3 -1
- package/build/select.cjs.map +2 -2
- package/build/store/index.cjs +1 -1
- package/build/store/index.cjs.map +3 -3
- package/build/types.cjs.map +1 -1
- package/build-module/components/async-mode-provider/context.mjs +1 -1
- package/build-module/components/async-mode-provider/context.mjs.map +3 -3
- package/build-module/components/async-mode-provider/index.mjs +1 -1
- package/build-module/components/async-mode-provider/index.mjs.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs.map +3 -3
- package/build-module/components/registry-provider/context.mjs +1 -1
- package/build-module/components/registry-provider/context.mjs.map +1 -1
- package/build-module/components/registry-provider/index.mjs +1 -1
- package/build-module/components/registry-provider/index.mjs.map +1 -1
- package/build-module/components/registry-provider/use-registry.mjs +1 -1
- package/build-module/components/registry-provider/use-registry.mjs.map +3 -3
- package/build-module/components/use-dispatch/index.mjs +1 -1
- package/build-module/components/use-dispatch/index.mjs.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs.map +3 -3
- package/build-module/components/use-dispatch/use-dispatch.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch.mjs.map +3 -3
- package/build-module/components/use-select/index.mjs +2 -2
- package/build-module/components/use-select/index.mjs.map +3 -3
- package/build-module/components/with-dispatch/index.mjs +1 -1
- package/build-module/components/with-dispatch/index.mjs.map +3 -3
- package/build-module/components/with-registry/index.mjs +1 -1
- package/build-module/components/with-registry/index.mjs.map +3 -3
- package/build-module/components/with-select/index.mjs +1 -1
- package/build-module/components/with-select/index.mjs.map +3 -3
- package/build-module/controls.mjs +7 -6
- package/build-module/controls.mjs.map +3 -3
- package/build-module/default-registry.mjs +3 -2
- package/build-module/default-registry.mjs.map +3 -3
- package/build-module/dispatch.mjs +3 -1
- package/build-module/dispatch.mjs.map +2 -2
- package/build-module/factory.mjs.map +2 -2
- package/build-module/index.mjs +4 -3
- package/build-module/index.mjs.map +2 -2
- package/build-module/plugins/index.mjs +1 -1
- package/build-module/plugins/index.mjs.map +1 -1
- package/build-module/plugins/persistence/index.mjs +13 -8
- package/build-module/plugins/persistence/index.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/default.mjs +1 -1
- package/build-module/plugins/persistence/storage/default.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/object.mjs +1 -1
- package/build-module/plugins/persistence/storage/object.mjs.map +3 -3
- package/build-module/promise-middleware.mjs +2 -1
- package/build-module/promise-middleware.mjs.map +3 -3
- package/build-module/redux-store/index.mjs +32 -16
- package/build-module/redux-store/index.mjs.map +3 -3
- package/build-module/redux-store/metadata/selectors.mjs +1 -1
- package/build-module/redux-store/metadata/selectors.mjs.map +3 -3
- package/build-module/redux-store/metadata/types.mjs +1 -0
- package/build-module/redux-store/metadata/types.mjs.map +7 -0
- package/build-module/registry.mjs +11 -7
- package/build-module/registry.mjs.map +3 -3
- package/build-module/resolvers-cache-middleware.mjs +6 -3
- package/build-module/resolvers-cache-middleware.mjs.map +3 -3
- package/build-module/select.mjs +3 -1
- package/build-module/select.mjs.map +2 -2
- package/build-module/store/index.mjs +1 -1
- package/build-module/store/index.mjs.map +3 -3
- package/build-types/components/async-mode-provider/context.d.ts +37 -3
- package/build-types/components/async-mode-provider/context.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/index.d.ts +2 -2
- package/build-types/components/async-mode-provider/index.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -1
- package/build-types/components/registry-provider/context.d.ts +10 -3
- package/build-types/components/registry-provider/context.d.ts.map +1 -1
- package/build-types/components/registry-provider/index.d.ts +2 -2
- package/build-types/components/registry-provider/index.d.ts.map +1 -1
- package/build-types/components/registry-provider/use-registry.d.ts +3 -2
- package/build-types/components/registry-provider/use-registry.d.ts.map +1 -1
- package/build-types/components/use-dispatch/index.d.ts +2 -2
- package/build-types/components/use-dispatch/index.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +11 -9
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch.d.ts +10 -19
- package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -1
- package/build-types/components/use-select/index.d.ts +24 -28
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/components/with-dispatch/index.d.ts +10 -11
- package/build-types/components/with-dispatch/index.d.ts.map +1 -1
- package/build-types/components/with-registry/index.d.ts +2 -6
- package/build-types/components/with-registry/index.d.ts.map +1 -1
- package/build-types/components/with-select/index.d.ts +7 -8
- package/build-types/components/with-select/index.d.ts.map +1 -1
- package/build-types/controls.d.ts +57 -44
- package/build-types/controls.d.ts.map +1 -1
- package/build-types/default-registry.d.ts +2 -2
- package/build-types/default-registry.d.ts.map +1 -1
- package/build-types/dispatch.d.ts +4 -0
- package/build-types/dispatch.d.ts.map +1 -1
- package/build-types/factory.d.ts +2 -1
- package/build-types/factory.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/plugins/index.d.ts +1 -1
- package/build-types/plugins/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/index.d.ts +38 -27
- package/build-types/plugins/persistence/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/default.d.ts +7 -1
- package/build-types/plugins/persistence/storage/default.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/object.d.ts +4 -5
- package/build-types/plugins/persistence/storage/object.d.ts.map +1 -1
- package/build-types/promise-middleware.d.ts +6 -4
- package/build-types/promise-middleware.d.ts.map +1 -1
- package/build-types/redux-store/index.d.ts +12 -15
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/build-types/redux-store/metadata/selectors.d.ts +45 -50
- package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
- package/build-types/redux-store/metadata/types.d.ts +48 -0
- package/build-types/redux-store/metadata/types.d.ts.map +1 -0
- package/build-types/registry.d.ts +5 -49
- package/build-types/registry.d.ts.map +1 -1
- package/build-types/resolvers-cache-middleware.d.ts +13 -7
- package/build-types/resolvers-cache-middleware.d.ts.map +1 -1
- package/build-types/select.d.ts +3 -0
- package/build-types/select.d.ts.map +1 -1
- package/build-types/store/index.d.ts +5 -12
- package/build-types/store/index.d.ts.map +1 -1
- package/build-types/types.d.ts +201 -10
- package/build-types/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/components/async-mode-provider/{context.js → context.ts} +0 -1
- package/src/components/async-mode-provider/{use-async-mode.js → use-async-mode.ts} +1 -1
- package/src/components/registry-provider/{use-registry.js → use-registry.ts} +3 -2
- package/src/components/use-dispatch/{use-dispatch-with-map.js → use-dispatch-with-map.ts} +18 -9
- package/src/components/use-dispatch/{use-dispatch.js → use-dispatch.ts} +25 -20
- package/src/components/use-select/{index.js → index.ts} +84 -70
- package/src/components/with-dispatch/{index.js → index.tsx} +20 -13
- package/src/components/with-registry/{index.js → index.tsx} +1 -5
- package/src/components/with-select/{index.js → index.tsx} +17 -10
- package/src/{controls.js → controls.ts} +53 -26
- package/src/{default-registry.js → default-registry.ts} +3 -1
- package/src/dispatch.ts +7 -1
- package/src/factory.ts +4 -3
- package/src/index.ts +4 -8
- package/src/plugins/persistence/{index.js → index.ts} +93 -54
- package/src/plugins/persistence/storage/{default.js → default.ts} +3 -2
- package/src/plugins/persistence/storage/object.ts +25 -0
- package/src/{promise-middleware.js → promise-middleware.ts} +3 -3
- package/src/redux-store/{index.js → index.ts} +218 -131
- package/src/redux-store/metadata/{selectors.js → selectors.ts} +83 -54
- package/src/redux-store/metadata/types.ts +100 -0
- package/src/{registry.js → registry.ts} +98 -88
- package/src/{resolvers-cache-middleware.js → resolvers-cache-middleware.ts} +22 -7
- package/src/select.ts +6 -1
- package/src/store/{index.js → index.ts} +13 -8
- package/src/types.ts +263 -24
- package/src/plugins/persistence/storage/object.js +0 -23
- /package/src/components/async-mode-provider/{index.js → index.ts} +0 -0
- /package/src/components/registry-provider/{context.js → context.ts} +0 -0
- /package/src/components/registry-provider/{index.js → index.ts} +0 -0
- /package/src/components/use-dispatch/{index.js → index.ts} +0 -0
- /package/src/plugins/{index.js → index.ts} +0 -0
package/src/types.ts
CHANGED
|
@@ -1,8 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
|
-
import type {
|
|
4
|
+
|
|
5
|
+
import type {
|
|
6
|
+
// eslint-disable-next-line no-restricted-imports
|
|
7
|
+
combineReducers as reduxCombineReducers,
|
|
8
|
+
Store as ReduxStore,
|
|
9
|
+
} from 'redux';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import type { DataEmitter } from './utils/emitter';
|
|
15
|
+
import type {
|
|
16
|
+
MetadataSelectors,
|
|
17
|
+
MetadataActions,
|
|
18
|
+
} from './redux-store/metadata/types';
|
|
6
19
|
|
|
7
20
|
type MapOf< T > = { [ name: string ]: T };
|
|
8
21
|
|
|
@@ -30,11 +43,7 @@ export interface StoreDescriptor< Config extends AnyConfig = AnyConfig > {
|
|
|
30
43
|
instantiate: ( registry: DataRegistry ) => StoreInstance< Config >;
|
|
31
44
|
}
|
|
32
45
|
|
|
33
|
-
export interface ReduxStoreConfig<
|
|
34
|
-
State,
|
|
35
|
-
ActionCreators extends MapOf< ActionCreator >,
|
|
36
|
-
Selectors,
|
|
37
|
-
> {
|
|
46
|
+
export interface ReduxStoreConfig< State, ActionCreators, Selectors > {
|
|
38
47
|
initialState?: State;
|
|
39
48
|
reducer: ( state: any, action: any ) => any;
|
|
40
49
|
actions?: ActionCreators;
|
|
@@ -54,7 +63,7 @@ export type UseSelectReturn< F extends MapSelect | StoreDescriptor< any > > =
|
|
|
54
63
|
// Return type for the useDispatch() hook.
|
|
55
64
|
export type UseDispatchReturn< StoreNameOrDescriptor > =
|
|
56
65
|
StoreNameOrDescriptor extends StoreDescriptor< any >
|
|
57
|
-
? ActionCreatorsOf<
|
|
66
|
+
? ActionCreatorsOf< StoreNameOrDescriptor >
|
|
58
67
|
: StoreNameOrDescriptor extends undefined
|
|
59
68
|
? DispatchFunction
|
|
60
69
|
: any;
|
|
@@ -65,7 +74,7 @@ export type DispatchFunction = < StoreNameOrDescriptor >(
|
|
|
65
74
|
|
|
66
75
|
export type DispatchReturn< StoreNameOrDescriptor > =
|
|
67
76
|
StoreNameOrDescriptor extends StoreDescriptor< any >
|
|
68
|
-
? ActionCreatorsOf<
|
|
77
|
+
? ActionCreatorsOf< StoreNameOrDescriptor >
|
|
69
78
|
: unknown;
|
|
70
79
|
|
|
71
80
|
export type MapSelect = (
|
|
@@ -84,7 +93,9 @@ export type ListenerFunction = () => void;
|
|
|
84
93
|
export type CurriedSelectorsOf< S > = S extends StoreDescriptor<
|
|
85
94
|
ReduxStoreConfig< any, any, infer Selectors >
|
|
86
95
|
>
|
|
87
|
-
? {
|
|
96
|
+
? {
|
|
97
|
+
[ key in keyof Selectors ]: CurriedState< Selectors[ key ] >;
|
|
98
|
+
} & MetadataSelectors< S >
|
|
88
99
|
: never;
|
|
89
100
|
|
|
90
101
|
/**
|
|
@@ -193,39 +204,244 @@ export interface SelectorWithCustomCurrySignature {
|
|
|
193
204
|
PromiseCurriedSignature?: Function;
|
|
194
205
|
}
|
|
195
206
|
|
|
207
|
+
/**
|
|
208
|
+
* A store name or store descriptor, used throughout the API.
|
|
209
|
+
*/
|
|
210
|
+
export type StoreNameOrDescriptor = string | StoreDescriptor;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* An isolated orchestrator of store registrations.
|
|
214
|
+
*
|
|
215
|
+
* Returned by `createRegistry`. Provides methods to register stores,
|
|
216
|
+
* select data, dispatch actions, and subscribe to changes.
|
|
217
|
+
*/
|
|
196
218
|
export interface DataRegistry {
|
|
219
|
+
batch: ( callback: () => void ) => void;
|
|
220
|
+
stores: Record< string, InternalStoreInstance >;
|
|
221
|
+
namespaces: Record< string, InternalStoreInstance >;
|
|
222
|
+
subscribe: (
|
|
223
|
+
listener: ListenerFunction,
|
|
224
|
+
storeNameOrDescriptor?: StoreNameOrDescriptor
|
|
225
|
+
) => () => void;
|
|
226
|
+
select: {
|
|
227
|
+
< S extends StoreDescriptor< any > >(
|
|
228
|
+
store: S
|
|
229
|
+
): CurriedSelectorsOf< S >;
|
|
230
|
+
(
|
|
231
|
+
store: StoreNameOrDescriptor
|
|
232
|
+
): Record< string, ( ...args: any[] ) => any >;
|
|
233
|
+
};
|
|
234
|
+
resolveSelect: {
|
|
235
|
+
< S extends StoreDescriptor< any > >(
|
|
236
|
+
store: S
|
|
237
|
+
): CurriedSelectorsResolveOf< S >;
|
|
238
|
+
(
|
|
239
|
+
store: StoreNameOrDescriptor
|
|
240
|
+
): Record< string, ( ...args: any[] ) => Promise< any > >;
|
|
241
|
+
};
|
|
242
|
+
suspendSelect: {
|
|
243
|
+
< S extends StoreDescriptor< any > >(
|
|
244
|
+
store: S
|
|
245
|
+
): CurriedSelectorsOf< S >;
|
|
246
|
+
(
|
|
247
|
+
store: StoreNameOrDescriptor
|
|
248
|
+
): Record< string, ( ...args: any[] ) => any >;
|
|
249
|
+
};
|
|
250
|
+
dispatch: {
|
|
251
|
+
< S extends StoreDescriptor< any > >( store: S ): ActionCreatorsOf< S >;
|
|
252
|
+
(
|
|
253
|
+
store: StoreNameOrDescriptor
|
|
254
|
+
): Record< string, ( ...args: any[] ) => any >;
|
|
255
|
+
};
|
|
256
|
+
use: (
|
|
257
|
+
plugin: DataPlugin,
|
|
258
|
+
options?: Record< string, unknown >
|
|
259
|
+
) => DataRegistry;
|
|
197
260
|
register: ( store: StoreDescriptor< any > ) => void;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
261
|
+
registerGenericStore: (
|
|
262
|
+
name: string,
|
|
263
|
+
store: StoreInstance< AnyConfig >
|
|
264
|
+
) => void;
|
|
265
|
+
registerStore: (
|
|
266
|
+
storeName: string,
|
|
267
|
+
options: ReduxStoreConfig< any, any, any >
|
|
268
|
+
) => ReduxStore;
|
|
269
|
+
__unstableMarkListeningStores: < T >(
|
|
270
|
+
callback: () => T,
|
|
271
|
+
ref: { current: string[] | null }
|
|
272
|
+
) => T;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* The plugin function signature.
|
|
277
|
+
*/
|
|
278
|
+
export type DataPlugin = (
|
|
279
|
+
registry: DataRegistry,
|
|
280
|
+
options?: Record< string, unknown >
|
|
281
|
+
) => Partial< DataRegistry >;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Status of a selector resolution.
|
|
285
|
+
*/
|
|
286
|
+
export type ResolutionStatus = 'resolving' | 'finished' | 'error';
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* State value for a single resolution.
|
|
290
|
+
*/
|
|
291
|
+
export type ResolutionState =
|
|
292
|
+
| { status: 'resolving' }
|
|
293
|
+
| { status: 'finished' }
|
|
294
|
+
| { status: 'error'; error: Error | unknown };
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* A normalized resolver with a `fulfill` method and optional `isFulfilled`.
|
|
298
|
+
*/
|
|
299
|
+
export interface NormalizedResolver {
|
|
300
|
+
/**
|
|
301
|
+
* The function to call to fulfill the resolver.
|
|
302
|
+
*/
|
|
303
|
+
fulfill: ( ...args: any[] ) => any;
|
|
304
|
+
/**
|
|
305
|
+
* Optional function to check if the resolver is already fulfilled.
|
|
306
|
+
*/
|
|
307
|
+
isFulfilled?: ( state: any, ...args: any[] ) => boolean;
|
|
308
|
+
/**
|
|
309
|
+
* Optional function to check if the resolver should be invalidated.
|
|
310
|
+
*/
|
|
311
|
+
shouldInvalidate?: ( action: any, ...args: any[] ) => boolean;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* A bound selector with optional resolver metadata.
|
|
316
|
+
*/
|
|
317
|
+
export interface BoundSelector {
|
|
318
|
+
( ...args: any[] ): any;
|
|
319
|
+
/**
|
|
320
|
+
* Whether this selector has a resolver attached.
|
|
321
|
+
*/
|
|
322
|
+
hasResolver: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Optional function to normalize the arguments.
|
|
325
|
+
*/
|
|
326
|
+
__unstableNormalizeArgs?: ( args: any[] ) => any[];
|
|
327
|
+
/**
|
|
328
|
+
* Whether this selector is a registry selector.
|
|
329
|
+
*/
|
|
330
|
+
isRegistrySelector?: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* The registry instance this selector is bound to.
|
|
333
|
+
*/
|
|
334
|
+
registry?: DataRegistry;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* The shape of a store instance as seen internally by the registry.
|
|
339
|
+
* Extends the public StoreInstance with additional internal properties.
|
|
340
|
+
*/
|
|
341
|
+
export interface InternalStoreInstance< Config extends AnyConfig = AnyConfig >
|
|
342
|
+
extends StoreInstance< Config > {
|
|
343
|
+
/**
|
|
344
|
+
* The Redux store instance (only for Redux-based stores).
|
|
345
|
+
*/
|
|
346
|
+
store?: ReduxStore;
|
|
347
|
+
/**
|
|
348
|
+
* The internal emitter for pause/resume batching.
|
|
349
|
+
*/
|
|
350
|
+
emitter: DataEmitter;
|
|
351
|
+
/**
|
|
352
|
+
* The combined reducer.
|
|
353
|
+
*/
|
|
354
|
+
reducer?: ( state: any, action: any ) => any;
|
|
355
|
+
/**
|
|
356
|
+
* Bound actions object.
|
|
357
|
+
*/
|
|
358
|
+
actions?: Record< string, ActionCreator >;
|
|
359
|
+
/**
|
|
360
|
+
* Bound selectors object.
|
|
361
|
+
*/
|
|
362
|
+
selectors?: Record< string, Selector >;
|
|
363
|
+
/**
|
|
364
|
+
* Resolver definitions.
|
|
365
|
+
*/
|
|
366
|
+
resolvers?: Record< string, NormalizedResolver >;
|
|
367
|
+
/**
|
|
368
|
+
* Returns resolve-wrapped selectors.
|
|
369
|
+
*/
|
|
370
|
+
getResolveSelectors?: () => Record<
|
|
371
|
+
string,
|
|
372
|
+
( ...args: any[] ) => Promise< any >
|
|
373
|
+
>;
|
|
374
|
+
/**
|
|
375
|
+
* Returns suspense-wrapped selectors.
|
|
376
|
+
*/
|
|
377
|
+
getSuspendSelectors?: () => Record< string, ( ...args: any[] ) => any >;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Control descriptor for the controls system.
|
|
382
|
+
*/
|
|
383
|
+
export interface ControlDescriptor {
|
|
384
|
+
/**
|
|
385
|
+
* The type of the control action.
|
|
386
|
+
*/
|
|
387
|
+
type: string;
|
|
388
|
+
/**
|
|
389
|
+
* The store key to target.
|
|
390
|
+
*/
|
|
391
|
+
storeKey: string;
|
|
392
|
+
/**
|
|
393
|
+
* The name of the selector (for select/resolveSelect controls).
|
|
394
|
+
*/
|
|
395
|
+
selectorName?: string;
|
|
396
|
+
/**
|
|
397
|
+
* The name of the action (for dispatch controls).
|
|
398
|
+
*/
|
|
399
|
+
actionName?: string;
|
|
400
|
+
/**
|
|
401
|
+
* Arguments for the selector or action.
|
|
402
|
+
*/
|
|
403
|
+
args: any[];
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Storage interface (Web Storage API subset).
|
|
408
|
+
*/
|
|
409
|
+
export interface StorageInterface {
|
|
410
|
+
getItem: ( key: string ) => string | null;
|
|
411
|
+
setItem: ( key: string, value: string ) => void;
|
|
412
|
+
removeItem?: ( key: string ) => void;
|
|
413
|
+
clear?: VoidFunction;
|
|
201
414
|
}
|
|
202
415
|
|
|
203
416
|
// Type Helpers.
|
|
204
417
|
|
|
205
418
|
export type ConfigOf< S > = S extends StoreDescriptor< infer C > ? C : never;
|
|
206
419
|
|
|
207
|
-
export type ActionCreatorsOf<
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
420
|
+
export type ActionCreatorsOf< T > = T extends StoreDescriptor<
|
|
421
|
+
ReduxStoreConfig< any, infer ActionCreators, any >
|
|
422
|
+
>
|
|
423
|
+
? PromisifiedActionCreators< ActionCreators > & MetadataActions< T >
|
|
424
|
+
: T extends ReduxStoreConfig< any, infer ActionCreators, any >
|
|
425
|
+
? PromisifiedActionCreators< ActionCreators >
|
|
426
|
+
: never;
|
|
211
427
|
|
|
212
428
|
// Takes an object containing all action creators for a store and updates the
|
|
213
429
|
// return type of each action creator to account for internal registry details --
|
|
214
430
|
// for example, dispatched actions are wrapped with a Promise.
|
|
215
|
-
export type PromisifiedActionCreators<
|
|
216
|
-
ActionCreators extends
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
ActionCreators[ Action ]
|
|
220
|
-
>;
|
|
431
|
+
export type PromisifiedActionCreators< ActionCreators > = {
|
|
432
|
+
[ Action in keyof ActionCreators ]: ActionCreators[ Action ] extends ActionCreator
|
|
433
|
+
? PromisifyActionCreator< ActionCreators[ Action ] >
|
|
434
|
+
: ActionCreators[ Action ];
|
|
221
435
|
};
|
|
222
436
|
|
|
223
|
-
// Wraps action creator return types with a Promise and handles thunks.
|
|
437
|
+
// Wraps action creator return types with a Promise and handles thunks and generators.
|
|
224
438
|
export type PromisifyActionCreator< Action extends ActionCreator > = (
|
|
225
439
|
...args: Parameters< Action >
|
|
226
440
|
) => Promise<
|
|
227
441
|
ReturnType< Action > extends ( ..._args: any[] ) => any
|
|
228
442
|
? ThunkReturnType< Action >
|
|
443
|
+
: ReturnType< Action > extends Generator< any, infer TReturn, any >
|
|
444
|
+
? TReturn
|
|
229
445
|
: ReturnType< Action >
|
|
230
446
|
>;
|
|
231
447
|
|
|
@@ -245,4 +461,27 @@ type SelectorsOf< Config extends AnyConfig > = Config extends ReduxStoreConfig<
|
|
|
245
461
|
? { [ name in keyof Selectors ]: Function }
|
|
246
462
|
: never;
|
|
247
463
|
|
|
464
|
+
/**
|
|
465
|
+
* The argument object passed to every thunk function. When parameterized with
|
|
466
|
+
* a store descriptor, `dispatch`, `select`, and `resolveSelect` are fully
|
|
467
|
+
* typed against that store's actions and selectors.
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```ts
|
|
471
|
+
* const myAction =
|
|
472
|
+
* ( id: number ) =>
|
|
473
|
+
* async ( { dispatch, select }: ThunkArgs< typeof myStore > ) => {
|
|
474
|
+
* const record = select.getRecord( id );
|
|
475
|
+
* dispatch.setLoading( true );
|
|
476
|
+
* };
|
|
477
|
+
* ```
|
|
478
|
+
*/
|
|
479
|
+
export interface ThunkArgs< S extends StoreDescriptor = StoreDescriptor > {
|
|
480
|
+
dispatch: ActionCreatorsOf< S > &
|
|
481
|
+
( ( action: Record< string, unknown > | Function ) => unknown );
|
|
482
|
+
select: CurriedSelectorsOf< S >;
|
|
483
|
+
resolveSelect: CurriedSelectorsResolveOf< S >;
|
|
484
|
+
registry: DataRegistry;
|
|
485
|
+
}
|
|
486
|
+
|
|
248
487
|
export type combineReducers = typeof reduxCombineReducers;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
let objectStorage;
|
|
2
|
-
|
|
3
|
-
const storage = {
|
|
4
|
-
getItem( key ) {
|
|
5
|
-
if ( ! objectStorage || ! objectStorage[ key ] ) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return objectStorage[ key ];
|
|
10
|
-
},
|
|
11
|
-
setItem( key, value ) {
|
|
12
|
-
if ( ! objectStorage ) {
|
|
13
|
-
storage.clear();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
objectStorage[ key ] = String( value );
|
|
17
|
-
},
|
|
18
|
-
clear() {
|
|
19
|
-
objectStorage = Object.create( null );
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default storage;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|