@wordpress/data 6.3.0 → 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 +2 -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 +24 -8
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/actions.js +47 -4
- package/build/redux-store/metadata/actions.js.map +1 -1
- package/build/redux-store/metadata/reducer.js +57 -4
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +71 -7
- package/build/redux-store/metadata/selectors.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 +24 -8
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/actions.js +43 -4
- package/build-module/redux-store/metadata/actions.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +57 -4
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +65 -7
- package/build-module/redux-store/metadata/selectors.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 +37 -4
- 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 +40 -0
- package/build-types/redux-store/metadata/selectors.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 +43 -15
- package/src/redux-store/metadata/actions.js +43 -4
- package/src/redux-store/metadata/reducer.ts +60 -9
- package/src/redux-store/metadata/selectors.js +60 -7
- package/src/redux-store/metadata/test/reducer.js +64 -24
- package/src/redux-store/metadata/test/selectors.js +263 -53
- 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/build-module/factory.js
CHANGED
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
* @return {Function} Registry selector that can be registered with a store.
|
|
37
37
|
*/
|
|
38
38
|
export function createRegistrySelector(registrySelector) {
|
|
39
|
-
//
|
|
39
|
+
// Create a selector function that is bound to the registry referenced by `selector.registry`
|
|
40
40
|
// and that has the same API as a regular selector. Binding it in such a way makes it
|
|
41
41
|
// possible to call the selector directly from another selector.
|
|
42
42
|
const selector = function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":"AAAA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG;AAAA,WAChBD,gBAAgB,CAAEC,QAAQ,CAACC,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,YAA9C,CADgB;AAAA,GAAjB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCF,EAAAA,QAAQ,CAACG,kBAAT,GAA8B,IAA9B;AAEA,SAAOH,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( 'core/editor' ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t//
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":"AAAA;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG;AAAA,WAChBD,gBAAgB,CAAEC,QAAQ,CAACC,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,YAA9C,CADgB;AAAA,GAAjB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCF,EAAAA,QAAQ,CAACG,kBAAT,GAA8B,IAA9B;AAEA,SAAOH,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASI,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( 'core/editor' ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// Create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selecto.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"]}
|
|
@@ -208,6 +208,107 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
208
208
|
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Move the 'features' object in local storage from the sourceStoreName to the
|
|
213
|
+
* preferences store.
|
|
214
|
+
*
|
|
215
|
+
* @param {Object} persistence The persistence interface.
|
|
216
|
+
* @param {string} sourceStoreName The name of the store that has persisted
|
|
217
|
+
* preferences to migrate to the preferences
|
|
218
|
+
* package.
|
|
219
|
+
*/
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
export function migrateFeaturePreferencesToPreferencesStore(persistence, sourceStoreName) {
|
|
223
|
+
var _state$interfaceStore, _state$interfaceStore2, _state$interfaceStore3, _state$sourceStoreNam, _state$sourceStoreNam2;
|
|
224
|
+
|
|
225
|
+
const preferencesStoreName = 'core/preferences';
|
|
226
|
+
const interfaceStoreName = 'core/interface';
|
|
227
|
+
const state = persistence.get(); // Features most recently (and briefly) lived in the interface package.
|
|
228
|
+
// If data exists there, prioritize using that for the migration. If not
|
|
229
|
+
// also check the original package as the user may have updated from an
|
|
230
|
+
// older block editor version.
|
|
231
|
+
|
|
232
|
+
const interfaceFeatures = (_state$interfaceStore = state[interfaceStoreName]) === null || _state$interfaceStore === void 0 ? void 0 : (_state$interfaceStore2 = _state$interfaceStore.preferences) === null || _state$interfaceStore2 === void 0 ? void 0 : (_state$interfaceStore3 = _state$interfaceStore2.features) === null || _state$interfaceStore3 === void 0 ? void 0 : _state$interfaceStore3[sourceStoreName];
|
|
233
|
+
const sourceFeatures = (_state$sourceStoreNam = state[sourceStoreName]) === null || _state$sourceStoreNam === void 0 ? void 0 : (_state$sourceStoreNam2 = _state$sourceStoreNam.preferences) === null || _state$sourceStoreNam2 === void 0 ? void 0 : _state$sourceStoreNam2.features;
|
|
234
|
+
const featuresToMigrate = interfaceFeatures ? interfaceFeatures : sourceFeatures;
|
|
235
|
+
|
|
236
|
+
if (featuresToMigrate) {
|
|
237
|
+
var _state$preferencesSto;
|
|
238
|
+
|
|
239
|
+
const targetFeatures = (_state$preferencesSto = state[preferencesStoreName]) === null || _state$preferencesSto === void 0 ? void 0 : _state$preferencesSto.preferences; // Avoid migrating features again if they've previously been migrated.
|
|
240
|
+
|
|
241
|
+
if (!(targetFeatures !== null && targetFeatures !== void 0 && targetFeatures[sourceStoreName])) {
|
|
242
|
+
// Set the feature values in the interface store, the features
|
|
243
|
+
// object is keyed by 'scope', which matches the store name for
|
|
244
|
+
// the source.
|
|
245
|
+
persistence.set(preferencesStoreName, {
|
|
246
|
+
preferences: { ...targetFeatures,
|
|
247
|
+
[sourceStoreName]: featuresToMigrate
|
|
248
|
+
}
|
|
249
|
+
}); // Remove migrated feature preferences from `interface`.
|
|
250
|
+
|
|
251
|
+
if (interfaceFeatures) {
|
|
252
|
+
var _state$interfaceStore4, _state$interfaceStore5;
|
|
253
|
+
|
|
254
|
+
const otherInterfaceFeatures = (_state$interfaceStore4 = state[interfaceStoreName]) === null || _state$interfaceStore4 === void 0 ? void 0 : (_state$interfaceStore5 = _state$interfaceStore4.preferences) === null || _state$interfaceStore5 === void 0 ? void 0 : _state$interfaceStore5.features;
|
|
255
|
+
persistence.set(interfaceStoreName, {
|
|
256
|
+
preferences: {
|
|
257
|
+
features: { ...otherInterfaceFeatures,
|
|
258
|
+
[sourceStoreName]: undefined
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
} // Remove migrated feature preferences from the source.
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
if (sourceFeatures) {
|
|
266
|
+
var _state$sourceStoreNam3;
|
|
267
|
+
|
|
268
|
+
const sourcePreferences = (_state$sourceStoreNam3 = state[sourceStoreName]) === null || _state$sourceStoreNam3 === void 0 ? void 0 : _state$sourceStoreNam3.preferences;
|
|
269
|
+
persistence.set(sourceStoreName, {
|
|
270
|
+
preferences: { ...sourcePreferences,
|
|
271
|
+
features: undefined
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
export function migrateIndividualPreferenceToPreferencesStore(persistence, sourceStoreName, key) {
|
|
279
|
+
var _state$sourceStoreNam4, _state$sourceStoreNam5, _state$preferencesSto2, _state$preferencesSto3, _state$preferencesSto4, _state$preferencesSto5, _state$preferencesSto6, _state$preferencesSto7, _state$sourceStoreNam6;
|
|
280
|
+
|
|
281
|
+
const preferencesStoreName = 'core/preferences';
|
|
282
|
+
const state = persistence.get();
|
|
283
|
+
const sourcePreference = (_state$sourceStoreNam4 = state[sourceStoreName]) === null || _state$sourceStoreNam4 === void 0 ? void 0 : (_state$sourceStoreNam5 = _state$sourceStoreNam4.preferences) === null || _state$sourceStoreNam5 === void 0 ? void 0 : _state$sourceStoreNam5[key]; // There's nothing to migrate, exit early.
|
|
284
|
+
|
|
285
|
+
if (!sourcePreference) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const targetPreference = (_state$preferencesSto2 = state[preferencesStoreName]) === null || _state$preferencesSto2 === void 0 ? void 0 : (_state$preferencesSto3 = _state$preferencesSto2.preferences) === null || _state$preferencesSto3 === void 0 ? void 0 : (_state$preferencesSto4 = _state$preferencesSto3[sourceStoreName]) === null || _state$preferencesSto4 === void 0 ? void 0 : _state$preferencesSto4[key]; // There's existing data at the target, so don't overwrite it, exit early.
|
|
290
|
+
|
|
291
|
+
if (targetPreference) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const allPreferences = (_state$preferencesSto5 = state[preferencesStoreName]) === null || _state$preferencesSto5 === void 0 ? void 0 : _state$preferencesSto5.preferences;
|
|
296
|
+
const targetPreferences = (_state$preferencesSto6 = state[preferencesStoreName]) === null || _state$preferencesSto6 === void 0 ? void 0 : (_state$preferencesSto7 = _state$preferencesSto6.preferences) === null || _state$preferencesSto7 === void 0 ? void 0 : _state$preferencesSto7[sourceStoreName];
|
|
297
|
+
persistence.set(preferencesStoreName, {
|
|
298
|
+
preferences: { ...allPreferences,
|
|
299
|
+
[sourceStoreName]: { ...targetPreferences,
|
|
300
|
+
[key]: sourcePreference
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}); // Remove migrated feature preferences from the source.
|
|
304
|
+
|
|
305
|
+
const allSourcePreferences = (_state$sourceStoreNam6 = state[sourceStoreName]) === null || _state$sourceStoreNam6 === void 0 ? void 0 : _state$sourceStoreNam6.preferences;
|
|
306
|
+
persistence.set(sourceStoreName, {
|
|
307
|
+
preferences: { ...allSourcePreferences,
|
|
308
|
+
[key]: undefined
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
211
312
|
/**
|
|
212
313
|
* Move the 'features' object in local storage from the sourceStoreName to the
|
|
213
314
|
* interface store.
|
|
@@ -218,19 +319,18 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
218
319
|
* package.
|
|
219
320
|
*/
|
|
220
321
|
|
|
221
|
-
|
|
222
322
|
export function migrateFeaturePreferencesToInterfaceStore(persistence, sourceStoreName) {
|
|
223
|
-
var _state$
|
|
323
|
+
var _state$sourceStoreNam7;
|
|
224
324
|
|
|
225
325
|
const interfaceStoreName = 'core/interface';
|
|
226
326
|
const state = persistence.get();
|
|
227
|
-
const sourcePreferences = (_state$
|
|
327
|
+
const sourcePreferences = (_state$sourceStoreNam7 = state[sourceStoreName]) === null || _state$sourceStoreNam7 === void 0 ? void 0 : _state$sourceStoreNam7.preferences;
|
|
228
328
|
const sourceFeatures = sourcePreferences === null || sourcePreferences === void 0 ? void 0 : sourcePreferences.features;
|
|
229
329
|
|
|
230
330
|
if (sourceFeatures) {
|
|
231
|
-
var _state$
|
|
331
|
+
var _state$interfaceStore6, _state$interfaceStore7;
|
|
232
332
|
|
|
233
|
-
const targetFeatures = (_state$
|
|
333
|
+
const targetFeatures = (_state$interfaceStore6 = state[interfaceStoreName]) === null || _state$interfaceStore6 === void 0 ? void 0 : (_state$interfaceStore7 = _state$interfaceStore6.preferences) === null || _state$interfaceStore7 === void 0 ? void 0 : _state$interfaceStore7.features; // Avoid migrating features again if they've previously been migrated.
|
|
234
334
|
|
|
235
335
|
if (!(targetFeatures !== null && targetFeatures !== void 0 && targetFeatures[sourceStoreName])) {
|
|
236
336
|
// Set the feature values in the interface store, the features
|
|
@@ -252,16 +352,15 @@ export function migrateFeaturePreferencesToInterfaceStore(persistence, sourceSto
|
|
|
252
352
|
}
|
|
253
353
|
}
|
|
254
354
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Deprecated: Remove this function and the code in WordPress Core that calls
|
|
257
|
-
* it once WordPress 6.0 is released.
|
|
258
|
-
*/
|
|
259
355
|
|
|
260
356
|
persistencePlugin.__unstableMigrate = pluginOptions => {
|
|
261
357
|
const persistence = createPersistenceInterface(pluginOptions);
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
358
|
+
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-widgets');
|
|
359
|
+
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/customize-widgets');
|
|
360
|
+
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-post');
|
|
361
|
+
migrateIndividualPreferenceToPreferencesStore(persistence, 'core/edit-post', 'hiddenBlockTypes');
|
|
362
|
+
migrateFeaturePreferencesToPreferencesStore(persistence, 'core/edit-site');
|
|
363
|
+
migrateIndividualPreferenceToPreferencesStore(persistence, 'core/edit-site', 'editorMode');
|
|
265
364
|
};
|
|
266
365
|
|
|
267
366
|
export default persistencePlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["merge","isPlainObject","defaultStorage","combineReducers","DEFAULT_STORAGE","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","store","subscribe","migrateFeaturePreferencesToInterfaceStore","sourceStoreName","interfaceStoreName","sourcePreferences","preferences","sourceFeatures","features","targetFeatures","__unstableMigrate"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,aAAhB,QAAqC,QA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sB,EAAAA,yCAAyC,CACxCrB,WADwC,EAExC,mBAFwC,CAAzC;AAIAqB,EAAAA,yCAAyC,CACxCrB,WADwC,EAExC,wBAFwC,CAAzC;AAIAqB,EAAAA,yCAAyC,CAAErB,WAAF,EAAe,gBAAf,CAAzC;AACA,CAZD;;AAcA,eAAeH,iBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n *\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst {\n\t\tstorage = DEFAULT_STORAGE,\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = options;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = merge( {}, initialState, persistedState );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * interface store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the interface\n * package.\n */\nexport function migrateFeaturePreferencesToInterfaceStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst state = persistence.get();\n\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\tconst sourceFeatures = sourcePreferences?.features;\n\n\tif ( sourceFeatures ) {\n\t\tconst targetFeatures =\n\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! targetFeatures?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...targetFeatures,\n\t\t\t\t\t\t[ sourceStoreName ]: sourceFeatures,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove feature preferences from the source.\n\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}\n}\n\n/**\n * Deprecated: Remove this function and the code in WordPress Core that calls\n * it once WordPress 6.0 is released.\n */\n\npersistencePlugin.__unstableMigrate = ( pluginOptions ) => {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\tmigrateFeaturePreferencesToInterfaceStore(\n\t\tpersistence,\n\t\t'core/edit-widgets'\n\t);\n\tmigrateFeaturePreferencesToInterfaceStore(\n\t\tpersistence,\n\t\t'core/customize-widgets'\n\t);\n\tmigrateFeaturePreferencesToInterfaceStore( persistence, 'core/edit-post' );\n};\n\nexport default persistencePlugin;\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/plugins/persistence/index.js"],"names":["merge","isPlainObject","defaultStorage","combineReducers","DEFAULT_STORAGE","DEFAULT_STORAGE_KEY","withLazySameState","reducer","state","action","nextState","createPersistenceInterface","options","storage","storageKey","data","getData","undefined","persisted","getItem","JSON","parse","error","setData","key","value","setItem","stringify","get","set","persistencePlugin","registry","pluginOptions","persistence","createPersistOnChange","getState","storeName","keys","getPersistedState","Array","isArray","reducers","reduce","accumulator","Object","assign","lastState","registerStore","persist","persistedState","initialState","type","store","subscribe","migrateFeaturePreferencesToPreferencesStore","sourceStoreName","preferencesStoreName","interfaceStoreName","interfaceFeatures","preferences","features","sourceFeatures","featuresToMigrate","targetFeatures","otherInterfaceFeatures","sourcePreferences","migrateIndividualPreferenceToPreferencesStore","sourcePreference","targetPreference","allPreferences","targetPreferences","allSourcePreferences","migrateFeaturePreferencesToInterfaceStore","__unstableMigrate"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAT,EAAgBC,aAAhB,QAAqC,QAArC;AAEA;AACA;AACA;;AACA,OAAOC,cAAP,MAA2B,mBAA3B;AACA,SAASC,eAAT,QAAgC,QAAhC;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,eAAe,GAAGF,cAAxB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMG,mBAAmB,GAAG,SAA5B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,O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,CAC1CrB,WAD0C,EAE1C,mBAF0C,CAA3C;AAIAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,wBAF0C,CAA3C;AAIAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,gBAF0C,CAA3C;AAIAiC,EAAAA,6CAA6C,CAC5CjC,WAD4C,EAE5C,gBAF4C,EAG5C,kBAH4C,CAA7C;AAKAqB,EAAAA,2CAA2C,CAC1CrB,WAD0C,EAE1C,gBAF0C,CAA3C;AAIAiC,EAAAA,6CAA6C,CAC5CjC,WAD4C,EAE5C,gBAF4C,EAG5C,YAH4C,CAA7C;AAKA,CA7BD;;AA+BA,eAAeH,iBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport { merge, isPlainObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\n\n/** @typedef {import('../../registry').WPDataRegistry} WPDataRegistry */\n\n/** @typedef {import('../../registry').WPDataPlugin} WPDataPlugin */\n\n/**\n * @typedef {Object} WPDataPersistencePluginOptions Persistence plugin options.\n *\n * @property {Storage} storage Persistent storage implementation. This must\n * at least implement `getItem` and `setItem` of\n * the Web Storage API.\n * @property {string} storageKey Key on which to set in persistent storage.\n *\n */\n\n/**\n * Default plugin storage.\n *\n * @type {Storage}\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n *\n * @type {string}\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param {Function} reducer Original reducer.\n *\n * @return {Function} Enhanced reducer.\n */\nexport const withLazySameState = ( reducer ) => ( state, action ) => {\n\tif ( action.nextState === state ) {\n\t\treturn state;\n\t}\n\n\treturn reducer( state, action );\n};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param {WPDataPersistencePluginOptions} options Plugin options.\n *\n * @return {Object} Persistence interface.\n */\nexport function createPersistenceInterface( options ) {\n\tconst {\n\t\tstorage = DEFAULT_STORAGE,\n\t\tstorageKey = DEFAULT_STORAGE_KEY,\n\t} = options;\n\n\tlet data;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return {Object} Persisted data.\n\t */\n\tfunction getData() {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param {string} key Key to update.\n\t * @param {*} value Updated value.\n\t */\n\tfunction setData( key, value ) {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param {WPDataRegistry} registry Data registry.\n * @param {?WPDataPersistencePluginOptions} pluginOptions Plugin options.\n *\n * @return {WPDataPlugin} Data plugin.\n */\nfunction persistencePlugin( registry, pluginOptions ) {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param {Function} getState Function which returns current state.\n\t * @param {string} storeName Store name.\n\t * @param {?Array<string>} keys Optional subset of keys to save.\n\t *\n\t * @return {Function} Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange( getState, storeName, keys ) {\n\t\tlet getPersistedState;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t( accumulator, key ) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: ( state, action ) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = ( state, action ) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore( storeName, options ) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = merge( {}, initialState, persistedState );\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * preferences store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the preferences\n * package.\n */\nexport function migrateFeaturePreferencesToPreferencesStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst interfaceStoreName = 'core/interface';\n\n\tconst state = persistence.get();\n\n\t// Features most recently (and briefly) lived in the interface package.\n\t// If data exists there, prioritize using that for the migration. If not\n\t// also check the original package as the user may have updated from an\n\t// older block editor version.\n\tconst interfaceFeatures =\n\t\tstate[ interfaceStoreName ]?.preferences?.features?.[ sourceStoreName ];\n\tconst sourceFeatures = state[ sourceStoreName ]?.preferences?.features;\n\tconst featuresToMigrate = interfaceFeatures\n\t\t? interfaceFeatures\n\t\t: sourceFeatures;\n\n\tif ( featuresToMigrate ) {\n\t\tconst targetFeatures = state[ preferencesStoreName ]?.preferences;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! targetFeatures?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( preferencesStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...targetFeatures,\n\t\t\t\t\t[ sourceStoreName ]: featuresToMigrate,\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove migrated feature preferences from `interface`.\n\t\t\tif ( interfaceFeatures ) {\n\t\t\t\tconst otherInterfaceFeatures =\n\t\t\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\t\tpreferences: {\n\t\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t\t...otherInterfaceFeatures,\n\t\t\t\t\t\t\t[ sourceStoreName ]: undefined,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\t// Remove migrated feature preferences from the source.\n\t\t\tif ( sourceFeatures ) {\n\t\t\t\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\n\t\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\t\tpreferences: {\n\t\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\t\tfeatures: undefined,\n\t\t\t\t\t},\n\t\t\t\t} );\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function migrateIndividualPreferenceToPreferencesStore(\n\tpersistence,\n\tsourceStoreName,\n\tkey\n) {\n\tconst preferencesStoreName = 'core/preferences';\n\tconst state = persistence.get();\n\tconst sourcePreference = state[ sourceStoreName ]?.preferences?.[ key ];\n\n\t// There's nothing to migrate, exit early.\n\tif ( ! sourcePreference ) {\n\t\treturn;\n\t}\n\n\tconst targetPreference =\n\t\tstate[ preferencesStoreName ]?.preferences?.[ sourceStoreName ]?.[\n\t\t\tkey\n\t\t];\n\n\t// There's existing data at the target, so don't overwrite it, exit early.\n\tif ( targetPreference ) {\n\t\treturn;\n\t}\n\n\tconst allPreferences = state[ preferencesStoreName ]?.preferences;\n\tconst targetPreferences =\n\t\tstate[ preferencesStoreName ]?.preferences?.[ sourceStoreName ];\n\n\tpersistence.set( preferencesStoreName, {\n\t\tpreferences: {\n\t\t\t...allPreferences,\n\t\t\t[ sourceStoreName ]: {\n\t\t\t\t...targetPreferences,\n\t\t\t\t[ key ]: sourcePreference,\n\t\t\t},\n\t\t},\n\t} );\n\n\t// Remove migrated feature preferences from the source.\n\tconst allSourcePreferences = state[ sourceStoreName ]?.preferences;\n\tpersistence.set( sourceStoreName, {\n\t\tpreferences: {\n\t\t\t...allSourcePreferences,\n\t\t\t[ key ]: undefined,\n\t\t},\n\t} );\n}\n\n/**\n * Move the 'features' object in local storage from the sourceStoreName to the\n * interface store.\n *\n * @param {Object} persistence The persistence interface.\n * @param {string} sourceStoreName The name of the store that has persisted\n * preferences to migrate to the interface\n * package.\n */\nexport function migrateFeaturePreferencesToInterfaceStore(\n\tpersistence,\n\tsourceStoreName\n) {\n\tconst interfaceStoreName = 'core/interface';\n\tconst state = persistence.get();\n\tconst sourcePreferences = state[ sourceStoreName ]?.preferences;\n\tconst sourceFeatures = sourcePreferences?.features;\n\n\tif ( sourceFeatures ) {\n\t\tconst targetFeatures =\n\t\t\tstate[ interfaceStoreName ]?.preferences?.features;\n\n\t\t// Avoid migrating features again if they've previously been migrated.\n\t\tif ( ! targetFeatures?.[ sourceStoreName ] ) {\n\t\t\t// Set the feature values in the interface store, the features\n\t\t\t// object is keyed by 'scope', which matches the store name for\n\t\t\t// the source.\n\t\t\tpersistence.set( interfaceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\tfeatures: {\n\t\t\t\t\t\t...targetFeatures,\n\t\t\t\t\t\t[ sourceStoreName ]: sourceFeatures,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t} );\n\n\t\t\t// Remove feature preferences from the source.\n\t\t\tpersistence.set( sourceStoreName, {\n\t\t\t\tpreferences: {\n\t\t\t\t\t...sourcePreferences,\n\t\t\t\t\tfeatures: undefined,\n\t\t\t\t},\n\t\t\t} );\n\t\t}\n\t}\n}\n\npersistencePlugin.__unstableMigrate = ( pluginOptions ) => {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-widgets'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/customize-widgets'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-post'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-post',\n\t\t'hiddenBlockTypes'\n\t);\n\tmigrateFeaturePreferencesToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-site'\n\t);\n\tmigrateIndividualPreferenceToPreferencesStore(\n\t\tpersistence,\n\t\t'core/edit-site',\n\t\t'editorMode'\n\t);\n};\n\nexport default persistencePlugin;\n"]}
|
|
@@ -306,22 +306,33 @@ function mapResolveSelectors(selectors, store) {
|
|
|
306
306
|
args[_key3] = arguments[_key3];
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
return new Promise(resolve => {
|
|
309
|
+
return new Promise((resolve, reject) => {
|
|
310
310
|
const hasFinished = () => selectors.hasFinishedResolution(selectorName, args);
|
|
311
311
|
|
|
312
|
-
const
|
|
312
|
+
const finalize = result => {
|
|
313
|
+
const hasFailed = selectors.hasResolutionFailed(selectorName, args);
|
|
314
|
+
|
|
315
|
+
if (hasFailed) {
|
|
316
|
+
const error = selectors.getResolutionError(selectorName, args);
|
|
317
|
+
reject(error);
|
|
318
|
+
} else {
|
|
319
|
+
resolve(result);
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const getResult = () => selector.apply(null, args); // Trigger the selector (to trigger the resolver)
|
|
313
324
|
|
|
314
325
|
|
|
315
326
|
const result = getResult();
|
|
316
327
|
|
|
317
328
|
if (hasFinished()) {
|
|
318
|
-
return
|
|
329
|
+
return finalize(result);
|
|
319
330
|
}
|
|
320
331
|
|
|
321
332
|
const unsubscribe = store.subscribe(() => {
|
|
322
333
|
if (hasFinished()) {
|
|
323
334
|
unsubscribe();
|
|
324
|
-
|
|
335
|
+
finalize(getResult());
|
|
325
336
|
}
|
|
326
337
|
});
|
|
327
338
|
});
|
|
@@ -349,8 +360,8 @@ function mapResolvers(resolvers, selectors, store, resolversCache) {
|
|
|
349
360
|
}
|
|
350
361
|
|
|
351
362
|
return { ...resolver,
|
|
352
|
-
//
|
|
353
|
-
fulfill: resolver //
|
|
363
|
+
// Copy the enumerable properties of the resolver function.
|
|
364
|
+
fulfill: resolver // Add the fulfill method.
|
|
354
365
|
|
|
355
366
|
};
|
|
356
367
|
});
|
|
@@ -387,8 +398,13 @@ function mapResolvers(resolvers, selectors, store, resolversCache) {
|
|
|
387
398
|
setTimeout(async () => {
|
|
388
399
|
resolversCache.clear(selectorName, args);
|
|
389
400
|
store.dispatch(metadataActions.startResolution(selectorName, args));
|
|
390
|
-
|
|
391
|
-
|
|
401
|
+
|
|
402
|
+
try {
|
|
403
|
+
await fulfillResolver(store, mappedResolvers, selectorName, ...args);
|
|
404
|
+
store.dispatch(metadataActions.finishResolution(selectorName, args));
|
|
405
|
+
} catch (error) {
|
|
406
|
+
store.dispatch(metadataActions.failResolution(selectorName, args, error));
|
|
407
|
+
}
|
|
392
408
|
});
|
|
393
409
|
}
|
|
394
410
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/redux-store/index.js"],"names":["createStore","applyMiddleware","flowRight","get","mapValues","omit","combineReducers","EquivalentKeyMap","createReduxRoutineMiddleware","builtinControls","promise","createResolversCacheMiddleware","createThunkMiddleware","metadataReducer","metadataSelectors","metadataActions","trimUndefinedValues","array","result","i","length","undefined","splice","createResolversCache","cache","isRunning","selectorName","args","clear","delete","markAsRunning","set","createReduxStore","key","options","name","instantiate","registry","reducer","thunkArgs","dispatch","Object","assign","action","store","getActions","select","selector","__unstableOriginalGetState","getSelectors","resolveSelect","getResolveSelectors","instantiateReduxStore","resolversCache","resolvers","actions","mapActions","selectors","mapSelectors","state","metadata","isRegistrySelector","root","mapResolvers","resolveSelectors","mapResolveSelectors","getState","subscribe","listener","lastState","hasChanged","controls","normalizedControls","control","isRegistryControl","middlewares","enhancers","window","__REDUX_DEVTOOLS_EXTENSION__","push","instanceId","initialState","enhancedReducer","createStateSelector","registrySelector","runSelector","argsLength","arguments","Array","hasResolver","createBoundAction","Promise","resolve","hasFinished","hasFinishedResolution","getResult","apply","unsubscribe","mappedResolvers","resolver","fulfill","mapSelector","selectorResolver","fulfillSelector","isFulfilled","hasStartedResolution","setTimeout","startResolution","fulfillResolver","finishResolution"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,eAAtB,QAA6C,OAA7C;AACA,SAASC,SAAT,EAAoBC,GAApB,EAAyBC,SAAzB,EAAoCC,IAApC,QAAgD,QAAhD;AACA,OAAOC,eAAP,MAA4B,wBAA5B;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,OAAOC,4BAAP,MAAyC,0BAAzC;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,aAAhC;AACA,OAAOC,OAAP,MAAoB,uBAApB;AACA,OAAOC,8BAAP,MAA2C,+BAA3C;AACA,OAAOC,qBAAP,MAAkC,oBAAlC;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AACA,OAAO,KAAKC,iBAAZ,MAAmC,sBAAnC;AACA,OAAO,KAAKC,eAAZ,MAAiC,oBAAjC;AAEA;;AACA;;AACA;;AAEA,MAAMC,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAMC,MAAM,GAAG,CAAE,GAAGD,KAAL,CAAf;;AACA,OAAM,IAAIE,CAAC,GAAGD,MAAM,CAACE,MAAP,GAAgB,CAA9B,EAAiCD,CAAC,IAAI,CAAtC,EAAyCA,CAAC,EAA1C,EAA+C;AAC9C,QAAKD,MAAM,CAAEC,CAAF,CAAN,KAAgBE,SAArB,EAAiC;AAChCH,MAA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B,EAIpB,GAAGC,IAJiB,CAArB;AAMAiB,UAAAA,KAAK,CAACJ,QAAN,CACCzB,eAAe,CAAC8F,gBAAhB,CAAkCnF,YAAlC,EAAgDC,IAAhD,CADD;AAGA,SAdS,CAAV;AAeA;;AAED4E,MAAAA,eAAe,CAAE,GAAG5E,IAAL,CAAf;AACA,aAAOoB,QAAQ,CAAE,GAAGpB,IAAL,CAAf;AACA,KA7CD;;AA8CA2E,IAAAA,gBAAgB,CAACb,WAAjB,GAA+B,IAA/B;AACA,WAAOa,gBAAP;AACA,GAvDD;;AAyDA,SAAO;AACNhD,IAAAA,SAAS,EAAE4C,eADL;AAENzC,IAAAA,SAAS,EAAErD,SAAS,CAAEqD,SAAF,EAAa4C,WAAb;AAFd,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeO,eAAf,CAAgChE,KAAhC,EAAuCU,SAAvC,EAAkD5B,YAAlD,EAA0E;AACzE,QAAMyE,QAAQ,GAAGhG,GAAG,CAAEmD,SAAF,EAAa,CAAE5B,YAAF,CAAb,CAApB;;AACA,MAAK,CAAEyE,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAPxE,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMgB,MAAM,GAAGwD,QAAQ,CAACC,OAAT,CAAkB,GAAGzE,IAArB,CAAf;;AACA,MAAKgB,MAAL,EAAc;AACb,UAAMC,KAAK,CAACJ,QAAN,CAAgBG,MAAhB,CAAN;AACA;AACD","sourcesContent":["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport { flowRight, get, mapValues, omit } from 'lodash';\nimport combineReducers from 'turbo-combine-reducers';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport createReduxRoutineMiddleware from '@wordpress/redux-routine';\n\n/**\n * Internal dependencies\n */\nimport { builtinControls } from '../controls';\nimport promise from '../promise-middleware';\nimport createResolversCacheMiddleware from '../resolvers-cache-middleware';\nimport createThunkMiddleware from './thunk-middleware';\nimport metadataReducer from './metadata/reducer';\nimport * as metadataSelectors from './metadata/selectors';\nimport * as metadataActions from './metadata/actions';\n\n/** @typedef {import('../types').DataRegistry} DataRegistry */\n/** @typedef {import('../types').StoreDescriptor} StoreDescriptor */\n/** @typedef {import('../types').ReduxStoreConfig} ReduxStoreConfig */\n\nconst trimUndefinedValues = ( array ) => {\n\tconst result = [ ...array ];\n\tfor ( let i = result.length - 1; i >= 0; i-- ) {\n\t\tif ( result[ i ] === undefined ) {\n\t\t\tresult.splice( i, 1 );\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * Create a cache to track whether resolvers started running or not.\n *\n * @return {Object} Resolvers Cache.\n */\nfunction createResolversCache() {\n\tconst cache = {};\n\treturn {\n\t\tisRunning( selectorName, args ) {\n\t\t\treturn (\n\t\t\t\tcache[ selectorName ] &&\n\t\t\t\tcache[ selectorName ].get( trimUndefinedValues( args ) )\n\t\t\t);\n\t\t},\n\n\t\tclear( selectorName, args ) {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( trimUndefinedValues( args ) );\n\t\t\t}\n\t\t},\n\n\t\tmarkAsRunning( selectorName, args ) {\n\t\t\tif ( ! cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ] = new EquivalentKeyMap();\n\t\t\t}\n\n\t\t\tcache[ selectorName ].set( trimUndefinedValues( args ), true );\n\t\t},\n\t};\n}\n\n/**\n * Creates a data store descriptor for the provided Redux store configuration containing\n * properties describing reducer, actions, selectors, controls and resolvers.\n *\n * @example\n * ```js\n * import { createReduxStore } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * ```\n *\n * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor} Store Object.\n */\nexport default function createReduxStore( key, options ) {\n\treturn {\n\t\tname: key,\n\t\tinstantiate: ( registry ) => {\n\t\t\tconst reducer = options.reducer;\n\t\t\tconst thunkArgs = {\n\t\t\t\tregistry,\n\t\t\t\tget dispatch() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( action ) => store.dispatch( action ),\n\t\t\t\t\t\tgetActions()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget select() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\tselector( store.__unstableOriginalGetState() ),\n\t\t\t\t\t\tgetSelectors()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget resolveSelect() {\n\t\t\t\t\treturn getResolveSelectors();\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst store = instantiateReduxStore(\n\t\t\t\tkey,\n\t\t\t\toptions,\n\t\t\t\tregistry,\n\t\t\t\tthunkArgs\n\t\t\t);\n\t\t\tconst resolversCache = createResolversCache();\n\n\t\t\tlet resolvers;\n\t\t\tconst actions = mapActions(\n\t\t\t\t{\n\t\t\t\t\t...metadataActions,\n\t\t\t\t\t...options.actions,\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\n\t\t\tlet selectors = mapSelectors(\n\t\t\t\t{\n\t\t\t\t\t...mapValues(\n\t\t\t\t\t\tmetadataSelectors,\n\t\t\t\t\t\t( selector ) => ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.metadata, ...args )\n\t\t\t\t\t),\n\t\t\t\t\t...mapValues( options.selectors, ( selector ) => {\n\t\t\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\t\t\tselector.registry = registry;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.root, ...args );\n\t\t\t\t\t} ),\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\t\t\tif ( options.resolvers ) {\n\t\t\t\tconst result = mapResolvers(\n\t\t\t\t\toptions.resolvers,\n\t\t\t\t\tselectors,\n\t\t\t\t\tstore,\n\t\t\t\t\tresolversCache\n\t\t\t\t);\n\t\t\t\tresolvers = result.resolvers;\n\t\t\t\tselectors = result.selectors;\n\t\t\t}\n\n\t\t\tconst resolveSelectors = mapResolveSelectors( selectors, store );\n\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\n\n\t\t\t// We have some modules monkey-patching the store object\n\t\t\t// It's wrong to do so but until we refactor all of our effects to controls\n\t\t\t// We need to keep the same \"store\" instance here.\n\t\t\tstore.__unstableOriginalGetState = store.getState;\n\t\t\tstore.getState = () => store.__unstableOriginalGetState().root;\n\n\t\t\t// Customize subscribe behavior to call listeners only on effective change,\n\t\t\t// not on every dispatch.\n\t\t\tconst subscribe =\n\t\t\t\tstore &&\n\t\t\t\t( ( listener ) => {\n\t\t\t\t\tlet lastState = store.__unstableOriginalGetState();\n\t\t\t\t\treturn store.subscribe( () => {\n\t\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\t\t\tconst hasChanged = state !== lastState;\n\t\t\t\t\t\tlastState = state;\n\n\t\t\t\t\t\tif ( hasChanged ) {\n\t\t\t\t\t\t\tlistener();\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\t// This can be simplified to just { subscribe, getSelectors, getActions }\n\t\t\t// Once we remove the use function.\n\t\t\treturn {\n\t\t\t\treducer,\n\t\t\t\tstore,\n\t\t\t\tactions,\n\t\t\t\tselectors,\n\t\t\t\tresolvers,\n\t\t\t\tgetSelectors,\n\t\t\t\tgetResolveSelectors,\n\t\t\t\tgetActions,\n\t\t\t\tsubscribe,\n\t\t\t};\n\t\t},\n\t};\n}\n\n/**\n * Creates a redux store for a namespace.\n *\n * @param {string} key Unique namespace identifier.\n * @param {Object} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n * @param {DataRegistry} registry Registry reference.\n * @param {Object} thunkArgs Argument object for the thunk middleware.\n * @return {Object} Newly created redux store.\n */\nfunction instantiateReduxStore( key, options, registry, thunkArgs ) {\n\tconst controls = {\n\t\t...options.controls,\n\t\t...builtinControls,\n\t};\n\n\tconst normalizedControls = mapValues( controls, ( control ) =>\n\t\tcontrol.isRegistryControl ? control( registry ) : control\n\t);\n\n\tconst middlewares = [\n\t\tcreateResolversCacheMiddleware( registry, key ),\n\t\tpromise,\n\t\tcreateReduxRoutineMiddleware( normalizedControls ),\n\t\tcreateThunkMiddleware( thunkArgs ),\n\t];\n\n\tconst enhancers = [ applyMiddleware( ...middlewares ) ];\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__REDUX_DEVTOOLS_EXTENSION__\n\t) {\n\t\tenhancers.push(\n\t\t\twindow.__REDUX_DEVTOOLS_EXTENSION__( {\n\t\t\t\tname: key,\n\t\t\t\tinstanceId: key,\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst { reducer, initialState } = options;\n\tconst enhancedReducer = combineReducers( {\n\t\tmetadata: metadataReducer,\n\t\troot: reducer,\n\t} );\n\n\treturn createStore(\n\t\tenhancedReducer,\n\t\t{ root: initialState },\n\t\tflowRight( enhancers )\n\t);\n}\n\n/**\n * Maps selectors to a store.\n *\n * @param {Object} selectors Selectors to register. Keys will be used as the\n * public facing API. Selectors will get passed the\n * state as first argument.\n * @param {Object} store The store to which the selectors should be mapped.\n * @return {Object} Selectors mapped to the provided store.\n */\nfunction mapSelectors( selectors, store ) {\n\tconst createStateSelector = ( registrySelector ) => {\n\t\tconst selector = function runSelector() {\n\t\t\t// This function is an optimized implementation of:\n\t\t\t//\n\t\t\t// selector( store.getState(), ...arguments )\n\t\t\t//\n\t\t\t// Where the above would incur an `Array#concat` in its application,\n\t\t\t// the logic here instead efficiently constructs an arguments array via\n\t\t\t// direct assignment.\n\t\t\tconst argsLength = arguments.length;\n\t\t\tconst args = new Array( argsLength + 1 );\n\t\t\targs[ 0 ] = store.__unstableOriginalGetState();\n\t\t\tfor ( let i = 0; i < argsLength; i++ ) {\n\t\t\t\targs[ i + 1 ] = arguments[ i ];\n\t\t\t}\n\n\t\t\treturn registrySelector( ...args );\n\t\t};\n\t\tselector.hasResolver = false;\n\t\treturn selector;\n\t};\n\n\treturn mapValues( selectors, createStateSelector );\n}\n\n/**\n * Maps actions to dispatch from a given store.\n *\n * @param {Object} actions Actions to register.\n * @param {Object} store The redux store to which the actions should be mapped.\n *\n * @return {Object} Actions mapped to the redux store provided.\n */\nfunction mapActions( actions, store ) {\n\tconst createBoundAction = ( action ) => ( ...args ) => {\n\t\treturn Promise.resolve( store.dispatch( action( ...args ) ) );\n\t};\n\n\treturn mapValues( actions, createBoundAction );\n}\n\n/**\n * Maps selectors to functions that return a resolution promise for them\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their resolution functions.\n */\nfunction mapResolveSelectors( selectors, store ) {\n\treturn mapValues(\n\t\tomit( selectors, [\n\t\t\t'getIsResolving',\n\t\t\t'hasStartedResolution',\n\t\t\t'hasFinishedResolution',\n\t\t\t'isResolving',\n\t\t\t'getCachedResolvers',\n\t\t] ),\n\t\t( selector, selectorName ) => ( ...args ) =>\n\t\t\tnew Promise( ( resolve ) => {\n\t\t\t\tconst hasFinished = () =>\n\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args );\n\t\t\t\tconst getResult = () => selector.apply( null, args );\n\t\t\t\t// trigger the selector (to trigger the resolver)\n\t\t\t\tconst result = getResult();\n\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\treturn resolve( result );\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tresolve( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} )\n\t);\n}\n\n/**\n * Returns resolvers with matched selectors for a given namespace.\n * Resolvers are side effects invoked once per argument set of a given selector call,\n * used in ensuring that the data needs for the selector are satisfied.\n *\n * @param {Object} resolvers Resolvers to register.\n * @param {Object} selectors The current selectors to be modified.\n * @param {Object} store The redux store to which the resolvers should be mapped.\n * @param {Object} resolversCache Resolvers Cache.\n */\nfunction mapResolvers( resolvers, selectors, store, resolversCache ) {\n\t// The `resolver` can be either a function that does the resolution, or, in more advanced\n\t// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`.\n\t// Here we normalize the `resolver` function to an object with `fulfill` method.\n\tconst mappedResolvers = mapValues( resolvers, ( resolver ) => {\n\t\tif ( resolver.fulfill ) {\n\t\t\treturn resolver;\n\t\t}\n\n\t\treturn {\n\t\t\t...resolver, // copy the enumerable properties of the resolver function\n\t\t\tfulfill: resolver, // add the fulfill method\n\t\t};\n\t} );\n\n\tconst mapSelector = ( selector, selectorName ) => {\n\t\tconst resolver = resolvers[ selectorName ];\n\t\tif ( ! resolver ) {\n\t\t\tselector.hasResolver = false;\n\t\t\treturn selector;\n\t\t}\n\n\t\tconst selectorResolver = ( ...args ) => {\n\t\t\tasync function fulfillSelector() {\n\t\t\t\tconst state = store.getState();\n\n\t\t\t\tif (\n\t\t\t\t\tresolversCache.isRunning( selectorName, args ) ||\n\t\t\t\t\t( typeof resolver.isFulfilled === 'function' &&\n\t\t\t\t\t\tresolver.isFulfilled( state, ...args ) )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { metadata } = store.__unstableOriginalGetState();\n\n\t\t\t\tif (\n\t\t\t\t\tmetadataSelectors.hasStartedResolution(\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tresolversCache.markAsRunning( selectorName, args );\n\n\t\t\t\tsetTimeout( async () => {\n\t\t\t\t\tresolversCache.clear( selectorName, args );\n\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\tmetadataActions.startResolution( selectorName, args )\n\t\t\t\t\t);\n\t\t\t\t\tawait fulfillResolver(\n\t\t\t\t\t\tstore,\n\t\t\t\t\t\tmappedResolvers,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t...args\n\t\t\t\t\t);\n\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\tmetadataActions.finishResolution( selectorName, args )\n\t\t\t\t\t);\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfulfillSelector( ...args );\n\t\t\treturn selector( ...args );\n\t\t};\n\t\tselectorResolver.hasResolver = true;\n\t\treturn selectorResolver;\n\t};\n\n\treturn {\n\t\tresolvers: mappedResolvers,\n\t\tselectors: mapValues( selectors, mapSelector ),\n\t};\n}\n\n/**\n * Calls a resolver given arguments\n *\n * @param {Object} store Store reference, for fulfilling via resolvers\n * @param {Object} resolvers Store Resolvers\n * @param {string} selectorName Selector name to fulfill.\n * @param {Array} args Selector Arguments.\n */\nasync function fulfillResolver( store, resolvers, selectorName, ...args ) {\n\tconst resolver = get( resolvers, [ selectorName ] );\n\tif ( ! resolver ) {\n\t\treturn;\n\t}\n\n\tconst action = resolver.fulfill( ...args );\n\tif ( action ) {\n\t\tawait store.dispatch( action );\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/redux-store/index.js"],"names":["createStore","applyMiddleware","flowRight","get","mapValues","omit","combineReducers","EquivalentKeyMap","createReduxRoutineMiddleware","builtinControls","promise","createResolversCacheMiddleware","createThunkMiddleware","metadataReducer","metadataSelectors","metadataActions","trimUndefinedValues","array","result","i","length","undefined","splice","createResolversCache","cache","isRunning","selectorName","args","clear","delete","markAsRunning","set","createReduxStore","key","options","name","instantiate","registry","reducer","thunkArgs","dispatch","Object","assign","action","store","getActions","select","selector","__unstableOriginalGetState","getSelectors","resolveSelect","getResolveSelectors","instantiateReduxStore","resolversCache","resolvers","actions","mapActions","selectors","mapSelectors","state","metadata","isRegistrySelector","root","mapResolvers","resolveSelectors","mapResolveSelectors","getState","subscribe","listener","lastState","hasChanged","controls","normalizedControls","control","isRegistryControl","middlewares","enhancers","window","__REDUX_DEVTOOLS_EXTENSION__","push","instanceId","initialState","enhancedReducer","createStateSelector","registrySelector","runSelector","argsLength","arguments","Array","hasResolver","createBoundAction","Promise","resolve","reject","hasFinished","hasFinishedResolution","finalize","hasFailed","hasResolutionFailed","error","getResolutionError","getResult","apply","unsubscribe","mappedResolvers","resolver","fulfill","mapSelector","selectorResolver","fulfillSelector","isFulfilled","hasStartedResolution","setTimeout","startResolution","fulfillResolver","finishResolution","failResolution"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,eAAtB,QAA6C,OAA7C;AACA,SAASC,SAAT,EAAoBC,GAApB,EAAyBC,SAAzB,EAAoCC,IAApC,QAAgD,QAAhD;AACA,OAAOC,eAAP,MAA4B,wBAA5B;AACA,OAAOC,gBAAP,MAA6B,oBAA7B;AAEA;AACA;AACA;;AACA,OAAOC,4BAAP,MAAyC,0BAAzC;AAEA;AACA;AACA;;AACA,SAASC,eAAT,QAAgC,aAAhC;AACA,OAAOC,OAAP,MAAoB,uBAApB;AACA,OAAOC,8BAAP,MAA2C,+BAA3C;AACA,OAAOC,qBAAP,MAAkC,oBAAlC;AACA,OAAOC,eAAP,MAA4B,oBAA5B;AACA,OAAO,KAAKC,iBAAZ,MAAmC,sBAAnC;AACA,OAAO,KAAKC,eAAZ,MAAiC,oBAAjC;AAEA;;AACA;;AACA;;AAEA,MAAMC,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAMC,MAAM,GAAG,CAAE,GAAGD,KAAL,CAAf;;AACA,OAAM,IAAIE,CAAC,GAAGD,MAAM,CAACE,MAAP,GAAgB,CAA9B,EAAiCD,CAAC,IAAI,CAAtC,EAAyCA,CAAC,EAA1C,EAA+C;AAC9C,QAAKD,MAAM,CAAEC,CAAF,CAAN,KAAgBE,SAAr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AK,CAAE+E,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAP9E,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMgB,MAAM,GAAG8D,QAAQ,CAACC,OAAT,CAAkB,GAAG/E,IAArB,CAAf;;AACA,MAAKgB,MAAL,EAAc;AACb,UAAMC,KAAK,CAACJ,QAAN,CAAgBG,MAAhB,CAAN;AACA;AACD","sourcesContent":["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport { flowRight, get, mapValues, omit } from 'lodash';\nimport combineReducers from 'turbo-combine-reducers';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport createReduxRoutineMiddleware from '@wordpress/redux-routine';\n\n/**\n * Internal dependencies\n */\nimport { builtinControls } from '../controls';\nimport promise from '../promise-middleware';\nimport createResolversCacheMiddleware from '../resolvers-cache-middleware';\nimport createThunkMiddleware from './thunk-middleware';\nimport metadataReducer from './metadata/reducer';\nimport * as metadataSelectors from './metadata/selectors';\nimport * as metadataActions from './metadata/actions';\n\n/** @typedef {import('../types').DataRegistry} DataRegistry */\n/** @typedef {import('../types').StoreDescriptor} StoreDescriptor */\n/** @typedef {import('../types').ReduxStoreConfig} ReduxStoreConfig */\n\nconst trimUndefinedValues = ( array ) => {\n\tconst result = [ ...array ];\n\tfor ( let i = result.length - 1; i >= 0; i-- ) {\n\t\tif ( result[ i ] === undefined ) {\n\t\t\tresult.splice( i, 1 );\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * Create a cache to track whether resolvers started running or not.\n *\n * @return {Object} Resolvers Cache.\n */\nfunction createResolversCache() {\n\tconst cache = {};\n\treturn {\n\t\tisRunning( selectorName, args ) {\n\t\t\treturn (\n\t\t\t\tcache[ selectorName ] &&\n\t\t\t\tcache[ selectorName ].get( trimUndefinedValues( args ) )\n\t\t\t);\n\t\t},\n\n\t\tclear( selectorName, args ) {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( trimUndefinedValues( args ) );\n\t\t\t}\n\t\t},\n\n\t\tmarkAsRunning( selectorName, args ) {\n\t\t\tif ( ! cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ] = new EquivalentKeyMap();\n\t\t\t}\n\n\t\t\tcache[ selectorName ].set( trimUndefinedValues( args ), true );\n\t\t},\n\t};\n}\n\n/**\n * Creates a data store descriptor for the provided Redux store configuration containing\n * properties describing reducer, actions, selectors, controls and resolvers.\n *\n * @example\n * ```js\n * import { createReduxStore } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * ```\n *\n * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor} Store Object.\n */\nexport default function createReduxStore( key, options ) {\n\treturn {\n\t\tname: key,\n\t\tinstantiate: ( registry ) => {\n\t\t\tconst reducer = options.reducer;\n\t\t\tconst thunkArgs = {\n\t\t\t\tregistry,\n\t\t\t\tget dispatch() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( action ) => store.dispatch( action ),\n\t\t\t\t\t\tgetActions()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget select() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\tselector( store.__unstableOriginalGetState() ),\n\t\t\t\t\t\tgetSelectors()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget resolveSelect() {\n\t\t\t\t\treturn getResolveSelectors();\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst store = instantiateReduxStore(\n\t\t\t\tkey,\n\t\t\t\toptions,\n\t\t\t\tregistry,\n\t\t\t\tthunkArgs\n\t\t\t);\n\t\t\tconst resolversCache = createResolversCache();\n\n\t\t\tlet resolvers;\n\t\t\tconst actions = mapActions(\n\t\t\t\t{\n\t\t\t\t\t...metadataActions,\n\t\t\t\t\t...options.actions,\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\n\t\t\tlet selectors = mapSelectors(\n\t\t\t\t{\n\t\t\t\t\t...mapValues(\n\t\t\t\t\t\tmetadataSelectors,\n\t\t\t\t\t\t( selector ) => ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.metadata, ...args )\n\t\t\t\t\t),\n\t\t\t\t\t...mapValues( options.selectors, ( selector ) => {\n\t\t\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\t\t\tselector.registry = registry;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.root, ...args );\n\t\t\t\t\t} ),\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\t\t\tif ( options.resolvers ) {\n\t\t\t\tconst result = mapResolvers(\n\t\t\t\t\toptions.resolvers,\n\t\t\t\t\tselectors,\n\t\t\t\t\tstore,\n\t\t\t\t\tresolversCache\n\t\t\t\t);\n\t\t\t\tresolvers = result.resolvers;\n\t\t\t\tselectors = result.selectors;\n\t\t\t}\n\n\t\t\tconst resolveSelectors = mapResolveSelectors( selectors, store );\n\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\n\n\t\t\t// We have some modules monkey-patching the store object\n\t\t\t// It's wrong to do so but until we refactor all of our effects to controls\n\t\t\t// We need to keep the same \"store\" instance here.\n\t\t\tstore.__unstableOriginalGetState = store.getState;\n\t\t\tstore.getState = () => store.__unstableOriginalGetState().root;\n\n\t\t\t// Customize subscribe behavior to call listeners only on effective change,\n\t\t\t// not on every dispatch.\n\t\t\tconst subscribe =\n\t\t\t\tstore &&\n\t\t\t\t( ( listener ) => {\n\t\t\t\t\tlet lastState = store.__unstableOriginalGetState();\n\t\t\t\t\treturn store.subscribe( () => {\n\t\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\t\t\tconst hasChanged = state !== lastState;\n\t\t\t\t\t\tlastState = state;\n\n\t\t\t\t\t\tif ( hasChanged ) {\n\t\t\t\t\t\t\tlistener();\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\t// This can be simplified to just { subscribe, getSelectors, getActions }\n\t\t\t// Once we remove the use function.\n\t\t\treturn {\n\t\t\t\treducer,\n\t\t\t\tstore,\n\t\t\t\tactions,\n\t\t\t\tselectors,\n\t\t\t\tresolvers,\n\t\t\t\tgetSelectors,\n\t\t\t\tgetResolveSelectors,\n\t\t\t\tgetActions,\n\t\t\t\tsubscribe,\n\t\t\t};\n\t\t},\n\t};\n}\n\n/**\n * Creates a redux store for a namespace.\n *\n * @param {string} key Unique namespace identifier.\n * @param {Object} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n * @param {DataRegistry} registry Registry reference.\n * @param {Object} thunkArgs Argument object for the thunk middleware.\n * @return {Object} Newly created redux store.\n */\nfunction instantiateReduxStore( key, options, registry, thunkArgs ) {\n\tconst controls = {\n\t\t...options.controls,\n\t\t...builtinControls,\n\t};\n\n\tconst normalizedControls = mapValues( controls, ( control ) =>\n\t\tcontrol.isRegistryControl ? control( registry ) : control\n\t);\n\n\tconst middlewares = [\n\t\tcreateResolversCacheMiddleware( registry, key ),\n\t\tpromise,\n\t\tcreateReduxRoutineMiddleware( normalizedControls ),\n\t\tcreateThunkMiddleware( thunkArgs ),\n\t];\n\n\tconst enhancers = [ applyMiddleware( ...middlewares ) ];\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__REDUX_DEVTOOLS_EXTENSION__\n\t) {\n\t\tenhancers.push(\n\t\t\twindow.__REDUX_DEVTOOLS_EXTENSION__( {\n\t\t\t\tname: key,\n\t\t\t\tinstanceId: key,\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst { reducer, initialState } = options;\n\tconst enhancedReducer = combineReducers( {\n\t\tmetadata: metadataReducer,\n\t\troot: reducer,\n\t} );\n\n\treturn createStore(\n\t\tenhancedReducer,\n\t\t{ root: initialState },\n\t\tflowRight( enhancers )\n\t);\n}\n\n/**\n * Maps selectors to a store.\n *\n * @param {Object} selectors Selectors to register. Keys will be used as the\n * public facing API. Selectors will get passed the\n * state as first argument.\n * @param {Object} store The store to which the selectors should be mapped.\n * @return {Object} Selectors mapped to the provided store.\n */\nfunction mapSelectors( selectors, store ) {\n\tconst createStateSelector = ( registrySelector ) => {\n\t\tconst selector = function runSelector() {\n\t\t\t// This function is an optimized implementation of:\n\t\t\t//\n\t\t\t// selector( store.getState(), ...arguments )\n\t\t\t//\n\t\t\t// Where the above would incur an `Array#concat` in its application,\n\t\t\t// the logic here instead efficiently constructs an arguments array via\n\t\t\t// direct assignment.\n\t\t\tconst argsLength = arguments.length;\n\t\t\tconst args = new Array( argsLength + 1 );\n\t\t\targs[ 0 ] = store.__unstableOriginalGetState();\n\t\t\tfor ( let i = 0; i < argsLength; i++ ) {\n\t\t\t\targs[ i + 1 ] = arguments[ i ];\n\t\t\t}\n\n\t\t\treturn registrySelector( ...args );\n\t\t};\n\t\tselector.hasResolver = false;\n\t\treturn selector;\n\t};\n\n\treturn mapValues( selectors, createStateSelector );\n}\n\n/**\n * Maps actions to dispatch from a given store.\n *\n * @param {Object} actions Actions to register.\n * @param {Object} store The redux store to which the actions should be mapped.\n *\n * @return {Object} Actions mapped to the redux store provided.\n */\nfunction mapActions( actions, store ) {\n\tconst createBoundAction = ( action ) => ( ...args ) => {\n\t\treturn Promise.resolve( store.dispatch( action( ...args ) ) );\n\t};\n\n\treturn mapValues( actions, createBoundAction );\n}\n\n/**\n * Maps selectors to functions that return a resolution promise for them\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their resolution functions.\n */\nfunction mapResolveSelectors( selectors, store ) {\n\treturn mapValues(\n\t\tomit( selectors, [\n\t\t\t'getIsResolving',\n\t\t\t'hasStartedResolution',\n\t\t\t'hasFinishedResolution',\n\t\t\t'isResolving',\n\t\t\t'getCachedResolvers',\n\t\t] ),\n\t\t( selector, selectorName ) => ( ...args ) =>\n\t\t\tnew Promise( ( resolve, reject ) => {\n\t\t\t\tconst hasFinished = () =>\n\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args );\n\t\t\t\tconst finalize = ( result ) => {\n\t\t\t\t\tconst hasFailed = selectors.hasResolutionFailed(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t\tif ( hasFailed ) {\n\t\t\t\t\t\tconst error = selectors.getResolutionError(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresolve( result );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst getResult = () => selector.apply( null, args );\n\t\t\t\t// Trigger the selector (to trigger the resolver)\n\t\t\t\tconst result = getResult();\n\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\treturn finalize( result );\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tfinalize( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} )\n\t);\n}\n\n/**\n * Returns resolvers with matched selectors for a given namespace.\n * Resolvers are side effects invoked once per argument set of a given selector call,\n * used in ensuring that the data needs for the selector are satisfied.\n *\n * @param {Object} resolvers Resolvers to register.\n * @param {Object} selectors The current selectors to be modified.\n * @param {Object} store The redux store to which the resolvers should be mapped.\n * @param {Object} resolversCache Resolvers Cache.\n */\nfunction mapResolvers( resolvers, selectors, store, resolversCache ) {\n\t// The `resolver` can be either a function that does the resolution, or, in more advanced\n\t// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`.\n\t// Here we normalize the `resolver` function to an object with `fulfill` method.\n\tconst mappedResolvers = mapValues( resolvers, ( resolver ) => {\n\t\tif ( resolver.fulfill ) {\n\t\t\treturn resolver;\n\t\t}\n\n\t\treturn {\n\t\t\t...resolver, // Copy the enumerable properties of the resolver function.\n\t\t\tfulfill: resolver, // Add the fulfill method.\n\t\t};\n\t} );\n\n\tconst mapSelector = ( selector, selectorName ) => {\n\t\tconst resolver = resolvers[ selectorName ];\n\t\tif ( ! resolver ) {\n\t\t\tselector.hasResolver = false;\n\t\t\treturn selector;\n\t\t}\n\n\t\tconst selectorResolver = ( ...args ) => {\n\t\t\tasync function fulfillSelector() {\n\t\t\t\tconst state = store.getState();\n\n\t\t\t\tif (\n\t\t\t\t\tresolversCache.isRunning( selectorName, args ) ||\n\t\t\t\t\t( typeof resolver.isFulfilled === 'function' &&\n\t\t\t\t\t\tresolver.isFulfilled( state, ...args ) )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { metadata } = store.__unstableOriginalGetState();\n\n\t\t\t\tif (\n\t\t\t\t\tmetadataSelectors.hasStartedResolution(\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tresolversCache.markAsRunning( selectorName, args );\n\n\t\t\t\tsetTimeout( async () => {\n\t\t\t\t\tresolversCache.clear( selectorName, args );\n\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\tmetadataActions.startResolution( selectorName, args )\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait fulfillResolver(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\tmappedResolvers,\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t...args\n\t\t\t\t\t\t);\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.finishResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch ( error ) {\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.failResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs,\n\t\t\t\t\t\t\t\terror\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfulfillSelector( ...args );\n\t\t\treturn selector( ...args );\n\t\t};\n\t\tselectorResolver.hasResolver = true;\n\t\treturn selectorResolver;\n\t};\n\n\treturn {\n\t\tresolvers: mappedResolvers,\n\t\tselectors: mapValues( selectors, mapSelector ),\n\t};\n}\n\n/**\n * Calls a resolver given arguments\n *\n * @param {Object} store Store reference, for fulfilling via resolvers\n * @param {Object} resolvers Store Resolvers\n * @param {string} selectorName Selector name to fulfill.\n * @param {Array} args Selector Arguments.\n */\nasync function fulfillResolver( store, resolvers, selectorName, ...args ) {\n\tconst resolver = get( resolvers, [ selectorName ] );\n\tif ( ! resolver ) {\n\t\treturn;\n\t}\n\n\tconst action = resolver.fulfill( ...args );\n\tif ( action ) {\n\t\tawait store.dispatch( action );\n\t}\n}\n"]}
|
|
@@ -31,13 +31,32 @@ export function finishResolution(selectorName, args) {
|
|
|
31
31
|
args
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns an action object used in signalling that selector resolution has
|
|
36
|
+
* failed.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} selectorName Name of selector for which resolver triggered.
|
|
39
|
+
* @param {unknown[]} args Arguments to associate for uniqueness.
|
|
40
|
+
* @param {Error|unknown} error The error that caused the failure.
|
|
41
|
+
*
|
|
42
|
+
* @return {{ type: 'FAIL_RESOLUTION', selectorName: string, args: unknown[], error: Error|unknown }} Action object.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
export function failResolution(selectorName, args, error) {
|
|
46
|
+
return {
|
|
47
|
+
type: 'FAIL_RESOLUTION',
|
|
48
|
+
selectorName,
|
|
49
|
+
args,
|
|
50
|
+
error
|
|
51
|
+
};
|
|
52
|
+
}
|
|
34
53
|
/**
|
|
35
54
|
* Returns an action object used in signalling that a batch of selector resolutions has
|
|
36
55
|
* started.
|
|
37
56
|
*
|
|
38
|
-
* @param {string}
|
|
57
|
+
* @param {string} selectorName Name of selector for which resolver triggered.
|
|
39
58
|
* @param {unknown[][]} args Array of arguments to associate for uniqueness, each item
|
|
40
|
-
*
|
|
59
|
+
* is associated to a resolution.
|
|
41
60
|
*
|
|
42
61
|
* @return {{ type: 'START_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.
|
|
43
62
|
*/
|
|
@@ -53,9 +72,9 @@ export function startResolutions(selectorName, args) {
|
|
|
53
72
|
* Returns an action object used in signalling that a batch of selector resolutions has
|
|
54
73
|
* completed.
|
|
55
74
|
*
|
|
56
|
-
* @param {string}
|
|
75
|
+
* @param {string} selectorName Name of selector for which resolver triggered.
|
|
57
76
|
* @param {unknown[][]} args Array of arguments to associate for uniqueness, each item
|
|
58
|
-
*
|
|
77
|
+
* is associated to a resolution.
|
|
59
78
|
*
|
|
60
79
|
* @return {{ type: 'FINISH_RESOLUTIONS', selectorName: string, args: unknown[][] }} Action object.
|
|
61
80
|
*/
|
|
@@ -67,6 +86,26 @@ export function finishResolutions(selectorName, args) {
|
|
|
67
86
|
args
|
|
68
87
|
};
|
|
69
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Returns an action object used in signalling that a batch of selector resolutions has
|
|
91
|
+
* completed and at least one of them has failed.
|
|
92
|
+
*
|
|
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.
|
|
96
|
+
* @param {(Error|unknown)[]} errors Array of errors to associate for uniqueness, each item
|
|
97
|
+
* is associated to a resolution.
|
|
98
|
+
* @return {{ type: 'FAIL_RESOLUTIONS', selectorName: string, args: unknown[], errors: Array<Error|unknown> }} Action object.
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
export function failResolutions(selectorName, args, errors) {
|
|
102
|
+
return {
|
|
103
|
+
type: 'FAIL_RESOLUTIONS',
|
|
104
|
+
selectorName,
|
|
105
|
+
args,
|
|
106
|
+
errors
|
|
107
|
+
};
|
|
108
|
+
}
|
|
70
109
|
/**
|
|
71
110
|
* Returns an action object used in signalling that we should invalidate the resolution cache.
|
|
72
111
|
*
|
|
@@ -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":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,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;;AACA,OAAO,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;;AACA,OAAO,SAASG,gBAAT,
|
|
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;AAC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,IAHM;AAINQ,IAAAA;AAJM,GAAP;AAMA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,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;;AACA,OAAO,SAASU,4BAAT,GAAwC;AAC9C,SAAO;AACNT,IAAAA,IAAI,EAAE;AADA,GAAP;AAGA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,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"]}
|