@wordpress/data 10.32.0 → 10.32.1-next.ff1cebbba.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 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/redux-store/metadata/reducer.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport EquivalentKeyMap from 'equivalent-key-map';\nimport type { Reducer } from 'redux';\n\n/**\n * Internal dependencies\n */\nimport { selectorArgsToStateKey, onSubKey } from './utils';\n\ntype Action =\n\t| ReturnType< typeof import('./actions').startResolution >\n\t| ReturnType< typeof import('./actions').finishResolution >\n\t| ReturnType< typeof import('./actions').failResolution >\n\t| ReturnType< typeof import('./actions').startResolutions >\n\t| ReturnType< typeof import('./actions').finishResolutions >\n\t| ReturnType< typeof import('./actions').failResolutions >\n\t| ReturnType< typeof import('./actions').invalidateResolution >\n\t| ReturnType< typeof import('./actions').invalidateResolutionForStore >\n\t| ReturnType<\n\t\t\ttypeof import('./actions').invalidateResolutionForStoreSelector\n\t >;\n\ntype StateKey = unknown[] | unknown;\nexport type StateValue =\n\t| { status: 'resolving' | 'finished' }\n\t| { status: 'error'; error: Error | unknown };\n\nexport type Status = StateValue[ 'status' ];\nexport type State = EquivalentKeyMap< StateKey, StateValue >;\n\n/**\n * Reducer function returning next state for selector resolution of\n * subkeys, object form:\n *\n * selectorName -> EquivalentKeyMap<Array,boolean>\n */\nconst subKeysIsResolved: Reducer< Record< string, State >, Action > = onSubKey<\n\tState,\n\tAction\n>( 'selectorName' )( ( state = new EquivalentKeyMap(), action: Action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'START_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'resolving',\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FINISH_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'finished',\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FAIL_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.set( selectorArgsToStateKey( action.args ), {\n\t\t\t\tstatus: 'error',\n\t\t\t\terror: action.error,\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'START_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tfor ( const resolutionArgs of action.args ) {\n\t\t\t\tnextState.set( selectorArgsToStateKey( resolutionArgs ), {\n\t\t\t\t\tstatus: 'resolving',\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FINISH_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tfor ( const resolutionArgs of action.args ) {\n\t\t\t\tnextState.set( selectorArgsToStateKey( resolutionArgs ), {\n\t\t\t\t\tstatus: 'finished',\n\t\t\t\t} );\n\t\t\t}\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'FAIL_RESOLUTIONS': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\taction.args.forEach( ( resolutionArgs, idx ) => {\n\t\t\t\tconst resolutionState: StateValue = {\n\t\t\t\t\tstatus: 'error',\n\t\t\t\t\terror: undefined,\n\t\t\t\t};\n\n\t\t\t\tconst error = action.errors[ idx ];\n\t\t\t\tif ( error ) {\n\t\t\t\t\tresolutionState.error = error;\n\t\t\t\t}\n\n\t\t\t\tnextState.set(\n\t\t\t\t\tselectorArgsToStateKey( resolutionArgs as unknown[] ),\n\t\t\t\t\tresolutionState\n\t\t\t\t);\n\t\t\t} );\n\t\t\treturn nextState;\n\t\t}\n\t\tcase 'INVALIDATE_RESOLUTION': {\n\t\t\tconst nextState = new EquivalentKeyMap( state );\n\t\t\tnextState.delete( selectorArgsToStateKey( action.args ) );\n\t\t\treturn nextState;\n\t\t}\n\t}\n\treturn state;\n} );\n\n/**\n * Reducer function returning next state for selector resolution, object form:\n *\n * selectorName -> EquivalentKeyMap<Array, boolean>\n *\n * @param state Current state.\n * @param action Dispatched action.\n *\n * @return Next state.\n */\nconst isResolved = ( state: Record< string, State > = {}, action: Action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'INVALIDATE_RESOLUTION_FOR_STORE':\n\t\t\treturn {};\n\t\tcase 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR': {\n\t\t\tif ( action.selectorName in state ) {\n\t\t\t\tconst {\n\t\t\t\t\t[ action.selectorName ]: removedSelector,\n\t\t\t\t\t...restState\n\t\t\t\t} = state;\n\t\t\t\treturn restState;\n\t\t\t}\n\t\t\treturn state;\n\t\t}\n\t\tcase 'START_RESOLUTION':\n\t\tcase 'FINISH_RESOLUTION':\n\t\tcase 'FAIL_RESOLUTION':\n\t\tcase 'START_RESOLUTIONS':\n\t\tcase 'FINISH_RESOLUTIONS':\n\t\tcase 'FAIL_RESOLUTIONS':\n\t\tcase 'INVALIDATE_RESOLUTION':\n\t\t\treturn subKeysIsResolved( state, action );\n\t}\n\treturn state;\n};\n\nexport default isResolved;\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,sBAAsB;AAM7B,SAAS,wBAAwB,gBAAgB;AA6BjD,MAAM,oBAAgE,SAGnE,cAAe,EAAG,CAAE,QAAQ,IAAI,iBAAiB,GAAG,WAAoB;AAC1E,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,oBAAoB;AACxB,YAAM,YAAY,IAAI,iBAAkB,KAAM;AAC9C,gBAAU,IAAK,uBAAwB,OAAO,IAAK,GAAG;AAAA,QACrD,QAAQ;AAAA,MACT,CAAE;AACF,aAAO;AAAA,IACR;AAAA,IACA,KAAK,qBAAqB;AACzB,YAAM,YAAY,IAAI,iBAAkB,KAAM;AAC9C,gBAAU,IAAK,uBAAwB,OAAO,IAAK,GAAG;AAAA,QACrD,QAAQ;AAAA,MACT,CAAE;AACF,aAAO;AAAA,IACR;AAAA,IACA,KAAK,mBAAmB;AACvB,YAAM,YAAY,IAAI,iBAAkB,KAAM;AAC9C,gBAAU,IAAK,uBAAwB,OAAO,IAAK,GAAG;AAAA,QACrD,QAAQ;AAAA,QACR,OAAO,OAAO;AAAA,MACf,CAAE;AACF,aAAO;AAAA,IACR;AAAA,IACA,KAAK,qBAAqB;AACzB,YAAM,YAAY,IAAI,iBAAkB,KAAM;AAC9C,iBAAY,kBAAkB,OAAO,MAAO;AAC3C,kBAAU,IAAK,uBAAwB,cAAe,GAAG;AAAA,UACxD,QAAQ;AAAA,QACT,CAAE;AAAA,MACH;AACA,aAAO;AAAA,IACR;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IAAO,kBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,194 +1,95 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { createSelector } from '../../create-selector';
|
|
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 */
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Returns the raw resolution state value for a given selector name,
|
|
18
|
-
* and arguments set. May be undefined if the selector has never been resolved
|
|
19
|
-
* or not resolved for the given set of arguments, otherwise true or false for
|
|
20
|
-
* resolution started and completed respectively.
|
|
21
|
-
*
|
|
22
|
-
* @param {State} state Data state.
|
|
23
|
-
* @param {string} selectorName Selector name.
|
|
24
|
-
* @param {unknown[]?} args Arguments passed to selector.
|
|
25
|
-
*
|
|
26
|
-
* @return {StateValue|undefined} isResolving value.
|
|
27
|
-
*/
|
|
28
|
-
export function getResolutionState(state, selectorName, args) {
|
|
1
|
+
import deprecated from "@wordpress/deprecated";
|
|
2
|
+
import { createSelector } from "../../create-selector";
|
|
3
|
+
import { selectorArgsToStateKey } from "./utils";
|
|
4
|
+
function getResolutionState(state, selectorName, args) {
|
|
29
5
|
const map = state[selectorName];
|
|
30
6
|
if (!map) {
|
|
31
7
|
return;
|
|
32
8
|
}
|
|
33
9
|
return map.get(selectorArgsToStateKey(args));
|
|
34
10
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
* has finished, respectively.
|
|
41
|
-
*
|
|
42
|
-
* This is a legacy selector that was implemented when the "raw" internal data had
|
|
43
|
-
* this `undefined | boolean` format. Nowadays the internal value is an object that
|
|
44
|
-
* can be retrieved with `getResolutionState`.
|
|
45
|
-
*
|
|
46
|
-
* @deprecated
|
|
47
|
-
*
|
|
48
|
-
* @param {State} state Data state.
|
|
49
|
-
* @param {string} selectorName Selector name.
|
|
50
|
-
* @param {unknown[]?} args Arguments passed to selector.
|
|
51
|
-
*
|
|
52
|
-
* @return {boolean | undefined} isResolving value.
|
|
53
|
-
*/
|
|
54
|
-
export function getIsResolving(state, selectorName, args) {
|
|
55
|
-
deprecated('wp.data.select( store ).getIsResolving', {
|
|
56
|
-
since: '6.6',
|
|
57
|
-
version: '6.8',
|
|
58
|
-
alternative: 'wp.data.select( store ).getResolutionState'
|
|
11
|
+
function getIsResolving(state, selectorName, args) {
|
|
12
|
+
deprecated("wp.data.select( store ).getIsResolving", {
|
|
13
|
+
since: "6.6",
|
|
14
|
+
version: "6.8",
|
|
15
|
+
alternative: "wp.data.select( store ).getResolutionState"
|
|
59
16
|
});
|
|
60
17
|
const resolutionState = getResolutionState(state, selectorName, args);
|
|
61
|
-
return resolutionState && resolutionState.status ===
|
|
18
|
+
return resolutionState && resolutionState.status === "resolving";
|
|
62
19
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
* Returns true if resolution has already been triggered for a given
|
|
66
|
-
* selector name, and arguments set.
|
|
67
|
-
*
|
|
68
|
-
* @param {State} state Data state.
|
|
69
|
-
* @param {string} selectorName Selector name.
|
|
70
|
-
* @param {unknown[]?} args Arguments passed to selector.
|
|
71
|
-
*
|
|
72
|
-
* @return {boolean} Whether resolution has been triggered.
|
|
73
|
-
*/
|
|
74
|
-
export function hasStartedResolution(state, selectorName, args) {
|
|
75
|
-
return getResolutionState(state, selectorName, args) !== undefined;
|
|
20
|
+
function hasStartedResolution(state, selectorName, args) {
|
|
21
|
+
return getResolutionState(state, selectorName, args) !== void 0;
|
|
76
22
|
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Returns true if resolution has completed for a given selector
|
|
80
|
-
* name, and arguments set.
|
|
81
|
-
*
|
|
82
|
-
* @param {State} state Data state.
|
|
83
|
-
* @param {string} selectorName Selector name.
|
|
84
|
-
* @param {unknown[]?} args Arguments passed to selector.
|
|
85
|
-
*
|
|
86
|
-
* @return {boolean} Whether resolution has completed.
|
|
87
|
-
*/
|
|
88
|
-
export function hasFinishedResolution(state, selectorName, args) {
|
|
23
|
+
function hasFinishedResolution(state, selectorName, args) {
|
|
89
24
|
const status = getResolutionState(state, selectorName, args)?.status;
|
|
90
|
-
return status ===
|
|
25
|
+
return status === "finished" || status === "error";
|
|
91
26
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
* Returns true if resolution has failed for a given selector
|
|
95
|
-
* name, and arguments set.
|
|
96
|
-
*
|
|
97
|
-
* @param {State} state Data state.
|
|
98
|
-
* @param {string} selectorName Selector name.
|
|
99
|
-
* @param {unknown[]?} args Arguments passed to selector.
|
|
100
|
-
*
|
|
101
|
-
* @return {boolean} Has resolution failed
|
|
102
|
-
*/
|
|
103
|
-
export function hasResolutionFailed(state, selectorName, args) {
|
|
104
|
-
return getResolutionState(state, selectorName, args)?.status === 'error';
|
|
27
|
+
function hasResolutionFailed(state, selectorName, args) {
|
|
28
|
+
return getResolutionState(state, selectorName, args)?.status === "error";
|
|
105
29
|
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Returns the resolution error for a given selector name, and arguments set.
|
|
109
|
-
* Note it may be of an Error type, but may also be null, undefined, or anything else
|
|
110
|
-
* that can be `throw`-n.
|
|
111
|
-
*
|
|
112
|
-
* @param {State} state Data state.
|
|
113
|
-
* @param {string} selectorName Selector name.
|
|
114
|
-
* @param {unknown[]?} args Arguments passed to selector.
|
|
115
|
-
*
|
|
116
|
-
* @return {Error|unknown} Last resolution error
|
|
117
|
-
*/
|
|
118
|
-
export function getResolutionError(state, selectorName, args) {
|
|
30
|
+
function getResolutionError(state, selectorName, args) {
|
|
119
31
|
const resolutionState = getResolutionState(state, selectorName, args);
|
|
120
|
-
return resolutionState?.status ===
|
|
32
|
+
return resolutionState?.status === "error" ? resolutionState.error : null;
|
|
121
33
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
* Returns true if resolution has been triggered but has not yet completed for
|
|
125
|
-
* a given selector name, and arguments set.
|
|
126
|
-
*
|
|
127
|
-
* @param {State} state Data state.
|
|
128
|
-
* @param {string} selectorName Selector name.
|
|
129
|
-
* @param {unknown[]?} args Arguments passed to selector.
|
|
130
|
-
*
|
|
131
|
-
* @return {boolean} Whether resolution is in progress.
|
|
132
|
-
*/
|
|
133
|
-
export function isResolving(state, selectorName, args) {
|
|
134
|
-
return getResolutionState(state, selectorName, args)?.status === 'resolving';
|
|
34
|
+
function isResolving(state, selectorName, args) {
|
|
35
|
+
return getResolutionState(state, selectorName, args)?.status === "resolving";
|
|
135
36
|
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Returns the list of the cached resolvers.
|
|
139
|
-
*
|
|
140
|
-
* @param {State} state Data state.
|
|
141
|
-
*
|
|
142
|
-
* @return {State} Resolvers mapped by args and selectorName.
|
|
143
|
-
*/
|
|
144
|
-
export function getCachedResolvers(state) {
|
|
37
|
+
function getCachedResolvers(state) {
|
|
145
38
|
return state;
|
|
146
39
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* @see https://github.com/aduth/equivalent-key-map
|
|
163
|
-
*/
|
|
164
|
-
Array.from(selectorState._map.values()).some(resolution => resolution[1]?.status === 'resolving'));
|
|
40
|
+
function hasResolvingSelectors(state) {
|
|
41
|
+
return Object.values(state).some(
|
|
42
|
+
(selectorState) => (
|
|
43
|
+
/**
|
|
44
|
+
* This uses the internal `_map` property of `EquivalentKeyMap` for
|
|
45
|
+
* optimization purposes, since the `EquivalentKeyMap` implementation
|
|
46
|
+
* does not support a `.values()` implementation.
|
|
47
|
+
*
|
|
48
|
+
* @see https://github.com/aduth/equivalent-key-map
|
|
49
|
+
*/
|
|
50
|
+
Array.from(selectorState._map.values()).some(
|
|
51
|
+
(resolution) => resolution[1]?.status === "resolving"
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
);
|
|
165
55
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
56
|
+
const countSelectorsByStatus = createSelector(
|
|
57
|
+
(state) => {
|
|
58
|
+
const selectorsByStatus = {};
|
|
59
|
+
Object.values(state).forEach(
|
|
60
|
+
(selectorState) => (
|
|
61
|
+
/**
|
|
62
|
+
* This uses the internal `_map` property of `EquivalentKeyMap` for
|
|
63
|
+
* optimization purposes, since the `EquivalentKeyMap` implementation
|
|
64
|
+
* does not support a `.values()` implementation.
|
|
65
|
+
*
|
|
66
|
+
* @see https://github.com/aduth/equivalent-key-map
|
|
67
|
+
*/
|
|
68
|
+
Array.from(selectorState._map.values()).forEach(
|
|
69
|
+
(resolution) => {
|
|
70
|
+
const currentStatus = resolution[1]?.status ?? "error";
|
|
71
|
+
if (!selectorsByStatus[currentStatus]) {
|
|
72
|
+
selectorsByStatus[currentStatus] = 0;
|
|
73
|
+
}
|
|
74
|
+
selectorsByStatus[currentStatus]++;
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
return selectorsByStatus;
|
|
80
|
+
},
|
|
81
|
+
(state) => [state]
|
|
82
|
+
);
|
|
83
|
+
export {
|
|
84
|
+
countSelectorsByStatus,
|
|
85
|
+
getCachedResolvers,
|
|
86
|
+
getIsResolving,
|
|
87
|
+
getResolutionError,
|
|
88
|
+
getResolutionState,
|
|
89
|
+
hasFinishedResolution,
|
|
90
|
+
hasResolutionFailed,
|
|
91
|
+
hasResolvingSelectors,
|
|
92
|
+
hasStartedResolution,
|
|
93
|
+
isResolving
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["deprecated","createSelector","selectorArgsToStateKey","getResolutionState","state","selectorName","args","map","get","getIsResolving","since","version","alternative","resolutionState","status","hasStartedResolution","undefined","hasFinishedResolution","hasResolutionFailed","getResolutionError","error","isResolving","getCachedResolvers","hasResolvingSelectors","Object","values","some","selectorState","Array","from","_map","resolution","countSelectorsByStatus","selectorsByStatus","forEach","_resolution$1$status","currentStatus"],"sources":["@wordpress/data/src/redux-store/metadata/selectors.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createSelector } from '../../create-selector';\nimport { selectorArgsToStateKey } from './utils';\n\n/** @typedef {Record<string, import('./reducer').State>} State */\n/** @typedef {import('./reducer').StateValue} StateValue */\n/** @typedef {import('./reducer').Status} Status */\n\n/**\n * Returns the raw resolution state value for a given selector name,\n * and arguments set. May be undefined if the selector has never been resolved\n * or not resolved for the given set of arguments, otherwise true or false for\n * resolution started and completed respectively.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {StateValue|undefined} isResolving value.\n */\nexport function getResolutionState( state, selectorName, args ) {\n\tconst map = state[ selectorName ];\n\tif ( ! map ) {\n\t\treturn;\n\t}\n\n\treturn map.get( selectorArgsToStateKey( args ) );\n}\n\n/**\n * Returns an `isResolving`-like value for a given selector name and arguments set.\n * Its value is either `undefined` if the selector has never been resolved or has been\n * invalidated, or a `true`/`false` boolean value if the resolution is in progress or\n * has finished, respectively.\n *\n * This is a legacy selector that was implemented when the \"raw\" internal data had\n * this `undefined | boolean` format. Nowadays the internal value is an object that\n * can be retrieved with `getResolutionState`.\n *\n * @deprecated\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean | undefined} isResolving value.\n */\nexport function getIsResolving( state, selectorName, args ) {\n\tdeprecated( 'wp.data.select( store ).getIsResolving', {\n\t\tsince: '6.6',\n\t\tversion: '6.8',\n\t\talternative: 'wp.data.select( store ).getResolutionState',\n\t} );\n\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\treturn resolutionState && resolutionState.status === 'resolving';\n}\n\n/**\n * Returns true if resolution has already been triggered for a given\n * selector name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has been triggered.\n */\nexport function hasStartedResolution( state, selectorName, args ) {\n\treturn getResolutionState( state, selectorName, args ) !== undefined;\n}\n\n/**\n * Returns true if resolution has completed for a given selector\n * name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has completed.\n */\nexport function hasFinishedResolution( state, selectorName, args ) {\n\tconst status = getResolutionState( state, selectorName, args )?.status;\n\treturn status === 'finished' || status === 'error';\n}\n\n/**\n * Returns true if resolution has failed for a given selector\n * name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Has resolution failed\n */\nexport function hasResolutionFailed( state, selectorName, args ) {\n\treturn getResolutionState( state, selectorName, args )?.status === 'error';\n}\n\n/**\n * Returns the resolution error for a given selector name, and arguments set.\n * Note it may be of an Error type, but may also be null, undefined, or anything else\n * that can be `throw`-n.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {Error|unknown} Last resolution error\n */\nexport function getResolutionError( state, selectorName, args ) {\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\treturn resolutionState?.status === 'error' ? resolutionState.error : null;\n}\n\n/**\n * Returns true if resolution has been triggered but has not yet completed for\n * a given selector name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution is in progress.\n */\nexport function isResolving( state, selectorName, args ) {\n\treturn (\n\t\tgetResolutionState( state, selectorName, args )?.status === 'resolving'\n\t);\n}\n\n/**\n * Returns the list of the cached resolvers.\n *\n * @param {State} state Data state.\n *\n * @return {State} Resolvers mapped by args and selectorName.\n */\nexport function getCachedResolvers( state ) {\n\treturn state;\n}\n\n/**\n * Whether the store has any currently resolving selectors.\n *\n * @param {State} state Data state.\n *\n * @return {boolean} True if one or more selectors are resolving, false otherwise.\n */\nexport function hasResolvingSelectors( state ) {\n\treturn Object.values( state ).some( ( selectorState ) =>\n\t\t/**\n\t\t * This uses the internal `_map` property of `EquivalentKeyMap` for\n\t\t * optimization purposes, since the `EquivalentKeyMap` implementation\n\t\t * does not support a `.values()` implementation.\n\t\t *\n\t\t * @see https://github.com/aduth/equivalent-key-map\n\t\t */\n\t\tArray.from( selectorState._map.values() ).some(\n\t\t\t( resolution ) => resolution[ 1 ]?.status === 'resolving'\n\t\t)\n\t);\n}\n\n/**\n * Retrieves the total number of selectors, grouped per status.\n *\n * @param {State} state Data state.\n *\n * @return {Object} Object, containing selector totals by status.\n */\nexport const countSelectorsByStatus = createSelector(\n\t( state ) => {\n\t\tconst selectorsByStatus = {};\n\n\t\tObject.values( state ).forEach( ( selectorState ) =>\n\t\t\t/**\n\t\t\t * This uses the internal `_map` property of `EquivalentKeyMap` for\n\t\t\t * optimization purposes, since the `EquivalentKeyMap` implementation\n\t\t\t * does not support a `.values()` implementation.\n\t\t\t *\n\t\t\t * @see https://github.com/aduth/equivalent-key-map\n\t\t\t */\n\t\t\tArray.from( selectorState._map.values() ).forEach(\n\t\t\t\t( resolution ) => {\n\t\t\t\t\tconst currentStatus = resolution[ 1 ]?.status ?? 'error';\n\t\t\t\t\tif ( ! selectorsByStatus[ currentStatus ] ) {\n\t\t\t\t\t\tselectorsByStatus[ currentStatus ] = 0;\n\t\t\t\t\t}\n\t\t\t\t\tselectorsByStatus[ currentStatus ]++;\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\n\t\treturn selectorsByStatus;\n\t},\n\t( state ) => [ state ]\n);\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,SAASC,cAAc,QAAQ,uBAAuB;AACtD,SAASC,sBAAsB,QAAQ,SAAS;;AAEhD;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,kBAAkBA,CAAEC,KAAK,EAAEC,YAAY,EAAEC,IAAI,EAAG;EAC/D,MAAMC,GAAG,GAAGH,KAAK,CAAEC,YAAY,CAAE;EACjC,IAAK,CAAEE,GAAG,EAAG;IACZ;EACD;EAEA,OAAOA,GAAG,CAACC,GAAG,CAAEN,sBAAsB,CAAEI,IAAK,CAAE,CAAC;AACjD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASG,cAAcA,CAAEL,KAAK,EAAEC,YAAY,EAAEC,IAAI,EAAG;EAC3DN,UAAU,CAAE,wCAAwC,EAAE;IACrDU,KAAK,EAAE,KAAK;IACZC,OAAO,EAAE,KAAK;IACdC,WAAW,EAAE;EACd,CAAE,CAAC;EAEH,MAAMC,eAAe,GAAGV,kBAAkB,CAAEC,KAAK,EAAEC,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,CACD,CACD,CAAC;EAED,OAAOH,iBAAiB;AACzB,CAAC,EACC7B,KAAK,IAAM,CAAEA,KAAK,CACrB,CAAC","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/redux-store/metadata/selectors.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createSelector } from '../../create-selector';\nimport { selectorArgsToStateKey } from './utils';\n\n/** @typedef {Record<string, import('./reducer').State>} State */\n/** @typedef {import('./reducer').StateValue} StateValue */\n/** @typedef {import('./reducer').Status} Status */\n\n/**\n * Returns the raw resolution state value for a given selector name,\n * and arguments set. May be undefined if the selector has never been resolved\n * or not resolved for the given set of arguments, otherwise true or false for\n * resolution started and completed respectively.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {StateValue|undefined} isResolving value.\n */\nexport function getResolutionState( state, selectorName, args ) {\n\tconst map = state[ selectorName ];\n\tif ( ! map ) {\n\t\treturn;\n\t}\n\n\treturn map.get( selectorArgsToStateKey( args ) );\n}\n\n/**\n * Returns an `isResolving`-like value for a given selector name and arguments set.\n * Its value is either `undefined` if the selector has never been resolved or has been\n * invalidated, or a `true`/`false` boolean value if the resolution is in progress or\n * has finished, respectively.\n *\n * This is a legacy selector that was implemented when the \"raw\" internal data had\n * this `undefined | boolean` format. Nowadays the internal value is an object that\n * can be retrieved with `getResolutionState`.\n *\n * @deprecated\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean | undefined} isResolving value.\n */\nexport function getIsResolving( state, selectorName, args ) {\n\tdeprecated( 'wp.data.select( store ).getIsResolving', {\n\t\tsince: '6.6',\n\t\tversion: '6.8',\n\t\talternative: 'wp.data.select( store ).getResolutionState',\n\t} );\n\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\treturn resolutionState && resolutionState.status === 'resolving';\n}\n\n/**\n * Returns true if resolution has already been triggered for a given\n * selector name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has been triggered.\n */\nexport function hasStartedResolution( state, selectorName, args ) {\n\treturn getResolutionState( state, selectorName, args ) !== undefined;\n}\n\n/**\n * Returns true if resolution has completed for a given selector\n * name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution has completed.\n */\nexport function hasFinishedResolution( state, selectorName, args ) {\n\tconst status = getResolutionState( state, selectorName, args )?.status;\n\treturn status === 'finished' || status === 'error';\n}\n\n/**\n * Returns true if resolution has failed for a given selector\n * name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Has resolution failed\n */\nexport function hasResolutionFailed( state, selectorName, args ) {\n\treturn getResolutionState( state, selectorName, args )?.status === 'error';\n}\n\n/**\n * Returns the resolution error for a given selector name, and arguments set.\n * Note it may be of an Error type, but may also be null, undefined, or anything else\n * that can be `throw`-n.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {Error|unknown} Last resolution error\n */\nexport function getResolutionError( state, selectorName, args ) {\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\treturn resolutionState?.status === 'error' ? resolutionState.error : null;\n}\n\n/**\n * Returns true if resolution has been triggered but has not yet completed for\n * a given selector name, and arguments set.\n *\n * @param {State} state Data state.\n * @param {string} selectorName Selector name.\n * @param {unknown[]?} args Arguments passed to selector.\n *\n * @return {boolean} Whether resolution is in progress.\n */\nexport function isResolving( state, selectorName, args ) {\n\treturn (\n\t\tgetResolutionState( state, selectorName, args )?.status === 'resolving'\n\t);\n}\n\n/**\n * Returns the list of the cached resolvers.\n *\n * @param {State} state Data state.\n *\n * @return {State} Resolvers mapped by args and selectorName.\n */\nexport function getCachedResolvers( state ) {\n\treturn state;\n}\n\n/**\n * Whether the store has any currently resolving selectors.\n *\n * @param {State} state Data state.\n *\n * @return {boolean} True if one or more selectors are resolving, false otherwise.\n */\nexport function hasResolvingSelectors( state ) {\n\treturn Object.values( state ).some( ( selectorState ) =>\n\t\t/**\n\t\t * This uses the internal `_map` property of `EquivalentKeyMap` for\n\t\t * optimization purposes, since the `EquivalentKeyMap` implementation\n\t\t * does not support a `.values()` implementation.\n\t\t *\n\t\t * @see https://github.com/aduth/equivalent-key-map\n\t\t */\n\t\tArray.from( selectorState._map.values() ).some(\n\t\t\t( resolution ) => resolution[ 1 ]?.status === 'resolving'\n\t\t)\n\t);\n}\n\n/**\n * Retrieves the total number of selectors, grouped per status.\n *\n * @param {State} state Data state.\n *\n * @return {Object} Object, containing selector totals by status.\n */\nexport const countSelectorsByStatus = createSelector(\n\t( state ) => {\n\t\tconst selectorsByStatus = {};\n\n\t\tObject.values( state ).forEach( ( selectorState ) =>\n\t\t\t/**\n\t\t\t * This uses the internal `_map` property of `EquivalentKeyMap` for\n\t\t\t * optimization purposes, since the `EquivalentKeyMap` implementation\n\t\t\t * does not support a `.values()` implementation.\n\t\t\t *\n\t\t\t * @see https://github.com/aduth/equivalent-key-map\n\t\t\t */\n\t\t\tArray.from( selectorState._map.values() ).forEach(\n\t\t\t\t( resolution ) => {\n\t\t\t\t\tconst currentStatus = resolution[ 1 ]?.status ?? 'error';\n\t\t\t\t\tif ( ! selectorsByStatus[ currentStatus ] ) {\n\t\t\t\t\t\tselectorsByStatus[ currentStatus ] = 0;\n\t\t\t\t\t}\n\t\t\t\t\tselectorsByStatus[ currentStatus ]++;\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\n\t\treturn selectorsByStatus;\n\t},\n\t( state ) => [ state ]\n);\n"],
|
|
5
|
+
"mappings": "AA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AgB,WAAY,CAAE,GAAG,WAAW;AAAA,MAC/C;AAAA;AAAA,EACD;AACD;AASO,MAAM,yBAAyB;AAAA,EACrC,CAAE,UAAW;AACZ,UAAM,oBAAoB,CAAC;AAE3B,WAAO,OAAQ,KAAM,EAAE;AAAA,MAAS,CAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAQjC,MAAM,KAAM,cAAc,KAAK,OAAO,CAAE,EAAE;AAAA,UACzC,CAAE,eAAgB;AACjB,kBAAM,gBAAgB,WAAY,CAAE,GAAG,UAAU;AACjD,gBAAK,CAAE,kBAAmB,aAAc,GAAI;AAC3C,gCAAmB,aAAc,IAAI;AAAA,YACtC;AACA,8BAAmB,aAAc;AAAA,UAClC;AAAA,QACD;AAAA;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAAA,EACA,CAAE,UAAW,CAAE,KAAM;AACtB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,24 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Higher-order reducer creator which creates a combined reducer object, keyed
|
|
7
|
-
* by a property on the action object.
|
|
8
|
-
*
|
|
9
|
-
* @param actionProperty Action property by which to key object.
|
|
10
|
-
* @return Higher-order reducer.
|
|
11
|
-
*/
|
|
12
|
-
export const onSubKey = actionProperty => reducer => (state = {}, action) => {
|
|
13
|
-
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
|
14
|
-
// where reducer is scoped by action shape.
|
|
1
|
+
const onSubKey = (actionProperty) => (reducer) => (state = {}, action) => {
|
|
15
2
|
const key = action[actionProperty];
|
|
16
|
-
if (key ===
|
|
3
|
+
if (key === void 0) {
|
|
17
4
|
return state;
|
|
18
5
|
}
|
|
19
|
-
|
|
20
|
-
// Avoid updating state if unchanged. Note that this also accounts for a
|
|
21
|
-
// reducer which returns undefined on a key which is not yet tracked.
|
|
22
6
|
const nextKeyState = reducer(state[key], action);
|
|
23
7
|
if (nextKeyState === state[key]) {
|
|
24
8
|
return state;
|
|
@@ -28,23 +12,19 @@ export const onSubKey = actionProperty => reducer => (state = {}, action) => {
|
|
|
28
12
|
[key]: nextKeyState
|
|
29
13
|
};
|
|
30
14
|
};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
* Normalize selector argument array by defaulting `undefined` value to an empty array
|
|
34
|
-
* and removing trailing `undefined` values.
|
|
35
|
-
*
|
|
36
|
-
* @param args Selector argument array
|
|
37
|
-
* @return Normalized state key array
|
|
38
|
-
*/
|
|
39
|
-
export function selectorArgsToStateKey(args) {
|
|
40
|
-
if (args === undefined || args === null) {
|
|
15
|
+
function selectorArgsToStateKey(args) {
|
|
16
|
+
if (args === void 0 || args === null) {
|
|
41
17
|
return [];
|
|
42
18
|
}
|
|
43
19
|
const len = args.length;
|
|
44
20
|
let idx = len;
|
|
45
|
-
while (idx > 0 && args[idx - 1] ===
|
|
21
|
+
while (idx > 0 && args[idx - 1] === void 0) {
|
|
46
22
|
idx--;
|
|
47
23
|
}
|
|
48
24
|
return idx === len ? args : args.slice(0, idx);
|
|
49
25
|
}
|
|
50
|
-
|
|
26
|
+
export {
|
|
27
|
+
onSubKey,
|
|
28
|
+
selectorArgsToStateKey
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/redux-store/metadata/utils.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { AnyAction, Reducer } from 'redux';\n\n/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param actionProperty Action property by which to key object.\n * @return Higher-order reducer.\n */\nexport const onSubKey =\n\t< TState extends unknown, TAction extends AnyAction >(\n\t\tactionProperty: string\n\t) =>\n\t(\n\t\treducer: Reducer< TState, TAction >\n\t): Reducer< Record< string, TState >, TAction > =>\n\t( state: Record< string, TState > = {}, action ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\n/**\n * Normalize selector argument array by defaulting `undefined` value to an empty array\n * and removing trailing `undefined` values.\n *\n * @param args Selector argument array\n * @return Normalized state key array\n */\nexport function selectorArgsToStateKey( args: unknown[] | null | undefined ) {\n\tif ( args === undefined || args === null ) {\n\t\treturn [];\n\t}\n\n\tconst len = args.length;\n\tlet idx = len;\n\twhile ( idx > 0 && args[ idx - 1 ] === undefined ) {\n\t\tidx--;\n\t}\n\treturn idx === len ? args : args.slice( 0, idx );\n}\n"],
|
|
5
|
+
"mappings": "AAYO,MAAM,WACZ,CACC,mBAED,CACC,YAED,CAAE,QAAkC,CAAC,GAAG,WAAY;AAGnD,QAAM,MAAM,OAAQ,cAAe;AACnC,MAAK,QAAQ,QAAY;AACxB,WAAO;AAAA,EACR;AAIA,QAAM,eAAe,QAAS,MAAO,GAAI,GAAG,MAAO;AACnD,MAAK,iBAAiB,MAAO,GAAI,GAAI;AACpC,WAAO;AAAA,EACR;AAEA,SAAO;AAAA,IACN,GAAG;AAAA,IACH,CAAE,GAAI,GAAG;AAAA,EACV;AACD;AASM,SAAS,uBAAwB,MAAqC;AAC5E,MAAK,SAAS,UAAa,SAAS,MAAO;AAC1C,WAAO,CAAC;AAAA,EACT;AAEA,QAAM,MAAM,KAAK;AACjB,MAAI,MAAM;AACV,SAAQ,MAAM,KAAK,KAAM,MAAM,CAAE,MAAM,QAAY;AAClD;AAAA,EACD;AACA,SAAO,QAAQ,MAAM,OAAO,KAAK,MAAO,GAAG,GAAI;AAChD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
return () => next => action => {
|
|
3
|
-
if (typeof action ===
|
|
1
|
+
function createThunkMiddleware(args) {
|
|
2
|
+
return () => (next) => (action) => {
|
|
3
|
+
if (typeof action === "function") {
|
|
4
4
|
return action(args);
|
|
5
5
|
}
|
|
6
6
|
return next(action);
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
export {
|
|
10
|
+
createThunkMiddleware as default
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=thunk-middleware.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/redux-store/thunk-middleware.js"],
|
|
4
|
+
"sourcesContent": ["export default function createThunkMiddleware( args ) {\n\treturn () => ( next ) => ( action ) => {\n\t\tif ( typeof action === 'function' ) {\n\t\t\treturn action( args );\n\t\t}\n\n\t\treturn next( action );\n\t};\n}\n"],
|
|
5
|
+
"mappings": "AAAe,SAAR,sBAAwC,MAAO;AACrD,SAAO,MAAM,CAAE,SAAU,CAAE,WAAY;AACtC,QAAK,OAAO,WAAW,YAAa;AACnC,aAAO,OAAQ,IAAK;AAAA,IACrB;AAEA,WAAO,KAAM,MAAO;AAAA,EACrB;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|