@wordpress/data 10.41.0 → 10.41.1-next.v.202603161435.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
|
@@ -8,10 +8,7 @@ import deprecated from '@wordpress/deprecated';
|
|
|
8
8
|
*/
|
|
9
9
|
import { createSelector } from '../../create-selector';
|
|
10
10
|
import { selectorArgsToStateKey } from './utils';
|
|
11
|
-
|
|
12
|
-
/** @typedef {Record<string, import('./reducer').State>} State */
|
|
13
|
-
/** @typedef {import('./reducer').StateValue} StateValue */
|
|
14
|
-
/** @typedef {import('./reducer').Status} Status */
|
|
11
|
+
import type { State, StateValue } from './reducer';
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* Returns the raw resolution state value for a given selector name,
|
|
@@ -19,13 +16,17 @@ import { selectorArgsToStateKey } from './utils';
|
|
|
19
16
|
* or not resolved for the given set of arguments, otherwise true or false for
|
|
20
17
|
* resolution started and completed respectively.
|
|
21
18
|
*
|
|
22
|
-
* @param
|
|
23
|
-
* @param
|
|
24
|
-
* @param
|
|
19
|
+
* @param state Data state.
|
|
20
|
+
* @param selectorName Selector name.
|
|
21
|
+
* @param args Arguments passed to selector.
|
|
25
22
|
*
|
|
26
|
-
* @return
|
|
23
|
+
* @return isResolving value.
|
|
27
24
|
*/
|
|
28
|
-
export function getResolutionState(
|
|
25
|
+
export function getResolutionState(
|
|
26
|
+
state: Record< string, State >,
|
|
27
|
+
selectorName: string,
|
|
28
|
+
args?: unknown[] | null
|
|
29
|
+
): StateValue | undefined {
|
|
29
30
|
const map = state[ selectorName ];
|
|
30
31
|
if ( ! map ) {
|
|
31
32
|
return;
|
|
@@ -46,13 +47,17 @@ export function getResolutionState( state, selectorName, args ) {
|
|
|
46
47
|
*
|
|
47
48
|
* @deprecated
|
|
48
49
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
51
|
-
* @param
|
|
50
|
+
* @param state Data state.
|
|
51
|
+
* @param selectorName Selector name.
|
|
52
|
+
* @param args Arguments passed to selector.
|
|
52
53
|
*
|
|
53
|
-
* @return
|
|
54
|
+
* @return isResolving value.
|
|
54
55
|
*/
|
|
55
|
-
export function getIsResolving(
|
|
56
|
+
export function getIsResolving(
|
|
57
|
+
state: Record< string, State >,
|
|
58
|
+
selectorName: string,
|
|
59
|
+
args?: unknown[] | null
|
|
60
|
+
): boolean | undefined {
|
|
56
61
|
deprecated( 'wp.data.select( store ).getIsResolving', {
|
|
57
62
|
since: '6.6',
|
|
58
63
|
version: '6.8',
|
|
@@ -67,13 +72,17 @@ export function getIsResolving( state, selectorName, args ) {
|
|
|
67
72
|
* Returns true if resolution has already been triggered for a given
|
|
68
73
|
* selector name, and arguments set.
|
|
69
74
|
*
|
|
70
|
-
* @param
|
|
71
|
-
* @param
|
|
72
|
-
* @param
|
|
75
|
+
* @param state Data state.
|
|
76
|
+
* @param selectorName Selector name.
|
|
77
|
+
* @param args Arguments passed to selector.
|
|
73
78
|
*
|
|
74
|
-
* @return
|
|
79
|
+
* @return Whether resolution has been triggered.
|
|
75
80
|
*/
|
|
76
|
-
export function hasStartedResolution(
|
|
81
|
+
export function hasStartedResolution(
|
|
82
|
+
state: Record< string, State >,
|
|
83
|
+
selectorName: string,
|
|
84
|
+
args?: unknown[] | null
|
|
85
|
+
): boolean {
|
|
77
86
|
return getResolutionState( state, selectorName, args ) !== undefined;
|
|
78
87
|
}
|
|
79
88
|
|
|
@@ -81,13 +90,17 @@ export function hasStartedResolution( state, selectorName, args ) {
|
|
|
81
90
|
* Returns true if resolution has completed for a given selector
|
|
82
91
|
* name, and arguments set.
|
|
83
92
|
*
|
|
84
|
-
* @param
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
93
|
+
* @param state Data state.
|
|
94
|
+
* @param selectorName Selector name.
|
|
95
|
+
* @param args Arguments passed to selector.
|
|
87
96
|
*
|
|
88
|
-
* @return
|
|
97
|
+
* @return Whether resolution has completed.
|
|
89
98
|
*/
|
|
90
|
-
export function hasFinishedResolution(
|
|
99
|
+
export function hasFinishedResolution(
|
|
100
|
+
state: Record< string, State >,
|
|
101
|
+
selectorName: string,
|
|
102
|
+
args?: unknown[] | null
|
|
103
|
+
): boolean {
|
|
91
104
|
const status = getResolutionState( state, selectorName, args )?.status;
|
|
92
105
|
return status === 'finished' || status === 'error';
|
|
93
106
|
}
|
|
@@ -96,13 +109,17 @@ export function hasFinishedResolution( state, selectorName, args ) {
|
|
|
96
109
|
* Returns true if resolution has failed for a given selector
|
|
97
110
|
* name, and arguments set.
|
|
98
111
|
*
|
|
99
|
-
* @param
|
|
100
|
-
* @param
|
|
101
|
-
* @param
|
|
112
|
+
* @param state Data state.
|
|
113
|
+
* @param selectorName Selector name.
|
|
114
|
+
* @param args Arguments passed to selector.
|
|
102
115
|
*
|
|
103
|
-
* @return
|
|
116
|
+
* @return Has resolution failed
|
|
104
117
|
*/
|
|
105
|
-
export function hasResolutionFailed(
|
|
118
|
+
export function hasResolutionFailed(
|
|
119
|
+
state: Record< string, State >,
|
|
120
|
+
selectorName: string,
|
|
121
|
+
args?: unknown[] | null
|
|
122
|
+
): boolean {
|
|
106
123
|
return getResolutionState( state, selectorName, args )?.status === 'error';
|
|
107
124
|
}
|
|
108
125
|
|
|
@@ -111,13 +128,17 @@ export function hasResolutionFailed( state, selectorName, args ) {
|
|
|
111
128
|
* Note it may be of an Error type, but may also be null, undefined, or anything else
|
|
112
129
|
* that can be `throw`-n.
|
|
113
130
|
*
|
|
114
|
-
* @param
|
|
115
|
-
* @param
|
|
116
|
-
* @param
|
|
131
|
+
* @param state Data state.
|
|
132
|
+
* @param selectorName Selector name.
|
|
133
|
+
* @param args Arguments passed to selector.
|
|
117
134
|
*
|
|
118
|
-
* @return
|
|
135
|
+
* @return Last resolution error
|
|
119
136
|
*/
|
|
120
|
-
export function getResolutionError(
|
|
137
|
+
export function getResolutionError(
|
|
138
|
+
state: Record< string, State >,
|
|
139
|
+
selectorName: string,
|
|
140
|
+
args?: unknown[] | null
|
|
141
|
+
): Error | unknown {
|
|
121
142
|
const resolutionState = getResolutionState( state, selectorName, args );
|
|
122
143
|
return resolutionState?.status === 'error' ? resolutionState.error : null;
|
|
123
144
|
}
|
|
@@ -126,13 +147,17 @@ export function getResolutionError( state, selectorName, args ) {
|
|
|
126
147
|
* Returns true if resolution has been triggered but has not yet completed for
|
|
127
148
|
* a given selector name, and arguments set.
|
|
128
149
|
*
|
|
129
|
-
* @param
|
|
130
|
-
* @param
|
|
131
|
-
* @param
|
|
150
|
+
* @param state Data state.
|
|
151
|
+
* @param selectorName Selector name.
|
|
152
|
+
* @param args Arguments passed to selector.
|
|
132
153
|
*
|
|
133
|
-
* @return
|
|
154
|
+
* @return Whether resolution is in progress.
|
|
134
155
|
*/
|
|
135
|
-
export function isResolving(
|
|
156
|
+
export function isResolving(
|
|
157
|
+
state: Record< string, State >,
|
|
158
|
+
selectorName: string,
|
|
159
|
+
args?: unknown[] | null
|
|
160
|
+
): boolean {
|
|
136
161
|
return (
|
|
137
162
|
getResolutionState( state, selectorName, args )?.status === 'resolving'
|
|
138
163
|
);
|
|
@@ -141,22 +166,26 @@ export function isResolving( state, selectorName, args ) {
|
|
|
141
166
|
/**
|
|
142
167
|
* Returns the list of the cached resolvers.
|
|
143
168
|
*
|
|
144
|
-
* @param
|
|
169
|
+
* @param state Data state.
|
|
145
170
|
*
|
|
146
|
-
* @return
|
|
171
|
+
* @return Resolvers mapped by args and selectorName.
|
|
147
172
|
*/
|
|
148
|
-
export function getCachedResolvers(
|
|
173
|
+
export function getCachedResolvers(
|
|
174
|
+
state: Record< string, State >
|
|
175
|
+
): Record< string, State > {
|
|
149
176
|
return state;
|
|
150
177
|
}
|
|
151
178
|
|
|
152
179
|
/**
|
|
153
180
|
* Whether the store has any currently resolving selectors.
|
|
154
181
|
*
|
|
155
|
-
* @param
|
|
182
|
+
* @param state Data state.
|
|
156
183
|
*
|
|
157
|
-
* @return
|
|
184
|
+
* @return True if one or more selectors are resolving, false otherwise.
|
|
158
185
|
*/
|
|
159
|
-
export function hasResolvingSelectors(
|
|
186
|
+
export function hasResolvingSelectors(
|
|
187
|
+
state: Record< string, State >
|
|
188
|
+
): boolean {
|
|
160
189
|
return Object.values( state ).some( ( selectorState ) =>
|
|
161
190
|
/**
|
|
162
191
|
* This uses the internal `_map` property of `EquivalentKeyMap` for
|
|
@@ -165,8 +194,8 @@ export function hasResolvingSelectors( state ) {
|
|
|
165
194
|
*
|
|
166
195
|
* @see https://github.com/aduth/equivalent-key-map
|
|
167
196
|
*/
|
|
168
|
-
Array.from( selectorState._map.values() ).some(
|
|
169
|
-
( resolution ) => resolution[ 1 ]?.status === 'resolving'
|
|
197
|
+
Array.from( ( selectorState as any )._map.values() ).some(
|
|
198
|
+
( resolution: any ) => resolution[ 1 ]?.status === 'resolving'
|
|
170
199
|
)
|
|
171
200
|
);
|
|
172
201
|
}
|
|
@@ -174,13 +203,13 @@ export function hasResolvingSelectors( state ) {
|
|
|
174
203
|
/**
|
|
175
204
|
* Retrieves the total number of selectors, grouped per status.
|
|
176
205
|
*
|
|
177
|
-
* @param
|
|
206
|
+
* @param state Data state.
|
|
178
207
|
*
|
|
179
|
-
* @return
|
|
208
|
+
* @return Object, containing selector totals by status.
|
|
180
209
|
*/
|
|
181
210
|
export const countSelectorsByStatus = createSelector(
|
|
182
|
-
( state ) => {
|
|
183
|
-
const selectorsByStatus = {};
|
|
211
|
+
( state: Record< string, State > ): Record< string, number > => {
|
|
212
|
+
const selectorsByStatus: Record< string, number > = {};
|
|
184
213
|
|
|
185
214
|
Object.values( state ).forEach( ( selectorState ) =>
|
|
186
215
|
/**
|
|
@@ -190,8 +219,8 @@ export const countSelectorsByStatus = createSelector(
|
|
|
190
219
|
*
|
|
191
220
|
* @see https://github.com/aduth/equivalent-key-map
|
|
192
221
|
*/
|
|
193
|
-
Array.from( selectorState._map.values() ).forEach(
|
|
194
|
-
( resolution ) => {
|
|
222
|
+
Array.from( ( selectorState as any )._map.values() ).forEach(
|
|
223
|
+
( resolution: any ) => {
|
|
195
224
|
const currentStatus = resolution[ 1 ]?.status ?? 'error';
|
|
196
225
|
if ( ! selectorsByStatus[ currentStatus ] ) {
|
|
197
226
|
selectorsByStatus[ currentStatus ] = 0;
|
|
@@ -203,5 +232,5 @@ export const countSelectorsByStatus = createSelector(
|
|
|
203
232
|
|
|
204
233
|
return selectorsByStatus;
|
|
205
234
|
},
|
|
206
|
-
( state ) => [ state ]
|
|
235
|
+
( state: Record< string, State > ) => [ state ]
|
|
207
236
|
);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { StoreDescriptor, ReduxStoreConfig } from '../../types';
|
|
5
|
+
import type { StateValue as MetadataStateValue } from './reducer';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extracts selector key names from a store descriptor.
|
|
9
|
+
* Falls back to `string` when the store type is unknown.
|
|
10
|
+
*/
|
|
11
|
+
export type SelectorKeysOf< S > = S extends StoreDescriptor<
|
|
12
|
+
ReduxStoreConfig< any, any, infer Selectors >
|
|
13
|
+
>
|
|
14
|
+
? string & keyof Selectors
|
|
15
|
+
: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Metadata selectors injected into every Redux store.
|
|
19
|
+
*
|
|
20
|
+
* These are resolution-tracking selectors that the data module
|
|
21
|
+
* automatically adds to every registered store. The `S` parameter
|
|
22
|
+
* provides type-safe selector names via `SelectorKeysOf`.
|
|
23
|
+
*/
|
|
24
|
+
export type MetadataSelectors< S = unknown > = {
|
|
25
|
+
getResolutionState: (
|
|
26
|
+
selectorName: SelectorKeysOf< S >,
|
|
27
|
+
args?: unknown[] | null
|
|
28
|
+
) => MetadataStateValue | undefined;
|
|
29
|
+
getIsResolving: (
|
|
30
|
+
selectorName: SelectorKeysOf< S >,
|
|
31
|
+
args?: unknown[] | null
|
|
32
|
+
) => boolean | undefined;
|
|
33
|
+
hasStartedResolution: (
|
|
34
|
+
selectorName: SelectorKeysOf< S >,
|
|
35
|
+
args?: unknown[] | null
|
|
36
|
+
) => boolean;
|
|
37
|
+
hasFinishedResolution: (
|
|
38
|
+
selectorName: SelectorKeysOf< S >,
|
|
39
|
+
args?: unknown[] | null
|
|
40
|
+
) => boolean;
|
|
41
|
+
hasResolutionFailed: (
|
|
42
|
+
selectorName: SelectorKeysOf< S >,
|
|
43
|
+
args?: unknown[] | null
|
|
44
|
+
) => boolean;
|
|
45
|
+
getResolutionError: (
|
|
46
|
+
selectorName: SelectorKeysOf< S >,
|
|
47
|
+
args?: unknown[] | null
|
|
48
|
+
) => Error | unknown;
|
|
49
|
+
isResolving: (
|
|
50
|
+
selectorName: SelectorKeysOf< S >,
|
|
51
|
+
args?: unknown[] | null
|
|
52
|
+
) => boolean;
|
|
53
|
+
getCachedResolvers: () => Record< string, unknown >;
|
|
54
|
+
hasResolvingSelectors: () => boolean;
|
|
55
|
+
countSelectorsByStatus: () => Record< string, number >;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Metadata actions injected into every Redux store.
|
|
60
|
+
*
|
|
61
|
+
* These are resolution-tracking actions that the data module
|
|
62
|
+
* automatically adds to every registered store. The `S` parameter
|
|
63
|
+
* provides type-safe selector names via `SelectorKeysOf`.
|
|
64
|
+
*/
|
|
65
|
+
export type MetadataActions< S = unknown > = {
|
|
66
|
+
startResolution: (
|
|
67
|
+
selectorName: SelectorKeysOf< S >,
|
|
68
|
+
args: unknown[]
|
|
69
|
+
) => Promise< void >;
|
|
70
|
+
finishResolution: (
|
|
71
|
+
selectorName: SelectorKeysOf< S >,
|
|
72
|
+
args: unknown[]
|
|
73
|
+
) => Promise< void >;
|
|
74
|
+
failResolution: (
|
|
75
|
+
selectorName: SelectorKeysOf< S >,
|
|
76
|
+
args: unknown[],
|
|
77
|
+
error: Error | unknown
|
|
78
|
+
) => Promise< void >;
|
|
79
|
+
startResolutions: (
|
|
80
|
+
selectorName: SelectorKeysOf< S >,
|
|
81
|
+
args: unknown[][]
|
|
82
|
+
) => Promise< void >;
|
|
83
|
+
finishResolutions: (
|
|
84
|
+
selectorName: SelectorKeysOf< S >,
|
|
85
|
+
args: unknown[][]
|
|
86
|
+
) => Promise< void >;
|
|
87
|
+
failResolutions: (
|
|
88
|
+
selectorName: SelectorKeysOf< S >,
|
|
89
|
+
args: unknown[],
|
|
90
|
+
errors: ( Error | unknown )[]
|
|
91
|
+
) => Promise< void >;
|
|
92
|
+
invalidateResolution: (
|
|
93
|
+
selectorName: SelectorKeysOf< S >,
|
|
94
|
+
args: unknown[]
|
|
95
|
+
) => Promise< void >;
|
|
96
|
+
invalidateResolutionForStore: () => Promise< void >;
|
|
97
|
+
invalidateResolutionForStoreSelector: (
|
|
98
|
+
selectorName: SelectorKeysOf< S >
|
|
99
|
+
) => Promise< void >;
|
|
100
|
+
};
|