@wordpress/data 6.2.1 → 6.3.1-next.a55ed9455a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/build/components/use-select/index.js +1 -1
- package/build/components/use-select/index.js.map +1 -1
- package/build/factory.js +1 -1
- package/build/factory.js.map +1 -1
- package/build/plugins/persistence/index.js +114 -12
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/redux-store/index.js +25 -14
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/actions.js +51 -8
- package/build/redux-store/metadata/actions.js.map +1 -1
- package/build/redux-store/metadata/reducer.js +58 -5
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +93 -26
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +31 -13
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/registry.js +0 -2
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +3 -3
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build-module/components/use-select/index.js +1 -1
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/factory.js +1 -1
- package/build-module/factory.js.map +1 -1
- package/build-module/plugins/persistence/index.js +111 -12
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/redux-store/index.js +25 -14
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/actions.js +47 -8
- package/build-module/redux-store/metadata/actions.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +59 -6
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +86 -26
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +29 -13
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/registry.js +0 -2
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +3 -3
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-types/redux-store/metadata/actions.d.ts +44 -11
- package/build-types/redux-store/metadata/actions.d.ts.map +1 -1
- package/build-types/redux-store/metadata/reducer.d.ts +10 -2
- package/build-types/redux-store/metadata/reducer.d.ts.map +1 -1
- package/build-types/redux-store/metadata/selectors.d.ts +56 -16
- package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
- package/build-types/redux-store/metadata/utils.d.ts +20 -1
- package/build-types/redux-store/metadata/utils.d.ts.map +1 -1
- package/build-types/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/components/use-select/index.js +1 -1
- package/src/components/use-select/test/index.js +7 -7
- package/src/components/with-select/test/index.js +3 -3
- package/src/factory.js +1 -1
- package/src/plugins/persistence/index.js +142 -8
- package/src/plugins/persistence/test/index.js +405 -0
- package/src/redux-store/index.js +44 -19
- package/src/redux-store/metadata/actions.js +47 -8
- package/src/redux-store/metadata/reducer.ts +63 -9
- package/src/redux-store/metadata/selectors.js +81 -23
- package/src/redux-store/metadata/test/reducer.js +98 -18
- package/src/redux-store/metadata/test/selectors.js +266 -45
- package/src/redux-store/metadata/test/utils.js +28 -1
- package/src/redux-store/metadata/utils.ts +59 -0
- package/src/redux-store/test/index.js +42 -0
- package/src/registry.js +0 -2
- package/src/resolvers-cache-middleware.js +4 -3
- package/src/test/controls.js +7 -7
- package/src/test/registry.js +6 -6
- package/src/types.ts +1 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/src/redux-store/metadata/utils.js +0 -37
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.failResolution = failResolution;
|
|
7
|
+
exports.failResolutions = failResolutions;
|
|
6
8
|
exports.finishResolution = finishResolution;
|
|
7
9
|
exports.finishResolutions = finishResolutions;
|
|
8
10
|
exports.invalidateResolution = invalidateResolution;
|
|
@@ -45,15 +47,35 @@ function finishResolution(selectorName, args) {
|
|
|
45
47
|
args
|
|
46
48
|
};
|
|
47
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns an action object used in signalling that selector resolution has
|
|
52
|
+
* failed.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} selectorName Name of selector for which resolver triggered.
|
|
55
|
+
* @param {unknown[]} args Arguments to associate for uniqueness.
|
|
56
|
+
* @param {Error|unknown} error The error that caused the failure.
|
|
57
|
+
*
|
|
58
|
+
* @return {{ type: 'FAIL_RESOLUTION', selectorName: string, args: unknown[], error: Error|unknown }} Action object.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
function failResolution(selectorName, args, error) {
|
|
63
|
+
return {
|
|
64
|
+
type: 'FAIL_RESOLUTION',
|
|
65
|
+
selectorName,
|
|
66
|
+
args,
|
|
67
|
+
error
|
|
68
|
+
};
|
|
69
|
+
}
|
|
48
70
|
/**
|
|
49
71
|
* Returns an action object used in signalling that a batch of selector resolutions has
|
|
50
72
|
* started.
|
|
51
73
|
*
|
|
52
|
-
* @param {string}
|
|
53
|
-
* @param {unknown[]} args Array of arguments to associate for uniqueness, each item
|
|
54
|
-
*
|
|
74
|
+
* @param {string} selectorName Name of selector for which resolver triggered.
|
|
75
|
+
* @param {unknown[][]} args Array of arguments to associate for uniqueness, each item
|
|
76
|
+
* is associated to a resolution.
|
|
55
77
|
*
|
|
56
|
-
* @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[] }} Action object.
|
|
78
|
+
* @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.
|
|
57
79
|
*/
|
|
58
80
|
|
|
59
81
|
|
|
@@ -68,11 +90,11 @@ function startResolutions(selectorName, args) {
|
|
|
68
90
|
* Returns an action object used in signalling that a batch of selector resolutions has
|
|
69
91
|
* completed.
|
|
70
92
|
*
|
|
71
|
-
* @param {string}
|
|
72
|
-
* @param {unknown[]} args Array of arguments to associate for uniqueness, each item
|
|
73
|
-
*
|
|
93
|
+
* @param {string} selectorName Name of selector for which resolver triggered.
|
|
94
|
+
* @param {unknown[][]} args Array of arguments to associate for uniqueness, each item
|
|
95
|
+
* is associated to a resolution.
|
|
74
96
|
*
|
|
75
|
-
* @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[] }} Action object.
|
|
97
|
+
* @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.
|
|
76
98
|
*/
|
|
77
99
|
|
|
78
100
|
|
|
@@ -83,6 +105,27 @@ function finishResolutions(selectorName, args) {
|
|
|
83
105
|
args
|
|
84
106
|
};
|
|
85
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Returns an action object used in signalling that a batch of selector resolutions has
|
|
110
|
+
* completed and at least one of them has failed.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} selectorName Name of selector for which resolver triggered.
|
|
113
|
+
* @param {unknown[]} args Array of arguments to associate for uniqueness, each item
|
|
114
|
+
* is associated to a resolution.
|
|
115
|
+
* @param {(Error|unknown)[]} errors Array of errors to associate for uniqueness, each item
|
|
116
|
+
* is associated to a resolution.
|
|
117
|
+
* @return {{ type: 'FAIL_RESOLUTIONS', selectorName: string, args: unknown[], errors: Array<Error|unknown> }} Action object.
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
function failResolutions(selectorName, args, errors) {
|
|
122
|
+
return {
|
|
123
|
+
type: 'FAIL_RESOLUTIONS',
|
|
124
|
+
selectorName,
|
|
125
|
+
args,
|
|
126
|
+
errors
|
|
127
|
+
};
|
|
128
|
+
}
|
|
86
129
|
/**
|
|
87
130
|
* Returns an action object used in signalling that we should invalidate the resolution cache.
|
|
88
131
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/actions.js"],"names":["startResolution","selectorName","args","type","finishResolution","startResolutions","finishResolutions","invalidateResolution","invalidateResolutionForStore","invalidateResolutionForStoreSelector"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/actions.js"],"names":["startResolution","selectorName","args","type","finishResolution","failResolution","error","startResolutions","finishResolutions","failResolutions","errors","invalidateResolution","invalidateResolutionForStore","invalidateResolutionForStoreSelector"],"mappings":";;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,eAAT,CAA0BC,YAA1B,EAAwCC,IAAxC,EAA+C;AACrD,SAAO;AACNC,IAAAA,IAAI,EAAE,kBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASE,gBAAT,CAA2BH,YAA3B,EAAyCC,IAAzC,EAAgD;AACtD,SAAO;AACNC,IAAAA,IAAI,EAAE,mBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,cAAT,CAAyBJ,YAAzB,EAAuCC,IAAvC,EAA6CI,KAA7C,EAAqD;AAC3D,SAAO;AACNH,IAAAA,IAAI,EAAE,iBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA,IAHM;AAINI,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,gBAAT,CAA2BN,YAA3B,EAAyCC,IAAzC,EAAgD;AACtD,SAAO;AACNC,IAAAA,IAAI,EAAE,mBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASM,iBAAT,CAA4BP,YAA5B,EAA0CC,IAA1C,EAAiD;AACvD,SAAO;AACNC,IAAAA,IAAI,EAAE,oBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASO,eAAT,CAA0BR,YAA1B,EAAwCC,IAAxC,EAA8CQ,MAA9C,EAAuD;AAC7D,SAAO;AACNP,IAAAA,IAAI,EAAE,kBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA,IAHM;AAINQ,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,oBAAT,CAA+BV,YAA/B,EAA6CC,IAA7C,EAAoD;AAC1D,SAAO;AACNC,IAAAA,IAAI,EAAE,uBADA;AAENF,IAAAA,YAFM;AAGNC,IAAAA;AAHM,GAAP;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASU,4BAAT,GAAwC;AAC9C,SAAO;AACNT,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASU,oCAAT,CAA+CZ,YAA/C,EAA8D;AACpE,SAAO;AACNE,IAAAA,IAAI,EAAE,0CADA;AAENF,IAAAA;AAFM,GAAP;AAIA","sourcesContent":["/**\n * Returns an action object used in signalling that selector resolution has\n * started.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'START_RESOLUTION', selectorName: string, args: unknown[] }} Action object.\n */\nexport function startResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'START_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that selector resolution has\n * completed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'FINISH_RESOLUTION', selectorName: string, args: unknown[] }} Action object.\n */\nexport function finishResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'FINISH_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that selector resolution has\n * failed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n * @param {Error|unknown} error The error that caused the failure.\n *\n * @return {{ type: 'FAIL_RESOLUTION', selectorName: string, args: unknown[], error: Error|unknown }} Action object.\n */\nexport function failResolution( selectorName, args, error ) {\n\treturn {\n\t\ttype: 'FAIL_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t\terror,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a batch of selector resolutions has\n * started.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item\n * is associated to a resolution.\n *\n * @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.\n */\nexport function startResolutions( selectorName, args ) {\n\treturn {\n\t\ttype: 'START_RESOLUTIONS',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a batch of selector resolutions has\n * completed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[][]} args Array of arguments to associate for uniqueness, each item\n * is associated to a resolution.\n *\n * @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.\n */\nexport function finishResolutions( selectorName, args ) {\n\treturn {\n\t\ttype: 'FINISH_RESOLUTIONS',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that a batch of selector resolutions has\n * completed and at least one of them has failed.\n *\n * @param {string} selectorName Name of selector for which resolver triggered.\n * @param {unknown[]} args Array of arguments to associate for uniqueness, each item\n * is associated to a resolution.\n * @param {(Error|unknown)[]} errors Array of errors to associate for uniqueness, each item\n * is associated to a resolution.\n * @return {{ type: 'FAIL_RESOLUTIONS', selectorName: string, args: unknown[], errors: Array<Error|unknown> }} Action object.\n */\nexport function failResolutions( selectorName, args, errors ) {\n\treturn {\n\t\ttype: 'FAIL_RESOLUTIONS',\n\t\tselectorName,\n\t\targs,\n\t\terrors,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that we should invalidate the resolution cache.\n *\n * @param {string} selectorName Name of selector for which resolver should be invalidated.\n * @param {unknown[]} args Arguments to associate for uniqueness.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION', selectorName: string, args: any[] }} Action object.\n */\nexport function invalidateResolution( selectorName, args ) {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION',\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the resolution\n * should be invalidated.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE' }} Action object.\n */\nexport function invalidateResolutionForStore() {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION_FOR_STORE',\n\t};\n}\n\n/**\n * Returns an action object used in signalling that the resolution cache for a\n * given selectorName should be invalidated.\n *\n * @param {string} selectorName Name of selector for which all resolvers should\n * be invalidated.\n *\n * @return {{ type: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR', selectorName: string }} Action object.\n */\nexport function invalidateResolutionForStoreSelector( selectorName ) {\n\treturn {\n\t\ttype: 'INVALIDATE_RESOLUTION_FOR_STORE_SELECTOR',\n\t\tselectorName,\n\t};\n}\n"]}
|
|
@@ -33,31 +33,82 @@ const subKeysIsResolved = (0, _utils.onSubKey)('selectorName')(function () {
|
|
|
33
33
|
|
|
34
34
|
switch (action.type) {
|
|
35
35
|
case 'START_RESOLUTION':
|
|
36
|
+
{
|
|
37
|
+
const nextState = new _equivalentKeyMap.default(state);
|
|
38
|
+
nextState.set((0, _utils.selectorArgsToStateKey)(action.args), {
|
|
39
|
+
status: 'resolving'
|
|
40
|
+
});
|
|
41
|
+
return nextState;
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
case 'FINISH_RESOLUTION':
|
|
37
45
|
{
|
|
38
|
-
const isStarting = action.type === 'START_RESOLUTION';
|
|
39
46
|
const nextState = new _equivalentKeyMap.default(state);
|
|
40
|
-
nextState.set(action.args,
|
|
47
|
+
nextState.set((0, _utils.selectorArgsToStateKey)(action.args), {
|
|
48
|
+
status: 'finished'
|
|
49
|
+
});
|
|
50
|
+
return nextState;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
case 'FAIL_RESOLUTION':
|
|
54
|
+
{
|
|
55
|
+
const nextState = new _equivalentKeyMap.default(state);
|
|
56
|
+
nextState.set((0, _utils.selectorArgsToStateKey)(action.args), {
|
|
57
|
+
status: 'error',
|
|
58
|
+
error: action.error
|
|
59
|
+
});
|
|
41
60
|
return nextState;
|
|
42
61
|
}
|
|
43
62
|
|
|
44
63
|
case 'START_RESOLUTIONS':
|
|
64
|
+
{
|
|
65
|
+
const nextState = new _equivalentKeyMap.default(state);
|
|
66
|
+
|
|
67
|
+
for (const resolutionArgs of action.args) {
|
|
68
|
+
nextState.set((0, _utils.selectorArgsToStateKey)(resolutionArgs), {
|
|
69
|
+
status: 'resolving'
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return nextState;
|
|
74
|
+
}
|
|
75
|
+
|
|
45
76
|
case 'FINISH_RESOLUTIONS':
|
|
46
77
|
{
|
|
47
|
-
const isStarting = action.type === 'START_RESOLUTIONS';
|
|
48
78
|
const nextState = new _equivalentKeyMap.default(state);
|
|
49
79
|
|
|
50
80
|
for (const resolutionArgs of action.args) {
|
|
51
|
-
nextState.set(resolutionArgs,
|
|
81
|
+
nextState.set((0, _utils.selectorArgsToStateKey)(resolutionArgs), {
|
|
82
|
+
status: 'finished'
|
|
83
|
+
});
|
|
52
84
|
}
|
|
53
85
|
|
|
54
86
|
return nextState;
|
|
55
87
|
}
|
|
56
88
|
|
|
89
|
+
case 'FAIL_RESOLUTIONS':
|
|
90
|
+
{
|
|
91
|
+
const nextState = new _equivalentKeyMap.default(state);
|
|
92
|
+
action.args.forEach((resolutionArgs, idx) => {
|
|
93
|
+
const resolutionState = {
|
|
94
|
+
status: 'error',
|
|
95
|
+
error: undefined
|
|
96
|
+
};
|
|
97
|
+
const error = action.errors[idx];
|
|
98
|
+
|
|
99
|
+
if (error) {
|
|
100
|
+
resolutionState.error = error;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
nextState.set((0, _utils.selectorArgsToStateKey)(resolutionArgs), resolutionState);
|
|
104
|
+
});
|
|
105
|
+
return nextState;
|
|
106
|
+
}
|
|
107
|
+
|
|
57
108
|
case 'INVALIDATE_RESOLUTION':
|
|
58
109
|
{
|
|
59
110
|
const nextState = new _equivalentKeyMap.default(state);
|
|
60
|
-
nextState.delete(action.args);
|
|
111
|
+
nextState.delete((0, _utils.selectorArgsToStateKey)(action.args));
|
|
61
112
|
return nextState;
|
|
62
113
|
}
|
|
63
114
|
}
|
|
@@ -88,8 +139,10 @@ const isResolved = function () {
|
|
|
88
139
|
|
|
89
140
|
case 'START_RESOLUTION':
|
|
90
141
|
case 'FINISH_RESOLUTION':
|
|
142
|
+
case 'FAIL_RESOLUTION':
|
|
91
143
|
case 'START_RESOLUTIONS':
|
|
92
144
|
case 'FINISH_RESOLUTIONS':
|
|
145
|
+
case 'FAIL_RESOLUTIONS':
|
|
93
146
|
case 'INVALIDATE_RESOLUTION':
|
|
94
147
|
return subKeysIsResolved(state, action);
|
|
95
148
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/reducer.ts"],"names":["subKeysIsResolved","state","EquivalentKeyMap","action","type","
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/reducer.ts"],"names":["subKeysIsResolved","state","EquivalentKeyMap","action","type","nextState","set","args","status","error","resolutionArgs","forEach","idx","resolutionState","undefined","errors","delete","isResolved","selectorName"],"mappings":";;;;;;;;;AAGA;;AACA;;AAMA;;AAVA;AACA;AACA;;AAKA;AACA;AACA;;AAwBA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAA6D,GAAG,qBAGnE,cAHmE,EAGjD,YAAsD;AAAA,MAApD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,CAAEE,MAAM,CAACe,YAAT,CAAZ,IACJ,kBAAMjB,KAAN,EAAa,CAAEE,MAAM,CAACe,YAAT,CAAb,CADI,GAEJjB,KAFH;;AAGD,SAAK,kBAAL;AACA,SAAK,mBAAL;AACA,SAAK,iBAAL;AACA,SAAK,mBAAL;AACA,SAAK,oBAAL;AACA,SAAK,kBAAL;AACA,SAAK,uBAAL;AACC,aAAOD,iBAAiB,CAAEC,KAAF,EAASE,MAAT,CAAxB;AAdF;;AAgBA,SAAOF,KAAP;AACA,CAlBD;;eAoBegB,U","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, has } from 'lodash';\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\treturn has( state, [ action.selectorName ] )\n\t\t\t\t? omit( state, [ action.selectorName ] )\n\t\t\t\t: state;\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,86 +5,153 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getCachedResolvers = getCachedResolvers;
|
|
7
7
|
exports.getIsResolving = getIsResolving;
|
|
8
|
+
exports.getResolutionError = getResolutionError;
|
|
9
|
+
exports.getResolutionState = getResolutionState;
|
|
8
10
|
exports.hasFinishedResolution = hasFinishedResolution;
|
|
11
|
+
exports.hasResolutionFailed = hasResolutionFailed;
|
|
9
12
|
exports.hasStartedResolution = hasStartedResolution;
|
|
10
13
|
exports.isResolving = isResolving;
|
|
11
14
|
|
|
12
15
|
var _lodash = require("lodash");
|
|
13
16
|
|
|
17
|
+
var _utils = require("./utils");
|
|
18
|
+
|
|
14
19
|
/**
|
|
15
20
|
* External dependencies
|
|
16
21
|
*/
|
|
17
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Internal dependencies
|
|
25
|
+
*/
|
|
26
|
+
|
|
18
27
|
/** @typedef {Record<string, import('./reducer').State>} State */
|
|
19
28
|
|
|
29
|
+
/** @typedef {import('./reducer').StateValue} StateValue */
|
|
30
|
+
|
|
31
|
+
/** @typedef {import('./reducer').Status} Status */
|
|
32
|
+
|
|
20
33
|
/**
|
|
21
|
-
* Returns the raw
|
|
34
|
+
* Returns the raw resolution state value for a given selector name,
|
|
22
35
|
* and arguments set. May be undefined if the selector has never been resolved
|
|
23
36
|
* or not resolved for the given set of arguments, otherwise true or false for
|
|
24
37
|
* resolution started and completed respectively.
|
|
25
38
|
*
|
|
26
|
-
* @param {State}
|
|
27
|
-
* @param {string}
|
|
28
|
-
* @param {unknown[]} args Arguments passed to selector.
|
|
39
|
+
* @param {State} state Data state.
|
|
40
|
+
* @param {string} selectorName Selector name.
|
|
41
|
+
* @param {unknown[]?} args Arguments passed to selector.
|
|
29
42
|
*
|
|
30
|
-
* @return {
|
|
43
|
+
* @return {StateValue|undefined} isResolving value.
|
|
31
44
|
*/
|
|
32
|
-
function
|
|
45
|
+
function getResolutionState(state, selectorName, args) {
|
|
33
46
|
const map = (0, _lodash.get)(state, [selectorName]);
|
|
34
47
|
|
|
35
48
|
if (!map) {
|
|
36
|
-
return
|
|
49
|
+
return;
|
|
37
50
|
}
|
|
38
51
|
|
|
39
|
-
return map.get(args);
|
|
52
|
+
return map.get((0, _utils.selectorArgsToStateKey)(args));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the raw `isResolving` value for a given selector name,
|
|
56
|
+
* and arguments set. May be undefined if the selector has never been resolved
|
|
57
|
+
* or not resolved for the given set of arguments, otherwise true or false for
|
|
58
|
+
* resolution started and completed respectively.
|
|
59
|
+
*
|
|
60
|
+
* @param {State} state Data state.
|
|
61
|
+
* @param {string} selectorName Selector name.
|
|
62
|
+
* @param {unknown[]?} args Arguments passed to selector.
|
|
63
|
+
*
|
|
64
|
+
* @return {boolean | undefined} isResolving value.
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
function getIsResolving(state, selectorName, args) {
|
|
69
|
+
const resolutionState = getResolutionState(state, selectorName, args);
|
|
70
|
+
return resolutionState && resolutionState.status === 'resolving';
|
|
40
71
|
}
|
|
41
72
|
/**
|
|
42
73
|
* Returns true if resolution has already been triggered for a given
|
|
43
74
|
* selector name, and arguments set.
|
|
44
75
|
*
|
|
45
|
-
* @param {State}
|
|
46
|
-
* @param {string}
|
|
47
|
-
* @param {unknown[]}
|
|
76
|
+
* @param {State} state Data state.
|
|
77
|
+
* @param {string} selectorName Selector name.
|
|
78
|
+
* @param {unknown[]?} args Arguments passed to selector.
|
|
48
79
|
*
|
|
49
80
|
* @return {boolean} Whether resolution has been triggered.
|
|
50
81
|
*/
|
|
51
82
|
|
|
52
83
|
|
|
53
|
-
function hasStartedResolution(state, selectorName) {
|
|
54
|
-
|
|
55
|
-
return getIsResolving(state, selectorName, args) !== undefined;
|
|
84
|
+
function hasStartedResolution(state, selectorName, args) {
|
|
85
|
+
return getResolutionState(state, selectorName, args) !== undefined;
|
|
56
86
|
}
|
|
57
87
|
/**
|
|
58
88
|
* Returns true if resolution has completed for a given selector
|
|
59
89
|
* name, and arguments set.
|
|
60
90
|
*
|
|
61
|
-
* @param {State}
|
|
62
|
-
* @param {string}
|
|
63
|
-
* @param {unknown[]}
|
|
91
|
+
* @param {State} state Data state.
|
|
92
|
+
* @param {string} selectorName Selector name.
|
|
93
|
+
* @param {unknown[]?} args Arguments passed to selector.
|
|
64
94
|
*
|
|
65
95
|
* @return {boolean} Whether resolution has completed.
|
|
66
96
|
*/
|
|
67
97
|
|
|
68
98
|
|
|
69
|
-
function hasFinishedResolution(state, selectorName) {
|
|
70
|
-
|
|
71
|
-
|
|
99
|
+
function hasFinishedResolution(state, selectorName, args) {
|
|
100
|
+
var _getResolutionState;
|
|
101
|
+
|
|
102
|
+
const status = (_getResolutionState = getResolutionState(state, selectorName, args)) === null || _getResolutionState === void 0 ? void 0 : _getResolutionState.status;
|
|
103
|
+
return status === 'finished' || status === 'error';
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Returns true if resolution has failed for a given selector
|
|
107
|
+
* name, and arguments set.
|
|
108
|
+
*
|
|
109
|
+
* @param {State} state Data state.
|
|
110
|
+
* @param {string} selectorName Selector name.
|
|
111
|
+
* @param {unknown[]?} args Arguments passed to selector.
|
|
112
|
+
*
|
|
113
|
+
* @return {boolean} Has resolution failed
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
function hasResolutionFailed(state, selectorName, args) {
|
|
118
|
+
var _getResolutionState2;
|
|
119
|
+
|
|
120
|
+
return ((_getResolutionState2 = getResolutionState(state, selectorName, args)) === null || _getResolutionState2 === void 0 ? void 0 : _getResolutionState2.status) === 'error';
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns the resolution error for a given selector name, and arguments set.
|
|
124
|
+
* Note it may be of an Error type, but may also be null, undefined, or anything else
|
|
125
|
+
* that can be `throw`-n.
|
|
126
|
+
*
|
|
127
|
+
* @param {State} state Data state.
|
|
128
|
+
* @param {string} selectorName Selector name.
|
|
129
|
+
* @param {unknown[]?} args Arguments passed to selector.
|
|
130
|
+
*
|
|
131
|
+
* @return {Error|unknown} Last resolution error
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
function getResolutionError(state, selectorName, args) {
|
|
136
|
+
const resolutionState = getResolutionState(state, selectorName, args);
|
|
137
|
+
return (resolutionState === null || resolutionState === void 0 ? void 0 : resolutionState.status) === 'error' ? resolutionState.error : null;
|
|
72
138
|
}
|
|
73
139
|
/**
|
|
74
140
|
* Returns true if resolution has been triggered but has not yet completed for
|
|
75
141
|
* a given selector name, and arguments set.
|
|
76
142
|
*
|
|
77
|
-
* @param {State}
|
|
78
|
-
* @param {string}
|
|
79
|
-
* @param {unknown[]}
|
|
143
|
+
* @param {State} state Data state.
|
|
144
|
+
* @param {string} selectorName Selector name.
|
|
145
|
+
* @param {unknown[]?} args Arguments passed to selector.
|
|
80
146
|
*
|
|
81
147
|
* @return {boolean} Whether resolution is in progress.
|
|
82
148
|
*/
|
|
83
149
|
|
|
84
150
|
|
|
85
|
-
function isResolving(state, selectorName) {
|
|
86
|
-
|
|
87
|
-
|
|
151
|
+
function isResolving(state, selectorName, args) {
|
|
152
|
+
var _getResolutionState3;
|
|
153
|
+
|
|
154
|
+
return ((_getResolutionState3 = getResolutionState(state, selectorName, args)) === null || _getResolutionState3 === void 0 ? void 0 : _getResolutionState3.status) === 'resolving';
|
|
88
155
|
}
|
|
89
156
|
/**
|
|
90
157
|
* Returns the list of the cached resolvers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/selectors.js"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/selectors.js"],"names":["getResolutionState","state","selectorName","args","map","get","getIsResolving","resolutionState","status","hasStartedResolution","undefined","hasFinishedResolution","hasResolutionFailed","getResolutionError","error","isResolving","getCachedResolvers"],"mappings":";;;;;;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,kBAAT,CAA6BC,KAA7B,EAAoCC,YAApC,EAAkDC,IAAlD,EAAyD;AAC/D,QAAMC,GAAG,GAAG,iBAAKH,KAAL,EAAY,CAAEC,YAAF,CAAZ,CAAZ;;AACA,MAAK,CAAEE,GAAP,EAAa;AACZ;AACA;;AAED,SAAOA,GAAG,CAACC,GAAJ,CAAS,mCAAwBF,I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AASC,YAAT,EAAuBC,IAAvB,CAA1C;AACA,SAAO,CAAAI,eAAe,SAAf,IAAAA,eAAe,WAAf,YAAAA,eAAe,CAAEC,MAAjB,MAA4B,OAA5B,GAAsCD,eAAe,CAACO,KAAtD,GAA8D,IAArE;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,WAAT,CAAsBd,KAAtB,EAA6BC,YAA7B,EAA2CC,IAA3C,EAAkD;AAAA;;AACxD,SACC,yBAAAH,kBAAkB,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAAlB,8EAAiDK,MAAjD,MAA4D,WAD7D;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASQ,kBAAT,CAA6Bf,KAA7B,EAAqC;AAC3C,SAAOA,KAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\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 = get( state, [ selectorName ] );\n\tif ( ! map ) {\n\t\treturn;\n\t}\n\n\treturn map.get( selectorArgsToStateKey( args ) );\n}\n\n/**\n * Returns the raw `isResolving` 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 {boolean | undefined} isResolving value.\n */\nexport function getIsResolving( state, selectorName, args ) {\n\tconst resolutionState = getResolutionState( state, selectorName, args );\n\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"]}
|
|
@@ -4,29 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.onSubKey = void 0;
|
|
7
|
+
exports.selectorArgsToStateKey = selectorArgsToStateKey;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* External dependencies
|
|
11
|
+
*/
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* Higher-order reducer creator which creates a combined reducer object, keyed
|
|
10
15
|
* by a property on the action object.
|
|
11
16
|
*
|
|
12
|
-
* @
|
|
13
|
-
* @
|
|
14
|
-
*
|
|
15
|
-
* @param {string} actionProperty Action property by which to key object.
|
|
16
|
-
*
|
|
17
|
-
* @return {(reducer: import('redux').Reducer<TState, TAction>) => import('redux').Reducer<Record<string, TState>, TAction>} Higher-order reducer.
|
|
17
|
+
* @param actionProperty Action property by which to key object.
|
|
18
|
+
* @return Higher-order reducer.
|
|
18
19
|
*/
|
|
19
20
|
const onSubKey = actionProperty => reducer => function () {
|
|
20
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] :
|
|
21
|
-
/** @type {Record<string, TState>} */
|
|
22
|
-
{};
|
|
21
|
+
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
23
22
|
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
24
23
|
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
|
25
24
|
// where reducer is scoped by action shape.
|
|
26
|
-
|
|
27
|
-
/** @type {keyof state} */
|
|
28
|
-
|
|
29
|
-
/* eslint-enable jsdoc/no-undefined-types */
|
|
30
25
|
const key = action[actionProperty];
|
|
31
26
|
|
|
32
27
|
if (key === undefined) {
|
|
@@ -45,6 +40,29 @@ const onSubKey = actionProperty => reducer => function () {
|
|
|
45
40
|
[key]: nextKeyState
|
|
46
41
|
};
|
|
47
42
|
};
|
|
43
|
+
/**
|
|
44
|
+
* Normalize selector argument array by defaulting `undefined` value to an empty array
|
|
45
|
+
* and removing trailing `undefined` values.
|
|
46
|
+
*
|
|
47
|
+
* @param args Selector argument array
|
|
48
|
+
* @return Normalized state key array
|
|
49
|
+
*/
|
|
50
|
+
|
|
48
51
|
|
|
49
52
|
exports.onSubKey = onSubKey;
|
|
53
|
+
|
|
54
|
+
function selectorArgsToStateKey(args) {
|
|
55
|
+
if (args === undefined || args === null) {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const len = args.length;
|
|
60
|
+
let idx = len;
|
|
61
|
+
|
|
62
|
+
while (idx > 0 && args[idx - 1] === undefined) {
|
|
63
|
+
idx--;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return idx === len ? args : args.slice(0, idx);
|
|
67
|
+
}
|
|
50
68
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/utils.
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/utils.ts"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState","selectorArgsToStateKey","args","len","length","idx","slice"],"mappings":";;;;;;;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GACpBC,cADuB,IAGvBC,OADI,IAE8C,YAG9C;AAAA,MAFJC,KAEI,uEAF8B,EAE9B;AAAA,MADJC,MACI;AACJ;AACA;AACA,QAAMC,GAAG,GAAGD,MAAM,CAAEH,cAAF,CAAlB;;AACA,MAAKI,GAAG,KAAKC,SAAb,EAAyB;AACxB,WAAOH,KAAP;AACA,GANG,CAQJ;AACA;;;AACA,QAAMI,YAAY,GAAGL,OAAO,CAAEC,KAAK,CAAEE,GAAF,CAAP,EAAgBD,MAAhB,CAA5B;;AACA,MAAKG,YAAY,KAAKJ,KAAK,CAAEE,GAAF,CAA3B,EAAqC;AACpC,WAAOF,KAAP;AACA;;AAED,SAAO,EACN,GAAGA,KADG;AAEN,KAAEE,GAAF,GAASE;AAFH,GAAP;AAIA,CA1BM;AA4BP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASC,sBAAT,CAAiCC,IAAjC,EAAsE;AAC5E,MAAKA,IAAI,KAAKH,SAAT,IAAsBG,IAAI,KAAK,IAApC,EAA2C;AAC1C,WAAO,EAAP;AACA;;AAED,QAAMC,GAAG,GAAGD,IAAI,CAACE,MAAjB;AACA,MAAIC,GAAG,GAAGF,GAAV;;AACA,SAAQE,GAAG,GAAG,CAAN,IAAWH,IAAI,CAAEG,GAAG,GAAG,CAAR,CAAJ,KAAoBN,SAAvC,EAAmD;AAClDM,IAAAA,GAAG;AACH;;AACD,SAAOA,GAAG,KAAKF,GAAR,GAAcD,IAAd,GAAqBA,IAAI,CAACI,KAAL,CAAY,CAAZ,EAAeD,GAAf,CAA5B;AACA","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 = < TState extends unknown, TAction extends AnyAction >(\n\tactionProperty: string\n) => (\n\treducer: Reducer< TState, TAction >\n): Reducer< Record< string, TState >, TAction > => (\n\tstate: Record< string, TState > = {},\n\taction\n) => {\n\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t// where reducer is scoped by action shape.\n\tconst key = action[ actionProperty ];\n\tif ( key === undefined ) {\n\t\treturn state;\n\t}\n\n\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t// reducer which returns undefined on a key which is not yet tracked.\n\tconst nextKeyState = reducer( state[ key ], action );\n\tif ( nextKeyState === state[ key ] ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\t...state,\n\t\t[ key ]: nextKeyState,\n\t};\n};\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"]}
|
package/build/registry.js
CHANGED
|
@@ -172,7 +172,6 @@ function createRegistry() {
|
|
|
172
172
|
} //
|
|
173
173
|
// Deprecated
|
|
174
174
|
// TODO: Remove this after `use()` is removed.
|
|
175
|
-
//
|
|
176
175
|
|
|
177
176
|
|
|
178
177
|
function withPlugins(attributes) {
|
|
@@ -320,7 +319,6 @@ function createRegistry() {
|
|
|
320
319
|
}; //
|
|
321
320
|
// TODO:
|
|
322
321
|
// This function will be deprecated as soon as it is no longer internally referenced.
|
|
323
|
-
//
|
|
324
322
|
|
|
325
323
|
function use(plugin, options) {
|
|
326
324
|
if (!plugin) {
|