@wordpress/data 9.3.0 → 9.5.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 +4 -0
- package/build/components/use-dispatch/use-dispatch-with-map.js +2 -6
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build/components/use-select/index.js +1 -1
- package/build/components/use-select/index.js.map +1 -1
- package/build/controls.js +18 -37
- package/build/controls.js.map +1 -1
- package/build/factory.js +1 -3
- package/build/factory.js.map +1 -1
- package/build/redux-store/index.js +100 -191
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/reducer.js +2 -8
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +13 -15
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +1 -3
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/registry.js +8 -18
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +3 -6
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/store/index.js +2 -10
- package/build/store/index.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +2 -6
- package/build-module/components/use-dispatch/use-dispatch-with-map.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/controls.js +18 -37
- package/build-module/controls.js.map +1 -1
- package/build-module/factory.js +1 -3
- package/build-module/factory.js.map +1 -1
- package/build-module/redux-store/index.js +100 -191
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +2 -8
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +13 -15
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +1 -3
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/registry.js +8 -18
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +3 -6
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/store/index.js +2 -10
- package/build-module/store/index.js.map +1 -1
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/redux-store/index.js +129 -206
- package/src/redux-store/metadata/selectors.js +9 -2
- package/src/test/privateAPIs.js +31 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -92,9 +92,7 @@ function hasStartedResolution(state, selectorName, args) {
|
|
|
92
92
|
|
|
93
93
|
|
|
94
94
|
function hasFinishedResolution(state, selectorName, args) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const status = (_getResolutionState = getResolutionState(state, selectorName, args)) === null || _getResolutionState === void 0 ? void 0 : _getResolutionState.status;
|
|
95
|
+
const status = getResolutionState(state, selectorName, args)?.status;
|
|
98
96
|
return status === 'finished' || status === 'error';
|
|
99
97
|
}
|
|
100
98
|
/**
|
|
@@ -110,9 +108,7 @@ function hasFinishedResolution(state, selectorName, args) {
|
|
|
110
108
|
|
|
111
109
|
|
|
112
110
|
function hasResolutionFailed(state, selectorName, args) {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return ((_getResolutionState2 = getResolutionState(state, selectorName, args)) === null || _getResolutionState2 === void 0 ? void 0 : _getResolutionState2.status) === 'error';
|
|
111
|
+
return getResolutionState(state, selectorName, args)?.status === 'error';
|
|
116
112
|
}
|
|
117
113
|
/**
|
|
118
114
|
* Returns the resolution error for a given selector name, and arguments set.
|
|
@@ -129,7 +125,7 @@ function hasResolutionFailed(state, selectorName, args) {
|
|
|
129
125
|
|
|
130
126
|
function getResolutionError(state, selectorName, args) {
|
|
131
127
|
const resolutionState = getResolutionState(state, selectorName, args);
|
|
132
|
-
return
|
|
128
|
+
return resolutionState?.status === 'error' ? resolutionState.error : null;
|
|
133
129
|
}
|
|
134
130
|
/**
|
|
135
131
|
* Returns true if resolution has been triggered but has not yet completed for
|
|
@@ -144,9 +140,7 @@ function getResolutionError(state, selectorName, args) {
|
|
|
144
140
|
|
|
145
141
|
|
|
146
142
|
function isResolving(state, selectorName, args) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return ((_getResolutionState3 = getResolutionState(state, selectorName, args)) === null || _getResolutionState3 === void 0 ? void 0 : _getResolutionState3.status) === 'resolving';
|
|
143
|
+
return getResolutionState(state, selectorName, args)?.status === 'resolving';
|
|
150
144
|
}
|
|
151
145
|
/**
|
|
152
146
|
* Returns the list of the cached resolvers.
|
|
@@ -170,10 +164,14 @@ function getCachedResolvers(state) {
|
|
|
170
164
|
|
|
171
165
|
|
|
172
166
|
function hasResolvingSelectors(state) {
|
|
173
|
-
return
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
167
|
+
return Object.values(state).some(selectorState =>
|
|
168
|
+
/**
|
|
169
|
+
* This uses the internal `_map` property of `EquivalentKeyMap` for
|
|
170
|
+
* optimization purposes, since the `EquivalentKeyMap` implementation
|
|
171
|
+
* does not support a `.values()` implementation.
|
|
172
|
+
*
|
|
173
|
+
* @see https://github.com/aduth/equivalent-key-map
|
|
174
|
+
*/
|
|
175
|
+
Array.from(selectorState._map.values()).some(resolution => resolution[1]?.status === 'resolving'));
|
|
178
176
|
}
|
|
179
177
|
//# sourceMappingURL=selectors.js.map
|
|
@@ -1 +1 @@
|
|
|
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","hasResolvingSelectors","Object","values","some","selectorState","_map","resolution"],"mappings":";;;;;;;;;;;;;;;AAGA;;AAHA;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,GAAGH,KAAK,CAAEC,YAAF,CAAjB;;AACA,MAAK,CAAEE,GAAP,EAAa;AACZ;AACA;;AAED,SAAOA,GAAG,CAACC,GAAJ,CAAS,mCAAwBF,IAAxB,CAAT,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,cAAT,CAAyBL,KAAzB,EAAgCC,YAAhC,EAA8CC,IAA9C,EAAqD;AAC3D,QAAMI,eAAe,GAAGP,kBAAkB,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAA1C;AAEA,SAAOI,eAAe,IAAIA,eAAe,CAACC,MAAhB,KAA2B,WAArD;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,oBAAT,CAA+BR,KAA/B,EAAsCC,YAAtC,EAAoDC,IAApD,EAA2D;AACjE,SAAOH,kBAAkB,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAAlB,KAAoDO,SAA3D;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,qBAAT,CAAgCV,KAAhC,EAAuCC,YAAvC,EAAqDC,IAArD,EAA4D;
|
|
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","hasResolvingSelectors","Object","values","some","selectorState","Array","from","_map","resolution"],"mappings":";;;;;;;;;;;;;;;AAGA;;AAHA;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,IA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;;;AACO,SAASK,kBAAT,CAA6BZ,KAA7B,EAAoCC,YAApC,EAAkDC,IAAlD,EAAyD;AAC/D,QAAMI,eAAe,GAAGP,kBAAkB,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAA1C;AACA,SAAOI,eAAe,EAAEC,MAAjB,KAA4B,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;AACxD,SACCH,kBAAkB,CAAEC,KAAF,EAASC,YAAT,EAAuBC,IAAvB,CAAlB,EAAiDK,MAAjD,KAA4D,WAD7D;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASQ,kBAAT,CAA6Bf,KAA7B,EAAqC;AAC3C,SAAOA,KAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASgB,qBAAT,CAAgChB,KAAhC,EAAwC;AAC9C,SAAOiB,MAAM,CAACC,MAAP,CAAelB,KAAf,EAAuBmB,IAAvB,CAA+BC,aAAF;AACnC;AACF;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA,KAAK,CAACC,IAAN,CAAYF,aAAa,CAACG,IAAd,CAAmBL,MAAnB,EAAZ,EAA0CC,IAA1C,CACGK,UAAF,IAAkBA,UAAU,CAAE,CAAF,CAAV,EAAiBjB,MAAjB,KAA4B,WAD/C,CARM,CAAP;AAYA","sourcesContent":["/**\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 = 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\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"]}
|
|
@@ -17,9 +17,7 @@ exports.selectorArgsToStateKey = selectorArgsToStateKey;
|
|
|
17
17
|
* @param actionProperty Action property by which to key object.
|
|
18
18
|
* @return Higher-order reducer.
|
|
19
19
|
*/
|
|
20
|
-
const onSubKey = actionProperty => reducer =>
|
|
21
|
-
let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
22
|
-
let action = arguments.length > 1 ? arguments[1] : undefined;
|
|
20
|
+
const onSubKey = actionProperty => reducer => (state = {}, action) => {
|
|
23
21
|
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
|
24
22
|
// where reducer is scoped by action shape.
|
|
25
23
|
const key = action[actionProperty];
|
|
@@ -1 +1 @@
|
|
|
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,GAEnBC,cADD,IAICC,OADD,IAGA,
|
|
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,GAEnBC,cADD,IAICC,OADD,IAGA,CAAEC,KAA+B,GAAG,EAApC,EAAwCC,MAAxC,KAAoD;AACnD;AACA;AACA,QAAMC,GAAG,GAAGD,MAAM,CAAEH,cAAF,CAAlB;;AACA,MAAKI,GAAG,KAAKC,SAAb,EAAyB;AACxB,WAAOH,KAAP;AACA,GANkD,CAQnD;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,CA1BK;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 =\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"]}
|
package/build/registry.js
CHANGED
|
@@ -66,9 +66,7 @@ function getStoreName(storeNameOrDescriptor) {
|
|
|
66
66
|
*/
|
|
67
67
|
|
|
68
68
|
|
|
69
|
-
function createRegistry() {
|
|
70
|
-
let storeConfigs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
-
let parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
69
|
+
function createRegistry(storeConfigs = {}, parent = null) {
|
|
72
70
|
const stores = {};
|
|
73
71
|
const emitter = (0, _emitter.createEmitter)();
|
|
74
72
|
let listeningStores = null;
|
|
@@ -125,17 +123,15 @@ function createRegistry() {
|
|
|
125
123
|
|
|
126
124
|
|
|
127
125
|
function select(storeNameOrDescriptor) {
|
|
128
|
-
var _listeningStores;
|
|
129
|
-
|
|
130
126
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
131
|
-
|
|
127
|
+
listeningStores?.add(storeName);
|
|
132
128
|
const store = stores[storeName];
|
|
133
129
|
|
|
134
130
|
if (store) {
|
|
135
131
|
return store.getSelectors();
|
|
136
132
|
}
|
|
137
133
|
|
|
138
|
-
return parent
|
|
134
|
+
return parent?.select(storeName);
|
|
139
135
|
}
|
|
140
136
|
|
|
141
137
|
function __unstableMarkListeningStores(callback, ref) {
|
|
@@ -162,10 +158,8 @@ function createRegistry() {
|
|
|
162
158
|
|
|
163
159
|
|
|
164
160
|
function resolveSelect(storeNameOrDescriptor) {
|
|
165
|
-
var _listeningStores2;
|
|
166
|
-
|
|
167
161
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
168
|
-
|
|
162
|
+
listeningStores?.add(storeName);
|
|
169
163
|
const store = stores[storeName];
|
|
170
164
|
|
|
171
165
|
if (store) {
|
|
@@ -188,10 +182,8 @@ function createRegistry() {
|
|
|
188
182
|
|
|
189
183
|
|
|
190
184
|
function suspendSelect(storeNameOrDescriptor) {
|
|
191
|
-
var _listeningStores3;
|
|
192
|
-
|
|
193
185
|
const storeName = getStoreName(storeNameOrDescriptor);
|
|
194
|
-
|
|
186
|
+
listeningStores?.add(storeName);
|
|
195
187
|
const store = stores[storeName];
|
|
196
188
|
|
|
197
189
|
if (store) {
|
|
@@ -225,9 +217,7 @@ function createRegistry() {
|
|
|
225
217
|
|
|
226
218
|
|
|
227
219
|
function withPlugins(attributes) {
|
|
228
|
-
return Object.fromEntries(Object.entries(attributes).map(
|
|
229
|
-
let [key, attribute] = _ref;
|
|
230
|
-
|
|
220
|
+
return Object.fromEntries(Object.entries(attributes).map(([key, attribute]) => {
|
|
231
221
|
if (typeof attribute !== 'function') {
|
|
232
222
|
return [key, attribute];
|
|
233
223
|
}
|
|
@@ -283,8 +273,8 @@ function createRegistry() {
|
|
|
283
273
|
listener();
|
|
284
274
|
});
|
|
285
275
|
return () => {
|
|
286
|
-
unsubscribeFromStore
|
|
287
|
-
unsubscribeFromEmitter
|
|
276
|
+
unsubscribeFromStore?.();
|
|
277
|
+
unsubscribeFromEmitter?.();
|
|
288
278
|
};
|
|
289
279
|
};
|
|
290
280
|
|
package/build/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["getStoreName","storeNameOrDescriptor","name","createRegistry","storeConfigs","parent","stores","emitter","listeningStores","globalListener","emit","subscribe","listener","storeName","store","select","add","getSelectors","__unstableMarkListeningStores","callback","ref","Set","call","current","Array","from","resolveSelect","getResolveSelectors","suspendSelect","getSuspendSelectors","dispatch","getActions","withPlugins","attributes","Object","fromEntries","entries","map","key","attribute","registry","apply","arguments","registerStoreInstance","createStore","console","error","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","registerPrivateActions","privateActionsOf","registerPrivateSelectors","privateSelectorsOf","e","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","batch","pause","values","forEach","resume","namespaces","use","plugin","coreDataStore","config","registryWithPlugins","privateActions","privateSelectors"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,SAASA,YAAT,CAAuBC,qBAAvB,EAA+C;AAC9C,SAAO,OAAOA,qBAAP,KAAiC,QAAjC,GACJA,qBADI,GAEJA,qBAAqB,CAACC,IAFzB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,cAAT,GAA4D;AAAA,MAAnCC,YAAmC,uEAApB,EAAoB;AAAA,MAAhBC,MAAgB,uEAAP,IAAO;AAClE,QAAMC,MAAM,GAAG,EAAf;AACA,QAAMC,OAAO,GAAG,6BAAhB;AACA,MAAIC,eAAe,GAAG,IAAtB;AAEA;AACD;AACA;;AACC,WAASC,cAAT,GAA0B;AACzBF,IAAAA,OAAO,CAACG,IAAR;AACA;AAED;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACC,QAAMC,SAAS,GAAG,CAAEC,QAAF,EAAYX,qBAAZ,KAAuC;AACxD;AACA,QAAK,CAAEA,qBAAP,EAA+B;AAC9B,aAAOM,OAAO,CAACI,SAAR,CAAmBC,QAAnB,CAAP;AACA,KAJuD,CAMxD;;;AACA,UAAMC,SAAS,GAAGb,YAAY,CAAEC,qBAAF,CAA9B;AACA,UAAMa,KAAK,GAAGR,MAAM,CAAEO,SAAF,CAApB;;AACA,QAAKC,KAAL,EAAa;AACZ,aAAOA,KAAK,CAACH,SAAN,CAAiBC,QAAjB,CAAP;AACA,KAXuD,CAaxD;AACA;AACA;AACA;;;AACA,QAAK,CAAEP,MAAP,EAAgB;AACf,aAAOE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AgBhC,YAAhB,CAAhC,EAAiE;AAChEoC,IAAAA,QAAQ,CAACiB,QAAT,CAAmB,yBAAkBvD,IAAlB,EAAwBwE,MAAxB,CAAnB;AACA;;AAED,MAAKrE,MAAL,EAAc;AACbA,IAAAA,MAAM,CAACM,SAAP,CAAkBF,cAAlB;AACA;;AAED,QAAMkE,mBAAmB,GAAG3C,WAAW,CAAEQ,QAAF,CAAvC;AACA,yBAAMmC,mBAAN,EAA2B;AAC1BtB,IAAAA,gBAAgB,EAAInD,IAAF,IAAY;AAC7B,UAAI;AACH,eAAO,yBAAQI,MAAM,CAAEJ,IAAF,CAAN,CAAeY,KAAvB,EAA+B8D,cAAtC;AACA,OAFD,CAEE,OAAQpB,CAAR,EAAY;AACb;AACA;AACA,eAAO,EAAP;AACA;AACD,KATyB;AAU1BD,IAAAA,kBAAkB,EAAIrD,IAAF,IAAY;AAC/B,UAAI;AACH,eAAO,yBAAQI,MAAM,CAAEJ,IAAF,CAAN,CAAeY,KAAvB,EAA+B+D,gBAAtC;AACA,OAFD,CAEE,OAAQrB,CAAR,EAAY;AACb,eAAO,EAAP;AACA;AACD;AAhByB,GAA3B;AAkBA,SAAOmB,mBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\nimport { lock, unlock } from './private-apis';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\nfunction getStoreName( storeNameOrDescriptor ) {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {Object?} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores = null;\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param {Function} listener Listener function.\n\t * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener, storeNameOrDescriptor ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to global `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores( callback, ref ) {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins( attributes ) {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\tfunction () {\n\t\t\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} )\n\t\t);\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param {string} name Store registry name.\n\t * @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, createStore ) {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store = createStore();\n\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param {StoreDescriptor} store Store descriptor.\n\t */\n\tfunction register( store ) {\n\t\tregisterStoreInstance( store.name, () =>\n\t\t\tstore.instantiate( registry )\n\t\t);\n\t}\n\n\tfunction registerGenericStore( name, store ) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, () => store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tfunction registerStore( storeName, options ) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance( storeName, () =>\n\t\t\tcreateReduxStore( storeName, options ).instantiate( registry )\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.resume() );\n\t}\n\n\tlet registry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t};\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin, options ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\tconst registryWithPlugins = withPlugins( registry );\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws an error the store was not locked – this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["getStoreName","storeNameOrDescriptor","name","createRegistry","storeConfigs","parent","stores","emitter","listeningStores","globalListener","emit","subscribe","listener","storeName","store","select","add","getSelectors","__unstableMarkListeningStores","callback","ref","Set","call","current","Array","from","resolveSelect","getResolveSelectors","suspendSelect","getSuspendSelectors","dispatch","getActions","withPlugins","attributes","Object","fromEntries","entries","map","key","attribute","registry","apply","arguments","registerStoreInstance","createStore","console","error","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","registerPrivateActions","privateActionsOf","registerPrivateSelectors","privateSelectorsOf","e","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","batch","pause","values","forEach","resume","namespaces","use","plugin","coreDataStore","config","registryWithPlugins","privateActions","privateSelectors"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAXA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AAEA,SAASA,YAAT,CAAuBC,qBAAvB,EAA+C;AAC9C,SAAO,OAAOA,qBAAP,KAAiC,QAAjC,GACJA,qBADI,GAEJA,qBAAqB,CAACC,IAFzB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,cAAT,CAAyBC,YAAY,GAAG,EAAxC,EAA4CC,MAAM,GAAG,IAArD,EAA4D;AAClE,QAAMC,MAAM,GAAG,EAAf;AACA,QAAMC,OAAO,GAAG,6BAAhB;AACA,MAAIC,eAAe,GAA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5QkE,CA4RlE;AACA;AACA;;AACA,WAASqD,GAAT,CAAcC,MAAd,EAAsBT,OAAtB,EAAgC;AAC/B,QAAK,CAAES,MAAP,EAAgB;AACf;AACA;;AAEDhC,IAAAA,QAAQ,GAAG,EACV,GAAGA,QADO;AAEV,SAAGgC,MAAM,CAAEhC,QAAF,EAAYuB,OAAZ;AAFC,KAAX;AAKA,WAAOvB,QAAP;AACA;;AAEDA,EAAAA,QAAQ,CAACiB,QAAT,CAAmBgB,cAAnB;;AAEA,OAAM,MAAM,CAAEvE,IAAF,EAAQwE,MAAR,CAAZ,IAAgCxC,MAAM,CAACE,OAAP,CAAgBhC,YAAhB,CAAhC,EAAiE;AAChEoC,IAAAA,QAAQ,CAACiB,QAAT,CAAmB,yBAAkBvD,IAAlB,EAAwBwE,MAAxB,CAAnB;AACA;;AAED,MAAKrE,MAAL,EAAc;AACbA,IAAAA,MAAM,CAACM,SAAP,CAAkBF,cAAlB;AACA;;AAED,QAAMkE,mBAAmB,GAAG3C,WAAW,CAAEQ,QAAF,CAAvC;AACA,yBAAMmC,mBAAN,EAA2B;AAC1BtB,IAAAA,gBAAgB,EAAInD,IAAF,IAAY;AAC7B,UAAI;AACH,eAAO,yBAAQI,MAAM,CAAEJ,IAAF,CAAN,CAAeY,KAAvB,EAA+B8D,cAAtC;AACA,OAFD,CAEE,OAAQpB,CAAR,EAAY;AACb;AACA;AACA,eAAO,EAAP;AACA;AACD,KATyB;AAU1BD,IAAAA,kBAAkB,EAAIrD,IAAF,IAAY;AAC/B,UAAI;AACH,eAAO,yBAAQI,MAAM,CAAEJ,IAAF,CAAN,CAAeY,KAAvB,EAA+B+D,gBAAtC;AACA,OAFD,CAEE,OAAQrB,CAAR,EAAY;AACb,eAAO,EAAP;AACA;AACD;AAhByB,GAA3B;AAkBA,SAAOmB,mBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\nimport { lock, unlock } from './private-apis';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\nfunction getStoreName( storeNameOrDescriptor ) {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {Object?} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores = null;\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param {Function} listener Listener function.\n\t * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener, storeNameOrDescriptor ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to global `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores( callback, ref ) {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins( attributes ) {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\tfunction () {\n\t\t\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} )\n\t\t);\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param {string} name Store registry name.\n\t * @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, createStore ) {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store = createStore();\n\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param {StoreDescriptor} store Store descriptor.\n\t */\n\tfunction register( store ) {\n\t\tregisterStoreInstance( store.name, () =>\n\t\t\tstore.instantiate( registry )\n\t\t);\n\t}\n\n\tfunction registerGenericStore( name, store ) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, () => store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tfunction registerStore( storeName, options ) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance( storeName, () =>\n\t\t\tcreateReduxStore( storeName, options ).instantiate( registry )\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.resume() );\n\t}\n\n\tlet registry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t};\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin, options ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\tconst registryWithPlugins = withPlugins( registry );\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws an error the store was not locked – this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins;\n}\n"]}
|
|
@@ -27,11 +27,8 @@ var _store = _interopRequireDefault(require("./store"));
|
|
|
27
27
|
*/
|
|
28
28
|
const createResolversCacheMiddleware = (registry, reducerKey) => () => next => action => {
|
|
29
29
|
const resolvers = registry.select(_store.default).getCachedResolvers(reducerKey);
|
|
30
|
-
Object.entries(resolvers).forEach(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
let [selectorName, resolversByArgs] = _ref;
|
|
34
|
-
const resolver = (_registry$stores = registry.stores) === null || _registry$stores === void 0 ? void 0 : (_registry$stores$redu = _registry$stores[reducerKey]) === null || _registry$stores$redu === void 0 ? void 0 : (_registry$stores$redu2 = _registry$stores$redu.resolvers) === null || _registry$stores$redu2 === void 0 ? void 0 : _registry$stores$redu2[selectorName];
|
|
30
|
+
Object.entries(resolvers).forEach(([selectorName, resolversByArgs]) => {
|
|
31
|
+
const resolver = registry.stores?.[reducerKey]?.resolvers?.[selectorName];
|
|
35
32
|
|
|
36
33
|
if (!resolver || !resolver.shouldInvalidate) {
|
|
37
34
|
return;
|
|
@@ -41,7 +38,7 @@ const createResolversCacheMiddleware = (registry, reducerKey) => () => next => a
|
|
|
41
38
|
// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.
|
|
42
39
|
// If the value is "finished" or "error" it means this resolver has finished its resolution which means we need
|
|
43
40
|
// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.
|
|
44
|
-
if (
|
|
41
|
+
if (value?.status !== 'finished' && value?.status !== 'error' || !resolver.shouldInvalidate(action, ...args)) {
|
|
45
42
|
return;
|
|
46
43
|
} // Trigger cache invalidation
|
|
47
44
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"names":["createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","coreDataStore","getCachedResolvers","Object","entries","forEach","selectorName","resolversByArgs","resolver","stores","shouldInvalidate","value","args","status","dispatch","invalidateResolution"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,8BAA8B,GACnC,CAAEC,QAAF,EAAYC,UAAZ,KAA4B,MAAQC,IAAF,IAAcC,MAAF,IAAc;AAC3D,QAAMC,SAAS,GAAGJ,QAAQ,CACxBK,MADgB,CACRC,cADQ,EAEhBC,kBAFgB,CAEIN,UAFJ,CAAlB;AAGAO,EAAAA,MAAM,CAACC,OAAP,CAAgBL,SAAhB,EAA4BM,OAA5B,CACC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"names":["createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","coreDataStore","getCachedResolvers","Object","entries","forEach","selectorName","resolversByArgs","resolver","stores","shouldInvalidate","value","args","status","dispatch","invalidateResolution"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,8BAA8B,GACnC,CAAEC,QAAF,EAAYC,UAAZ,KAA4B,MAAQC,IAAF,IAAcC,MAAF,IAAc;AAC3D,QAAMC,SAAS,GAAGJ,QAAQ,CACxBK,MADgB,CACRC,cADQ,EAEhBC,kBAFgB,CAEIN,UAFJ,CAAlB;AAGAO,EAAAA,MAAM,CAACC,OAAP,CAAgBL,SAAhB,EAA4BM,OAA5B,CACC,CAAE,CAAEC,YAAF,EAAgBC,eAAhB,CAAF,KAAyC;AACxC,UAAMC,QAAQ,GACbb,QAAQ,CAACc,MAAT,GAAmBb,UAAnB,GAAiCG,SAAjC,GACCO,YADD,CADD;;AAIA,QAAK,CAAEE,QAAF,IAAc,CAAEA,QAAQ,CAACE,gBAA9B,EAAiD;AAChD;AACA;;AACDH,IAAAA,eAAe,CAACF,OAAhB,CAAyB,CAAEM,KAAF,EAASC,IAAT,KAAmB;AAC3C;AACA;AACA;AACA,UACGD,KAAK,EAAEE,MAAP,KAAkB,UAAlB,IACDF,KAAK,EAAEE,MAAP,KAAkB,OADnB,IAEA,CAAEL,QAAQ,CAACE,gBAAT,CAA2BZ,MAA3B,EAAmC,GAAGc,IAAtC,CAHH,EAIE;AACD;AACA,OAV0C,CAY3C;;;AACAjB,MAAAA,QAAQ,CACNmB,QADF,CACYb,cADZ,EAEEc,oBAFF,CAEwBnB,UAFxB,EAEoCU,YAFpC,EAEkDM,IAFlD;AAGA,KAhBD;AAiBA,GA1BF;AA4BA,SAAOf,IAAI,CAAEC,MAAF,CAAX;AACA,CAlCF;;eAoCeJ,8B","sourcesContent":["/**\n * Internal dependencies\n */\nimport coreDataStore from './store';\n\n/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param {WPDataRegistry} registry The registry reference for which to create\n * the middleware.\n * @param {string} reducerKey The namespace for which to create the\n * middleware.\n *\n * @return {Function} Middleware function.\n */\nconst createResolversCacheMiddleware =\n\t( registry, reducerKey ) => () => ( next ) => ( action ) => {\n\t\tconst resolvers = registry\n\t\t\t.select( coreDataStore )\n\t\t\t.getCachedResolvers( reducerKey );\n\t\tObject.entries( resolvers ).forEach(\n\t\t\t( [ selectorName, resolversByArgs ] ) => {\n\t\t\t\tconst resolver =\n\t\t\t\t\tregistry.stores?.[ reducerKey ]?.resolvers?.[\n\t\t\t\t\t\tselectorName\n\t\t\t\t\t];\n\t\t\t\tif ( ! resolver || ! resolver.shouldInvalidate ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolversByArgs.forEach( ( value, args ) => {\n\t\t\t\t\t// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.\n\t\t\t\t\t// If the value is \"finished\" or \"error\" it means this resolver has finished its resolution which means we need\n\t\t\t\t\t// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\t\tif (\n\t\t\t\t\t\t( value?.status !== 'finished' &&\n\t\t\t\t\t\t\tvalue?.status !== 'error' ) ||\n\t\t\t\t\t\t! resolver.shouldInvalidate( action, ...args )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Trigger cache invalidation\n\t\t\t\t\tregistry\n\t\t\t\t\t\t.dispatch( coreDataStore )\n\t\t\t\t\t\t.invalidateResolution( reducerKey, selectorName, args );\n\t\t\t\t} );\n\t\t\t}\n\t\t);\n\t\treturn next( action );\n\t};\n\nexport default createResolversCacheMiddleware;\n"]}
|
package/build/store/index.js
CHANGED
|
@@ -8,19 +8,11 @@ const coreDataStore = {
|
|
|
8
8
|
name: 'core/data',
|
|
9
9
|
|
|
10
10
|
instantiate(registry) {
|
|
11
|
-
const getCoreDataSelector = selectorName =>
|
|
12
|
-
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
13
|
-
args[_key - 1] = arguments[_key];
|
|
14
|
-
}
|
|
15
|
-
|
|
11
|
+
const getCoreDataSelector = selectorName => (key, ...args) => {
|
|
16
12
|
return registry.select(key)[selectorName](...args);
|
|
17
13
|
};
|
|
18
14
|
|
|
19
|
-
const getCoreDataAction = actionName =>
|
|
20
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
21
|
-
args[_key2 - 1] = arguments[_key2];
|
|
22
|
-
}
|
|
23
|
-
|
|
15
|
+
const getCoreDataAction = actionName => (key, ...args) => {
|
|
24
16
|
return registry.dispatch(key)[actionName](...args);
|
|
25
17
|
};
|
|
26
18
|
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/store/index.js"],"names":["coreDataStore","name","instantiate","registry","getCoreDataSelector","selectorName","key","args","select","getCoreDataAction","actionName","dispatch","getSelectors","Object","fromEntries","map","getActions","subscribe"],"mappings":";;;;;;AAAA,MAAMA,aAAa,GAAG;AACrBC,EAAAA,IAAI,EAAE,WADe;;AAErBC,EAAAA,WAAW,CAAEC,QAAF,EAAa;AACvB,UAAMC,mBAAmB,GACtBC,YAAF,IACA,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/store/index.js"],"names":["coreDataStore","name","instantiate","registry","getCoreDataSelector","selectorName","key","args","select","getCoreDataAction","actionName","dispatch","getSelectors","Object","fromEntries","map","getActions","subscribe"],"mappings":";;;;;;AAAA,MAAMA,aAAa,GAAG;AACrBC,EAAAA,IAAI,EAAE,WADe;;AAErBC,EAAAA,WAAW,CAAEC,QAAF,EAAa;AACvB,UAAMC,mBAAmB,GACtBC,YAAF,IACA,CAAEC,GAAF,EAAO,GAAGC,IAAV,KAAoB;AACnB,aAAOJ,QAAQ,CAACK,MAAT,CAAiBF,GAAjB,EAAwBD,YAAxB,EAAwC,GAAGE,IAA3C,CAAP;AACA,KAJF;;AAMA,UAAME,iBAAiB,GACpBC,UAAF,IACA,CAAEJ,GAAF,EAAO,GAAGC,IAAV,KAAoB;AACnB,aAAOJ,QAAQ,CAACQ,QAAT,CAAmBL,GAAnB,EAA0BI,UAA1B,EAAwC,GAAGH,IAA3C,CAAP;AACA,KAJF;;AAMA,WAAO;AACNK,MAAAA,YAAY,GAAG;AACd,eAAOC,MAAM,CAACC,WAAP,CACN,CACC,gBADD,EAEC,sBAFD,EAGC,uBAHD,EAIC,aAJD,EAKC,oBALD,EAMEC,GANF,CAMSV,YAAF,IAAoB,CAC1BA,YAD0B,EAE1BD,mBAAmB,CAAEC,YAAF,CAFO,CAN3B,CADM,CAAP;AAYA,OAdK;;AAgBNW,MAAAA,UAAU,GAAG;AACZ,eAAOH,MAAM,CAACC,WAAP,CACN,CACC,iBADD,EAEC,kBAFD,EAGC,sBAHD,EAIC,8BAJD,EAKC,sCALD,EAMEC,GANF,CAMSL,UAAF,IAAkB,CACxBA,UADwB,EAExBD,iBAAiB,CAAEC,UAAF,CAFO,CANzB,CADM,CAAP;AAYA,OA7BK;;AA+BNO,MAAAA,SAAS,GAAG;AACX;AACA;AACA;AACA;AACA,eAAO,MAAM,MAAM,CAAE,CAArB;AACA;;AArCK,KAAP;AAuCA;;AAtDoB,CAAtB;eAyDejB,a","sourcesContent":["const coreDataStore = {\n\tname: 'core/data',\n\tinstantiate( registry ) {\n\t\tconst getCoreDataSelector =\n\t\t\t( selectorName ) =>\n\t\t\t( key, ...args ) => {\n\t\t\t\treturn registry.select( key )[ selectorName ]( ...args );\n\t\t\t};\n\n\t\tconst getCoreDataAction =\n\t\t\t( actionName ) =>\n\t\t\t( key, ...args ) => {\n\t\t\t\treturn registry.dispatch( key )[ actionName ]( ...args );\n\t\t\t};\n\n\t\treturn {\n\t\t\tgetSelectors() {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'getIsResolving',\n\t\t\t\t\t\t'hasStartedResolution',\n\t\t\t\t\t\t'hasFinishedResolution',\n\t\t\t\t\t\t'isResolving',\n\t\t\t\t\t\t'getCachedResolvers',\n\t\t\t\t\t].map( ( selectorName ) => [\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\tgetCoreDataSelector( selectorName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tgetActions() {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'startResolution',\n\t\t\t\t\t\t'finishResolution',\n\t\t\t\t\t\t'invalidateResolution',\n\t\t\t\t\t\t'invalidateResolutionForStore',\n\t\t\t\t\t\t'invalidateResolutionForStoreSelector',\n\t\t\t\t\t].map( ( actionName ) => [\n\t\t\t\t\t\tactionName,\n\t\t\t\t\t\tgetCoreDataAction( actionName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tsubscribe() {\n\t\t\t\t// There's no reasons to trigger any listener when we subscribe to this store\n\t\t\t\t// because there's no state stored in this store that need to retrigger selectors\n\t\t\t\t// if a change happens, the corresponding store where the tracking stated live\n\t\t\t\t// would have already triggered a \"subscribe\" call.\n\t\t\t\treturn () => () => {};\n\t\t\t},\n\t\t};\n\t},\n};\n\nexport default coreDataStore;\n"]}
|
|
@@ -31,17 +31,13 @@ const useDispatchWithMap = (dispatchMap, deps) => {
|
|
|
31
31
|
});
|
|
32
32
|
return useMemo(() => {
|
|
33
33
|
const currentDispatchProps = currentDispatchMap.current(registry.dispatch, registry);
|
|
34
|
-
return Object.fromEntries(Object.entries(currentDispatchProps).map(
|
|
35
|
-
let [propName, dispatcher] = _ref;
|
|
36
|
-
|
|
34
|
+
return Object.fromEntries(Object.entries(currentDispatchProps).map(([propName, dispatcher]) => {
|
|
37
35
|
if (typeof dispatcher !== 'function') {
|
|
38
36
|
// eslint-disable-next-line no-console
|
|
39
37
|
console.warn(`Property ${propName} returned from dispatchMap in useDispatchWithMap must be a function.`);
|
|
40
38
|
}
|
|
41
39
|
|
|
42
|
-
return [propName,
|
|
43
|
-
return currentDispatchMap.current(registry.dispatch, registry)[propName](...arguments);
|
|
44
|
-
}];
|
|
40
|
+
return [propName, (...args) => currentDispatchMap.current(registry.dispatch, registry)[propName](...args)];
|
|
45
41
|
}));
|
|
46
42
|
}, [registry, ...deps]);
|
|
47
43
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch-with-map.js"],"names":["useMemo","useRef","useIsomorphicLayoutEffect","useRegistry","useDispatchWithMap","dispatchMap","deps","registry","currentDispatchMap","current","currentDispatchProps","dispatch","Object","fromEntries","entries","map","propName","dispatcher","console","warn"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,MAAlB,QAAgC,oBAAhC;AACA,SAASC,yBAAT,QAA0C,oBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,kBAAkB,GAAG,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACnD,QAAMC,QAAQ,GAAGJ,WAAW,EAA5B;AACA,QAAMK,kBAAkB,GAAGP,MAAM,CAAEI,WAAF,CAAjC;AAEAH,EAAAA,yBAAyB,CAAE,MAAM;AAChCM,IAAAA,kBAAkB,CAACC,OAAnB,GAA6BJ,WAA7B;AACA,GAFwB,CAAzB;AAIA,SAAOL,OAAO,CAAE,MAAM;AACrB,UAAMU,oBAAoB,GAAGF,kBAAkB,CAACC,OAAnB,CAC5BF,QAAQ,CAACI,QADmB,EAE5BJ,QAF4B,CAA7B;AAIA,WAAOK,MAAM,CAACC,WAAP,CACND,MAAM,CAACE,OAAP,CAAgBJ,oBAAhB,EAAuCK,GAAvC,CACC,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/components/use-dispatch/use-dispatch-with-map.js"],"names":["useMemo","useRef","useIsomorphicLayoutEffect","useRegistry","useDispatchWithMap","dispatchMap","deps","registry","currentDispatchMap","current","currentDispatchProps","dispatch","Object","fromEntries","entries","map","propName","dispatcher","console","warn","args"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,MAAlB,QAAgC,oBAAhC;AACA,SAASC,yBAAT,QAA0C,oBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,kBAAkB,GAAG,CAAEC,WAAF,EAAeC,IAAf,KAAyB;AACnD,QAAMC,QAAQ,GAAGJ,WAAW,EAA5B;AACA,QAAMK,kBAAkB,GAAGP,MAAM,CAAEI,WAAF,CAAjC;AAEAH,EAAAA,yBAAyB,CAAE,MAAM;AAChCM,IAAAA,kBAAkB,CAACC,OAAnB,GAA6BJ,WAA7B;AACA,GAFwB,CAAzB;AAIA,SAAOL,OAAO,CAAE,MAAM;AACrB,UAAMU,oBAAoB,GAAGF,kBAAkB,CAACC,OAAnB,CAC5BF,QAAQ,CAACI,QADmB,EAE5BJ,QAF4B,CAA7B;AAIA,WAAOK,MAAM,CAACC,WAAP,CACND,MAAM,CAACE,OAAP,CAAgBJ,oBAAhB,EAAuCK,GAAvC,CACC,CAAE,CAAEC,QAAF,EAAYC,UAAZ,CAAF,KAAgC;AAC/B,UAAK,OAAOA,UAAP,KAAsB,UAA3B,EAAwC;AACvC;AACAC,QAAAA,OAAO,CAACC,IAAR,CACE,YAAYH,QAAU,sEADxB;AAGA;;AACD,aAAO,CACNA,QADM,EAEN,CAAE,GAAGI,IAAL,KACCZ,kBAAkB,CAChBC,OADF,CACWF,QAAQ,CAACI,QADpB,EAC8BJ,QAD9B,EAEGS,QAFH,EAEe,GAAGI,IAFlB,CAHK,CAAP;AAOA,KAfF,CADM,CAAP;AAmBA,GAxBa,EAwBX,CAAEb,QAAF,EAAY,GAAGD,IAAf,CAxBW,CAAd;AAyBA,CAjCD;;AAmCA,eAAeF,kBAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useRef } from '@wordpress/element';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\n\n/**\n * Custom react hook for returning aggregate dispatch actions using the provided\n * dispatchMap.\n *\n * Currently this is an internal api only and is implemented by `withDispatch`\n *\n * @param {Function} dispatchMap Receives the `registry.dispatch` function as\n * the first argument and the `registry` object\n * as the second argument. Should return an\n * object mapping props to functions.\n * @param {Array} deps An array of dependencies for the hook.\n * @return {Object} An object mapping props to functions created by the passed\n * in dispatchMap.\n */\nconst useDispatchWithMap = ( dispatchMap, deps ) => {\n\tconst registry = useRegistry();\n\tconst currentDispatchMap = useRef( dispatchMap );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tcurrentDispatchMap.current = dispatchMap;\n\t} );\n\n\treturn useMemo( () => {\n\t\tconst currentDispatchProps = currentDispatchMap.current(\n\t\t\tregistry.dispatch,\n\t\t\tregistry\n\t\t);\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( currentDispatchProps ).map(\n\t\t\t\t( [ propName, dispatcher ] ) => {\n\t\t\t\t\tif ( typeof dispatcher !== 'function' ) {\n\t\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t`Property ${ propName } returned from dispatchMap in useDispatchWithMap must be a function.`\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn [\n\t\t\t\t\t\tpropName,\n\t\t\t\t\t\t( ...args ) =>\n\t\t\t\t\t\t\tcurrentDispatchMap\n\t\t\t\t\t\t\t\t.current( registry.dispatch, registry )\n\t\t\t\t\t\t\t\t[ propName ]( ...args ),\n\t\t\t\t\t];\n\t\t\t\t}\n\t\t\t)\n\t\t);\n\t}, [ registry, ...deps ] );\n};\n\nexport default useDispatchWithMap;\n"]}
|
|
@@ -86,7 +86,7 @@ function Store(registry, suspense) {
|
|
|
86
86
|
|
|
87
87
|
for (const unsub of unsubs.values()) {
|
|
88
88
|
// The return value of the subscribe function could be undefined if the store is a custom generic store.
|
|
89
|
-
unsub
|
|
89
|
+
unsub?.();
|
|
90
90
|
} // Cancel existing store updates that were already scheduled.
|
|
91
91
|
|
|
92
92
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["createQueue","useRef","useCallback","useMemo","useSyncExternalStore","useDebugValue","isShallowEqual","useRegistry","useAsyncMode","renderQueue","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscriber","createSubscriber","stores","activeStores","activeSubscriptions","Set","subscribe","listener","onStoreChange","onChange","add","unsubs","subscribeStore","storeName","push","delete","unsub","values","cancel","updateStores","newStores","newStore","includes","subscription","mapSelect","isAsync","updateValue","listeningStores","current","mapResult","__unstableMarkListeningStores","getValue","useStaticSelect","useMappingSelect","deps","store","selector","result","useSelect","staticSelectMode","staticSelectModeRef","prevMode","nextMode","Error","useSuspenseSelect"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,2BAA5B;AACA,SACCC,MADD,EAECC,WAFD,EAGCC,OAHD,EAICC,oBAJD,EAKCC,aALD,QAMO,oBANP;AAOA,OAAOC,cAAP,MAA2B,6BAA3B;AAEA;AACA;AACA;;AACA,OAAOC,WAAP,MAAwB,mCAAxB;AACA,OAAOC,YAAP,MAAyB,uCAAzB;AAEA,MAAMC,WAAW,GAAGT,WAAW,EAA/B;AAEA;AACA;AACA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;;AACA;;AACA;AACA;AACA;AACA;;AAEA,SAASU,KAAT,CAAgBC,QAAhB,EAA0BC,QAA1B,EAAqC;AACpC,QAAMC,MAAM,GAAGD,QAAQ,GAAGD,QAAQ,CAACG,aAAZ,GAA4BH,QAAQ,CAACE,MAA5D;AACA,QAAME,YAAY,GAAG,EAArB;AACA,MAAIC,aAAJ;AACA,MAAIC,aAAJ;AACA,MAAIC,kBAAkB,GAAG,KAAzB;AACA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ACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASC,SAAT,CAAoBd,SAApB,EAA+BU,IAA/B,EAAsC;AACpD;AACA;AACA,QAAMK,gBAAgB,GAAG,OAAOf,SAAP,KAAqB,UAA9C;AACA,QAAMgB,mBAAmB,GAAG3D,MAAM,CAAE0D,gBAAF,CAAlC;;AAEA,MAAKA,gBAAgB,KAAKC,mBAAmB,CAACZ,OAA9C,EAAwD;AACvD,UAAMa,QAAQ,GAAGD,mBAAmB,CAACZ,OAApB,GAA8B,QAA9B,GAAyC,SAA1D;AACA,UAAMc,QAAQ,GAAGH,gBAAgB,GAAG,QAAH,GAAc,SAA/C;AACA,UAAM,IAAII,KAAJ,CACJ,4BAA4BF,QAAU,OAAOC,QAAU,iBADnD,CAAN;AAGA;AAED;AACA;AACA;;;AACA,SAAOH,gBAAgB,GACpBP,eAAe,CAAER,SAAF,CADK,GAEpBS,gBAAgB,CAAE,KAAF,EAAST,SAAT,EAAoBU,IAApB,CAFnB;AAGA;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASU,iBAAT,CAA4BpB,SAA5B,EAAuCU,IAAvC,EAA8C;AACpD,SAAOD,gBAAgB,CAAE,IAAF,EAAQT,SAAR,EAAmBU,IAAnB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscriber;\n\n\tconst createSubscriber = ( stores ) => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set();\n\n\t\tfunction subscribe( listener ) {\n\t\t\t// Invalidate the value right after subscription was created. React will\n\t\t\t// call `getValue` after subscribing, to detect store updates that happened\n\t\t\t// in the interval between the `getValue` call during render and creating\n\t\t\t// the subscription, which is slightly delayed. We need to ensure that this\n\t\t\t// second `getValue` call will compute a fresh value.\n\t\t\tlastMapResultValid = false;\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs = [];\n\t\t\tfunction subscribeStore( storeName ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect, isAsync ) => {\n\t\tfunction updateValue() {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber.subscribe, getValue };\n\t};\n}\n\nfunction useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo( () => Store( registry, suspense ), [ registry ] );\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t/* eslint-disable react-hooks/rules-of-hooks */\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? useStaticSelect( mapSelect )\n\t\t: useMappingSelect( false, mapSelect, deps );\n\t/* eslint-enable react-hooks/rules-of-hooks */\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn useMappingSelect( true, mapSelect, deps );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["createQueue","useRef","useCallback","useMemo","useSyncExternalStore","useDebugValue","isShallowEqual","useRegistry","useAsyncMode","renderQueue","Store","registry","suspense","select","suspendSelect","queueContext","lastMapSelect","lastMapResult","lastMapResultValid","lastIsAsync","subscriber","createSubscriber","stores","activeStores","activeSubscriptions","Set","subscribe","listener","onStoreChange","onChange","add","unsubs","subscribeStore","storeName","push","delete","unsub","values","cancel","updateStores","newStores","newStore","includes","subscription","mapSelect","isAsync","updateValue","listeningStores","current","mapResult","__unstableMarkListeningStores","getValue","useStaticSelect","useMappingSelect","deps","store","selector","result","useSelect","staticSelectMode","staticSelectModeRef","prevMode","nextMode","Error","useSuspenseSelect"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,QAA4B,2BAA5B;AACA,SACCC,MADD,EAECC,WAFD,EAGCC,OAHD,EAICC,oBAJD,EAKCC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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASU,iBAAT,CAA4BpB,SAA5B,EAAuCU,IAAvC,EAA8C;AACpD,SAAOD,gBAAgB,CAAE,IAAF,EAAQT,SAAR,EAAmBU,IAAnB,CAAvB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport {\n\tuseRef,\n\tuseCallback,\n\tuseMemo,\n\tuseSyncExternalStore,\n\tuseDebugValue,\n} from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst renderQueue = createQueue();\n\n/**\n * @typedef {import('../../types').StoreDescriptor<C>} StoreDescriptor\n * @template {import('../../types').AnyConfig} C\n */\n/**\n * @typedef {import('../../types').ReduxStoreConfig<State,Actions,Selectors>} ReduxStoreConfig\n * @template State\n * @template {Record<string,import('../../types').ActionCreator>} Actions\n * @template Selectors\n */\n/** @typedef {import('../../types').MapSelect} MapSelect */\n/**\n * @typedef {import('../../types').UseSelectReturn<T>} UseSelectReturn\n * @template {MapSelect|StoreDescriptor<any>} T\n */\n\nfunction Store( registry, suspense ) {\n\tconst select = suspense ? registry.suspendSelect : registry.select;\n\tconst queueContext = {};\n\tlet lastMapSelect;\n\tlet lastMapResult;\n\tlet lastMapResultValid = false;\n\tlet lastIsAsync;\n\tlet subscriber;\n\n\tconst createSubscriber = ( stores ) => {\n\t\t// The set of stores the `subscribe` function is supposed to subscribe to. Here it is\n\t\t// initialized, and then the `updateStores` function can add new stores to it.\n\t\tconst activeStores = [ ...stores ];\n\n\t\t// The `subscribe` function, which is passed to the `useSyncExternalStore` hook, could\n\t\t// be called multiple times to establish multiple subscriptions. That's why we need to\n\t\t// keep a set of active subscriptions;\n\t\tconst activeSubscriptions = new Set();\n\n\t\tfunction subscribe( listener ) {\n\t\t\t// Invalidate the value right after subscription was created. React will\n\t\t\t// call `getValue` after subscribing, to detect store updates that happened\n\t\t\t// in the interval between the `getValue` call during render and creating\n\t\t\t// the subscription, which is slightly delayed. We need to ensure that this\n\t\t\t// second `getValue` call will compute a fresh value.\n\t\t\tlastMapResultValid = false;\n\n\t\t\tconst onStoreChange = () => {\n\t\t\t\t// Invalidate the value on store update, so that a fresh value is computed.\n\t\t\t\tlastMapResultValid = false;\n\t\t\t\tlistener();\n\t\t\t};\n\n\t\t\tconst onChange = () => {\n\t\t\t\tif ( lastIsAsync ) {\n\t\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t\t} else {\n\t\t\t\t\tonStoreChange();\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst unsubs = [];\n\t\t\tfunction subscribeStore( storeName ) {\n\t\t\t\tunsubs.push( registry.subscribe( onChange, storeName ) );\n\t\t\t}\n\n\t\t\tfor ( const storeName of activeStores ) {\n\t\t\t\tsubscribeStore( storeName );\n\t\t\t}\n\n\t\t\tactiveSubscriptions.add( subscribeStore );\n\n\t\t\treturn () => {\n\t\t\t\tactiveSubscriptions.delete( subscribeStore );\n\n\t\t\t\tfor ( const unsub of unsubs.values() ) {\n\t\t\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\t\t\tunsub?.();\n\t\t\t\t}\n\t\t\t\t// Cancel existing store updates that were already scheduled.\n\t\t\t\trenderQueue.cancel( queueContext );\n\t\t\t};\n\t\t}\n\n\t\t// Check if `newStores` contains some stores we're not subscribed to yet, and add them.\n\t\tfunction updateStores( newStores ) {\n\t\t\tfor ( const newStore of newStores ) {\n\t\t\t\tif ( activeStores.includes( newStore ) ) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\t// New `subscribe` calls will subscribe to `newStore`, too.\n\t\t\t\tactiveStores.push( newStore );\n\n\t\t\t\t// Add `newStore` to existing subscriptions.\n\t\t\t\tfor ( const subscription of activeSubscriptions ) {\n\t\t\t\t\tsubscription( newStore );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn { subscribe, updateStores };\n\t};\n\n\treturn ( mapSelect, isAsync ) => {\n\t\tfunction updateValue() {\n\t\t\t// If the last value is valid, and the `mapSelect` callback hasn't changed,\n\t\t\t// then we can safely return the cached value. The value can change only on\n\t\t\t// store update, and in that case value will be invalidated by the listener.\n\t\t\tif ( lastMapResultValid && mapSelect === lastMapSelect ) {\n\t\t\t\treturn lastMapResult;\n\t\t\t}\n\n\t\t\tconst listeningStores = { current: null };\n\t\t\tconst mapResult = registry.__unstableMarkListeningStores(\n\t\t\t\t() => mapSelect( select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t);\n\n\t\t\tif ( ! subscriber ) {\n\t\t\t\tsubscriber = createSubscriber( listeningStores.current );\n\t\t\t} else {\n\t\t\t\tsubscriber.updateStores( listeningStores.current );\n\t\t\t}\n\n\t\t\t// If the new value is shallow-equal to the old one, keep the old one so\n\t\t\t// that we don't trigger unwanted updates that do a `===` check.\n\t\t\tif ( ! isShallowEqual( lastMapResult, mapResult ) ) {\n\t\t\t\tlastMapResult = mapResult;\n\t\t\t}\n\t\t\tlastMapSelect = mapSelect;\n\t\t\tlastMapResultValid = true;\n\t\t}\n\n\t\tfunction getValue() {\n\t\t\t// Update the value in case it's been invalidated or `mapSelect` has changed.\n\t\t\tupdateValue();\n\t\t\treturn lastMapResult;\n\t\t}\n\n\t\t// When transitioning from async to sync mode, cancel existing store updates\n\t\t// that have been scheduled, and invalidate the value so that it's freshly\n\t\t// computed. It might have been changed by the update we just cancelled.\n\t\tif ( lastIsAsync && ! isAsync ) {\n\t\t\tlastMapResultValid = false;\n\t\t\trenderQueue.cancel( queueContext );\n\t\t}\n\n\t\tupdateValue();\n\n\t\tlastIsAsync = isAsync;\n\n\t\t// Return a pair of functions that can be passed to `useSyncExternalStore`.\n\t\treturn { subscribe: subscriber.subscribe, getValue };\n\t};\n}\n\nfunction useStaticSelect( storeName ) {\n\treturn useRegistry().select( storeName );\n}\n\nfunction useMappingSelect( suspense, mapSelect, deps ) {\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\tconst store = useMemo( () => Store( registry, suspense ), [ registry ] );\n\tconst selector = useCallback( mapSelect, deps );\n\tconst { subscribe, getValue } = store( selector, isAsync );\n\tconst result = useSyncExternalStore( subscribe, getValue, getValue );\n\tuseDebugValue( result );\n\treturn result;\n}\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @template {MapSelect | StoreDescriptor<any>} T\n * @param {T} mapSelect Function called on every state change. The returned value is\n * exposed to the component implementing this hook. The function\n * receives the `registry.select` method on the first argument\n * and the `registry` on the second argument.\n * When a store key is passed, all selectors for the store will be\n * returned. This is only meant for usage of these selectors in event\n * callbacks, not for data needed to create the element tree.\n * @param {unknown[]} deps If provided, this memoizes the mapSelect so the same `mapSelect` is\n * invoked on every state change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( myCustomStore ).getPrice( 'hammer', currency );\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( myCustomStore );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n * @return {UseSelectReturn<T>} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\t// On initial call, on mount, determine the mode of this `useSelect` call\n\t// and then never allow it to change on subsequent updates.\n\tconst staticSelectMode = typeof mapSelect !== 'function';\n\tconst staticSelectModeRef = useRef( staticSelectMode );\n\n\tif ( staticSelectMode !== staticSelectModeRef.current ) {\n\t\tconst prevMode = staticSelectModeRef.current ? 'static' : 'mapping';\n\t\tconst nextMode = staticSelectMode ? 'static' : 'mapping';\n\t\tthrow new Error(\n\t\t\t`Switching useSelect from ${ prevMode } to ${ nextMode } is not allowed`\n\t\t);\n\t}\n\n\t/* eslint-disable react-hooks/rules-of-hooks */\n\t// `staticSelectMode` is not allowed to change during the hook instance's,\n\t// lifetime, so the rules of hooks are not really violated.\n\treturn staticSelectMode\n\t\t? useStaticSelect( mapSelect )\n\t\t: useMappingSelect( false, mapSelect, deps );\n\t/* eslint-enable react-hooks/rules-of-hooks */\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\treturn useMappingSelect( true, mapSelect, deps );\n}\n"]}
|