@wordpress/data 10.43.0 → 10.43.1-next.v.202604091042.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/plugins/persistence/index.cjs +1 -1
- package/build/plugins/persistence/index.cjs.map +2 -2
- package/build/plugins/persistence/storage/default.cjs +1 -1
- package/build/plugins/persistence/storage/default.cjs.map +2 -2
- package/build/registry.cjs +3 -3
- package/build/registry.cjs.map +2 -2
- package/build-module/plugins/persistence/index.mjs +1 -1
- package/build-module/plugins/persistence/index.mjs.map +2 -2
- package/build-module/plugins/persistence/storage/default.mjs +1 -1
- package/build-module/plugins/persistence/storage/default.mjs.map +2 -2
- package/build-module/registry.mjs +3 -3
- package/build-module/registry.mjs.map +2 -2
- package/package.json +9 -9
- package/src/plugins/persistence/index.ts +1 -1
- package/src/plugins/persistence/storage/default.ts +1 -1
- package/src/redux-store/metadata/test/selectors.js +1 -1
- package/src/registry.ts +3 -3
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/plugins/persistence/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\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 reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,6BAA8B;AAC9B,uBAAsB;AAKtB,qBAA2B;AAC3B,eAAgC;AA4BhC,IAAM,kBAAkB,eAAAA;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACuB;AACvB,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAqC;AAC7C,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\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 reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\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 {\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 key Key to update.\n\t * @param value Updated value.\n\t */\n\tfunction setData( key: string, value: unknown ): void {\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 registry Data registry.\n * @param pluginOptions Plugin options.\n *\n * @return Data plugin.\n */\nfunction persistencePlugin(\n\tregistry: DataRegistry,\n\tpluginOptions: PersistencePluginOptions\n): Partial< DataRegistry > {\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 getState Function which returns current state.\n\t * @param storeName Store name.\n\t * @param keys Optional subset of keys to save.\n\t *\n\t * @return Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange(\n\t\tgetState: () => unknown,\n\t\tstoreName: string,\n\t\tkeys: boolean | string[]\n\t): () => void {\n\t\tlet getPersistedState: ( state: any, action: any ) => any;\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(\n\t\t\t\t\taccumulator: Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t( state: any, action: any ) => any\n\t\t\t\t\t>,\n\t\t\t\t\tkey: string\n\t\t\t\t) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: (\n\t\t\t\t\t\t\tstate: unknown,\n\t\t\t\t\t\t\taction: { nextState: Record< string, unknown > }\n\t\t\t\t\t\t) => 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 = (\n\t\t\t\t_state: unknown,\n\t\t\t\taction: { nextState: unknown }\n\t\t\t) => 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(\n\t\t\tstoreName: string,\n\t\t\toptions: ReduxStoreConfig< any, any, any > & {\n\t\t\t\tpersist?: boolean | string[];\n\t\t\t}\n\t\t) {\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 = deepmerge(\n\t\t\t\t\t\tinitialState as Record< string, unknown >,\n\t\t\t\t\t\tpersistedState as Record< string, unknown >,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tisMergeableObject: isPlainObject,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\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\nexport default Object.assign( persistencePlugin, {\n\t__unstableMigrate: () => {},\n} );\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;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
3
3
|
"sources": ["../../../../src/plugins/persistence/storage/default.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA0B;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAA0B;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,QAAQ;AACP,YAAU,cAAAA;AACX;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": ["objectStorage"]
|
|
7
7
|
}
|
package/build/registry.cjs
CHANGED
|
@@ -162,7 +162,7 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
162
162
|
(0, import_lock_unlock.unlock)(store.store).registerPrivateSelectors(
|
|
163
163
|
(0, import_lock_unlock.unlock)(parent).privateSelectorsOf(name)
|
|
164
164
|
);
|
|
165
|
-
} catch
|
|
165
|
+
} catch {
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
return store;
|
|
@@ -248,14 +248,14 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
248
248
|
privateActionsOf: (name) => {
|
|
249
249
|
try {
|
|
250
250
|
return (0, import_lock_unlock.unlock)(stores[name].store).privateActions;
|
|
251
|
-
} catch
|
|
251
|
+
} catch {
|
|
252
252
|
return {};
|
|
253
253
|
}
|
|
254
254
|
},
|
|
255
255
|
privateSelectorsOf: (name) => {
|
|
256
256
|
try {
|
|
257
257
|
return (0, import_lock_unlock.unlock)(stores[name].store).privateSelectors;
|
|
258
|
-
} catch
|
|
258
|
+
} catch {
|
|
259
259
|
return {};
|
|
260
260
|
}
|
|
261
261
|
}
|
package/build/registry.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/registry.ts"],
|
|
4
|
-
"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 './lock-unlock';\nimport type {\n\tStoreDescriptor,\n\tStoreNameOrDescriptor,\n\tDataRegistry,\n\tDataPlugin,\n\tInternalStoreInstance,\n\tAnyConfig,\n\tReduxStoreConfig,\n} from './types';\n\nfunction getStoreName( storeNameOrDescriptor: StoreNameOrDescriptor ): string {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param storeConfigs Initial store configurations.\n * @param parent Parent registry.\n *\n * @return Data registry.\n */\nexport function createRegistry(\n\tstoreConfigs: Record< string, ReduxStoreConfig< any, any, any > > = {},\n\tparent: DataRegistry | null = null\n): DataRegistry {\n\tconst stores: Record< string, InternalStoreInstance > = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores: Set< string > | null = 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 listener Listener function.\n\t * @param storeNameOrDescriptor Optional store name.\n\t *\n\t * @return Unsubscribe function.\n\t */\n\tconst subscribe = (\n\t\tlistener: () => void,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t): ( () => void ) => {\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 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: 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< T >(\n\t\tthis: DataRegistry,\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t): T {\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 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 Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor: 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 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 containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor: 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 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: 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(\n\t\tattributes: Record< string, unknown >\n\t): Record< string, unknown > {\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\t( ...args: unknown[] ) => {\n\t\t\t\t\t\treturn ( registry as any )[ key ]( ...args );\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 name Store registry name.\n\t * @param createStoreFunc Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance(\n\t\tname: string,\n\t\tcreateStoreFunc: () => InternalStoreInstance\n\t): InternalStoreInstance {\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: any = createStoreFunc();\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: () => void ) => {\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 store Store descriptor.\n\t */\n\tfunction register( store: StoreDescriptor< AnyConfig > ) {\n\t\tregisterStoreInstance(\n\t\t\tstore.name,\n\t\t\t() => store.instantiate( registry ) as InternalStoreInstance\n\t\t);\n\t}\n\n\tfunction registerGenericStore(\n\t\tname: string,\n\t\tstore: InternalStoreInstance\n\t) {\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 storeName Unique namespace identifier.\n\t * @param options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return Registered store object.\n\t */\n\tfunction registerStore(\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance(\n\t\t\tstoreName,\n\t\t\t() =>\n\t\t\t\tcreateReduxStore( storeName, options ).instantiate(\n\t\t\t\t\tregistry\n\t\t\t\t) as InternalStoreInstance\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback: () => void ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\n\t}\n\n\tlet registry: DataRegistry = {\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} as DataRegistry;\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: DataPlugin, options?: Record< string, unknown > ) {\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(\n\t\tregistry as unknown as Record< string, unknown >\n\t);\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name: string ) => {\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 \u2013 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: string ) => {\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 as unknown as DataRegistry;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AAKvB,yBAA6B;AAC7B,mBAA0B;AAC1B,qBAA8B;AAC9B,yBAA6B;AAW7B,SAAS,aAAc,uBAAuD;AAC7E,SAAO,OAAO,0BAA0B,WACrC,wBACA,sBAAsB;AAC1B;AAWO,SAAS,eACf,eAAoE,CAAC,GACrE,SAA8B,MACf;AACf,QAAM,SAAkD,CAAC;AACzD,QAAM,cAAU,8BAAc;AAC9B,MAAI,kBAAwC;AAK5C,WAAS,iBAAiB;AACzB,YAAQ,KAAK;AAAA,EACd;AAWA,QAAM,YAAY,CACjB,UACA,0BACoB;AAEpB,QAAK,CAAE,uBAAwB;AAC9B,aAAO,QAAQ,UAAW,QAAS;AAAA,IACpC;AAGA,UAAM,YAAY,aAAc,qBAAsB;AACtD,UAAM,QAAQ,OAAQ,SAAU;AAChC,QA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EAAE,iBAAkB,IAAK;AAAA,QACzC;AACA,uCAAQ,MAAM,KAAM,EAAE;AAAA,cACrB,2BAAQ,MAAO,EAAE,mBAAoB,IAAK;AAAA,QAC3C;AAAA,MACD,
|
|
4
|
+
"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 './lock-unlock';\nimport type {\n\tStoreDescriptor,\n\tStoreNameOrDescriptor,\n\tDataRegistry,\n\tDataPlugin,\n\tInternalStoreInstance,\n\tAnyConfig,\n\tReduxStoreConfig,\n} from './types';\n\nfunction getStoreName( storeNameOrDescriptor: StoreNameOrDescriptor ): string {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param storeConfigs Initial store configurations.\n * @param parent Parent registry.\n *\n * @return Data registry.\n */\nexport function createRegistry(\n\tstoreConfigs: Record< string, ReduxStoreConfig< any, any, any > > = {},\n\tparent: DataRegistry | null = null\n): DataRegistry {\n\tconst stores: Record< string, InternalStoreInstance > = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores: Set< string > | null = 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 listener Listener function.\n\t * @param storeNameOrDescriptor Optional store name.\n\t *\n\t * @return Unsubscribe function.\n\t */\n\tconst subscribe = (\n\t\tlistener: () => void,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t): ( () => void ) => {\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 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: 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< T >(\n\t\tthis: DataRegistry,\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t): T {\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 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 Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor: 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 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 containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor: 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 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: 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(\n\t\tattributes: Record< string, unknown >\n\t): Record< string, unknown > {\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\t( ...args: unknown[] ) => {\n\t\t\t\t\t\treturn ( registry as any )[ key ]( ...args );\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 name Store registry name.\n\t * @param createStoreFunc Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance(\n\t\tname: string,\n\t\tcreateStoreFunc: () => InternalStoreInstance\n\t): InternalStoreInstance {\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: any = createStoreFunc();\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: () => void ) => {\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 {\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 store Store descriptor.\n\t */\n\tfunction register( store: StoreDescriptor< AnyConfig > ) {\n\t\tregisterStoreInstance(\n\t\t\tstore.name,\n\t\t\t() => store.instantiate( registry ) as InternalStoreInstance\n\t\t);\n\t}\n\n\tfunction registerGenericStore(\n\t\tname: string,\n\t\tstore: InternalStoreInstance\n\t) {\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 storeName Unique namespace identifier.\n\t * @param options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return Registered store object.\n\t */\n\tfunction registerStore(\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance(\n\t\t\tstoreName,\n\t\t\t() =>\n\t\t\t\tcreateReduxStore( storeName, options ).instantiate(\n\t\t\t\t\tregistry\n\t\t\t\t) as InternalStoreInstance\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback: () => void ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\n\t}\n\n\tlet registry: DataRegistry = {\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} as DataRegistry;\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: DataPlugin, options?: Record< string, unknown > ) {\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(\n\t\tregistry as unknown as Record< string, unknown >\n\t);\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch {\n\t\t\t\t// unlock() throws an error the store was not locked \u2013 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: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins as unknown as DataRegistry;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;A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MACvC,QAAQ;AACP,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
|
|
6
6
|
"names": ["deprecated", "createReduxStore", "coreDataStore"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/plugins/persistence/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\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 reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\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
|
|
5
|
-
"mappings": ";AAIA,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AAKtB,OAAO,oBAAoB;AAC3B,SAAS,uBAAuB;AA4BhC,IAAM,kBAAkB;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACuB;AACvB,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAqC;AAC7C,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\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 reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\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 {\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 key Key to update.\n\t * @param value Updated value.\n\t */\n\tfunction setData( key: string, value: unknown ): void {\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 registry Data registry.\n * @param pluginOptions Plugin options.\n *\n * @return Data plugin.\n */\nfunction persistencePlugin(\n\tregistry: DataRegistry,\n\tpluginOptions: PersistencePluginOptions\n): Partial< DataRegistry > {\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 getState Function which returns current state.\n\t * @param storeName Store name.\n\t * @param keys Optional subset of keys to save.\n\t *\n\t * @return Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange(\n\t\tgetState: () => unknown,\n\t\tstoreName: string,\n\t\tkeys: boolean | string[]\n\t): () => void {\n\t\tlet getPersistedState: ( state: any, action: any ) => any;\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(\n\t\t\t\t\taccumulator: Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t( state: any, action: any ) => any\n\t\t\t\t\t>,\n\t\t\t\t\tkey: string\n\t\t\t\t) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: (\n\t\t\t\t\t\t\tstate: unknown,\n\t\t\t\t\t\t\taction: { nextState: Record< string, unknown > }\n\t\t\t\t\t\t) => 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 = (\n\t\t\t\t_state: unknown,\n\t\t\t\taction: { nextState: unknown }\n\t\t\t) => 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(\n\t\t\tstoreName: string,\n\t\t\toptions: ReduxStoreConfig< any, any, any > & {\n\t\t\t\tpersist?: boolean | string[];\n\t\t\t}\n\t\t) {\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 = deepmerge(\n\t\t\t\t\t\tinitialState as Record< string, unknown >,\n\t\t\t\t\t\tpersistedState as Record< string, unknown >,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tisMergeableObject: isPlainObject,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\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\nexport default Object.assign( persistencePlugin, {\n\t__unstableMigrate: () => {},\n} );\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AAKtB,OAAO,oBAAoB;AAC3B,SAAS,uBAAuB;AA4BhC,IAAM,kBAAkB;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACuB;AACvB,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAqC;AAC7C,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,QAAQ;AAGP,iBAAO,CAAC;AAA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A,QACP,CAAE;AAEF,YACC,cAAe,YAAa,KAC5B,cAAe,cAAe,GAC7B;AAMD,yBAAe;AAAA,YACd;AAAA,YACA;AAAA,YACA;AAAA,cACC,mBAAmB;AAAA,YACpB;AAAA,UACD;AAAA,QACD,OAAO;AAGN,yBAAe;AAAA,QAChB;AAEA,kBAAU;AAAA,UACT,GAAG;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAEA,YAAM,QAAQ,SAAS,cAAe,WAAW,OAAQ;AAEzD,YAAM;AAAA,QACL;AAAA,UACC,MAAM;AAAA,UACN;AAAA,UACA,QAAQ;AAAA,QACT;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEA,IAAO,sBAAQ,OAAO,OAAQ,mBAAmB;AAAA,EAChD,mBAAmB,MAAM;AAAA,EAAC;AAC3B,CAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/plugins/persistence/storage/default.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch
|
|
5
|
-
"mappings": ";AAIA,OAAO,mBAAmB;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO,mBAAmB;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,QAAQ;AACP,YAAU;AACX;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -128,7 +128,7 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
128
128
|
unlock(store.store).registerPrivateSelectors(
|
|
129
129
|
unlock(parent).privateSelectorsOf(name)
|
|
130
130
|
);
|
|
131
|
-
} catch
|
|
131
|
+
} catch {
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
return store;
|
|
@@ -214,14 +214,14 @@ function createRegistry(storeConfigs = {}, parent = null) {
|
|
|
214
214
|
privateActionsOf: (name) => {
|
|
215
215
|
try {
|
|
216
216
|
return unlock(stores[name].store).privateActions;
|
|
217
|
-
} catch
|
|
217
|
+
} catch {
|
|
218
218
|
return {};
|
|
219
219
|
}
|
|
220
220
|
},
|
|
221
221
|
privateSelectorsOf: (name) => {
|
|
222
222
|
try {
|
|
223
223
|
return unlock(stores[name].store).privateSelectors;
|
|
224
|
-
} catch
|
|
224
|
+
} catch {
|
|
225
225
|
return {};
|
|
226
226
|
}
|
|
227
227
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/registry.ts"],
|
|
4
|
-
"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 './lock-unlock';\nimport type {\n\tStoreDescriptor,\n\tStoreNameOrDescriptor,\n\tDataRegistry,\n\tDataPlugin,\n\tInternalStoreInstance,\n\tAnyConfig,\n\tReduxStoreConfig,\n} from './types';\n\nfunction getStoreName( storeNameOrDescriptor: StoreNameOrDescriptor ): string {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param storeConfigs Initial store configurations.\n * @param parent Parent registry.\n *\n * @return Data registry.\n */\nexport function createRegistry(\n\tstoreConfigs: Record< string, ReduxStoreConfig< any, any, any > > = {},\n\tparent: DataRegistry | null = null\n): DataRegistry {\n\tconst stores: Record< string, InternalStoreInstance > = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores: Set< string > | null = 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 listener Listener function.\n\t * @param storeNameOrDescriptor Optional store name.\n\t *\n\t * @return Unsubscribe function.\n\t */\n\tconst subscribe = (\n\t\tlistener: () => void,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t): ( () => void ) => {\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 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: 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< T >(\n\t\tthis: DataRegistry,\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t): T {\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 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 Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor: 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 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 containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor: 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 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: 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(\n\t\tattributes: Record< string, unknown >\n\t): Record< string, unknown > {\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\t( ...args: unknown[] ) => {\n\t\t\t\t\t\treturn ( registry as any )[ key ]( ...args );\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 name Store registry name.\n\t * @param createStoreFunc Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance(\n\t\tname: string,\n\t\tcreateStoreFunc: () => InternalStoreInstance\n\t): InternalStoreInstance {\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: any = createStoreFunc();\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: () => void ) => {\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 store Store descriptor.\n\t */\n\tfunction register( store: StoreDescriptor< AnyConfig > ) {\n\t\tregisterStoreInstance(\n\t\t\tstore.name,\n\t\t\t() => store.instantiate( registry ) as InternalStoreInstance\n\t\t);\n\t}\n\n\tfunction registerGenericStore(\n\t\tname: string,\n\t\tstore: InternalStoreInstance\n\t) {\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 storeName Unique namespace identifier.\n\t * @param options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return Registered store object.\n\t */\n\tfunction registerStore(\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance(\n\t\t\tstoreName,\n\t\t\t() =>\n\t\t\t\tcreateReduxStore( storeName, options ).instantiate(\n\t\t\t\t\tregistry\n\t\t\t\t) as InternalStoreInstance\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback: () => void ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\n\t}\n\n\tlet registry: DataRegistry = {\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} as DataRegistry;\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: DataPlugin, options?: Record< string, unknown > ) {\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(\n\t\tregistry as unknown as Record< string, unknown >\n\t);\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name: string ) => {\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 \u2013 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: string ) => {\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 as unknown as DataRegistry;\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,OAAO,gBAAgB;AAKvB,OAAO,sBAAsB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,MAAM,cAAc;AAW7B,SAAS,aAAc,uBAAuD;AAC7E,SAAO,OAAO,0BAA0B,WACrC,wBACA,sBAAsB;AAC1B;A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S;AACjE,YAAM,uBAAuB,iBAAkB,MAAM;AACpD,YAAK,MAAM,QAAQ,UAAW;AAC7B,gBAAM,QAAQ,KAAK;AACnB;AAAA,QACD;AACA,iBAAS;AAAA,MACV,CAAE;AAEF,aAAO,MAAM;AACZ,+BAAuB;AACvB,iCAAyB;AAAA,MAC1B;AAAA,IACD;AACA,WAAQ,IAAK,IAAI;AACjB,UAAM,UAAW,cAAe;AAGhC,QAAK,QAAS;AACb,UAAI;AACH,eAAQ,MAAM,KAAM,EAAE;AAAA,UACrB,OAAQ,MAAO,EAAE,iBAAkB,IAAK;AAAA,QACzC;AACA,eAAQ,MAAM,KAAM,EAAE;AAAA,UACrB,OAAQ,MAAO,EAAE,mBAAoB,IAAK;AAAA,QAC3C;AAAA,MACD,
|
|
4
|
+
"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 './lock-unlock';\nimport type {\n\tStoreDescriptor,\n\tStoreNameOrDescriptor,\n\tDataRegistry,\n\tDataPlugin,\n\tInternalStoreInstance,\n\tAnyConfig,\n\tReduxStoreConfig,\n} from './types';\n\nfunction getStoreName( storeNameOrDescriptor: StoreNameOrDescriptor ): string {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param storeConfigs Initial store configurations.\n * @param parent Parent registry.\n *\n * @return Data registry.\n */\nexport function createRegistry(\n\tstoreConfigs: Record< string, ReduxStoreConfig< any, any, any > > = {},\n\tparent: DataRegistry | null = null\n): DataRegistry {\n\tconst stores: Record< string, InternalStoreInstance > = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores: Set< string > | null = 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 listener Listener function.\n\t * @param storeNameOrDescriptor Optional store name.\n\t *\n\t * @return Unsubscribe function.\n\t */\n\tconst subscribe = (\n\t\tlistener: () => void,\n\t\tstoreNameOrDescriptor?: StoreNameOrDescriptor\n\t): ( () => void ) => {\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 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: 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< T >(\n\t\tthis: DataRegistry,\n\t\tcallback: () => T,\n\t\tref: { current: string[] | null }\n\t): T {\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 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 Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor: 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 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 containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor: 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 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: 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(\n\t\tattributes: Record< string, unknown >\n\t): Record< string, unknown > {\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\t( ...args: unknown[] ) => {\n\t\t\t\t\t\treturn ( registry as any )[ key ]( ...args );\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 name Store registry name.\n\t * @param createStoreFunc Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance(\n\t\tname: string,\n\t\tcreateStoreFunc: () => InternalStoreInstance\n\t): InternalStoreInstance {\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: any = createStoreFunc();\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: () => void ) => {\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 {\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 store Store descriptor.\n\t */\n\tfunction register( store: StoreDescriptor< AnyConfig > ) {\n\t\tregisterStoreInstance(\n\t\t\tstore.name,\n\t\t\t() => store.instantiate( registry ) as InternalStoreInstance\n\t\t);\n\t}\n\n\tfunction registerGenericStore(\n\t\tname: string,\n\t\tstore: InternalStoreInstance\n\t) {\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 storeName Unique namespace identifier.\n\t * @param options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return Registered store object.\n\t */\n\tfunction registerStore(\n\t\tstoreName: string,\n\t\toptions: ReduxStoreConfig< any, any, any >\n\t) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance(\n\t\t\tstoreName,\n\t\t\t() =>\n\t\t\t\tcreateReduxStore( storeName, options ).instantiate(\n\t\t\t\t\tregistry\n\t\t\t\t) as InternalStoreInstance\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback: () => void ) {\n\t\t// If we're already batching, just call the callback.\n\t\tif ( emitter.isPaused ) {\n\t\t\tcallback();\n\t\t\treturn;\n\t\t}\n\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\temitter.resume();\n\t\t\tObject.values( stores ).forEach( ( store ) =>\n\t\t\t\tstore.emitter.resume()\n\t\t\t);\n\t\t}\n\t}\n\n\tlet registry: DataRegistry = {\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} as DataRegistry;\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: DataPlugin, options?: Record< string, unknown > ) {\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(\n\t\tregistry as unknown as Record< string, unknown >\n\t);\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch {\n\t\t\t\t// unlock() throws an error the store was not locked \u2013 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: string ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins as unknown as DataRegistry;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,gBAAgB;AAKvB,OAAO,sBAAsB;AAC7B,OAAO,mBAAmB;AAC1B,SAAS,qBAAqB;AAC9B,SAAS,MAAM,cAAc;AAW7B,SAAS,aAAc,uBAAuD;AAC7E,SAAO,OAAO,0BAA0B,WACrC,wBACA,sBAAsB;AAC1B;AAWO,SAAS,eACf,eAAoE,CAAC,GACrE,SAA8B,MACf;AACf,QAAM,SAAkD,CAAC;AACzD,QAAM,UAAU,cAAc;AAC9B,MAAI,kBAAwC;AAK5C,WAAS,iBAAiB;AACzB,YAAQ,KAAK;AAAA,EACd;AAWA,QAAM,YAAY,CACjB,UACA,0BACoB;AAEpB,QAAK,CAAE,uBAAwB;AAC9B,aAAO,QAAQ,UAAW,QAAS;AAAA,IACpC;AAGA,UAAM,YAAY,aAAc,qBAAsB;AACtD,UAAM,QAAQ,OAAQ,SAAU;AAChC,QAAK,OAAQ;AACZ,aAAO,MAAM,UAAW,QAAS;AAAA,IAClC;AAMA,QAAK,CAAE,QAAS;AACf,aAAO,QAAQ,UAAW,QAAS;AAAA,IACpC;AAEA,WAAO,OAAO,UAAW,UAAU,qBAAsB;AAAA,EAC1D;AAUA,WAAS,OAAQ,uBAA+C;AAC/D,UAAM,YAAY,aAAc,qBAAsB;AACtD,qBAAiB,IAAK,SAAU;AAChC,UAAM,QAAQ,OAAQ,SAAU;AAChC,QAAK,OAAQ;AACZ,aAAO,MAAM,aAAa;AAAA,IAC3B;AAEA,WAAO,QAAQ,OAAQ,SAAU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OAAM,qBAAqB;AAAA,IAC1B,kBAAkB,CAAE,SAAkB;AACrC,UAAI;AACH,eAAO,OAAQ,OAAQ,IAAK,EAAE,KAAM,EAAE;AAAA,MACvC,QAAQ;AAGP,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,IACA,oBAAoB,CAAE,SAAkB;AACvC,UAAI;AACH,eAAO,OAAQ,OAAQ,IAAK,EAAE,KAAM,EAAE;AAAA,MACvC,QAAQ;AACP,eAAO,CAAC;AAAA,MACT;AAAA,IACD;AAAA,EACD,CAAE;AACF,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "10.43.0",
|
|
3
|
+
"version": "10.43.1-next.v.202604091042.0+668146787",
|
|
4
4
|
"description": "Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"types": "build-types",
|
|
46
46
|
"sideEffects": false,
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@wordpress/compose": "^7.43.0",
|
|
49
|
-
"@wordpress/deprecated": "^4.43.0",
|
|
50
|
-
"@wordpress/element": "^6.
|
|
51
|
-
"@wordpress/is-shallow-equal": "^5.43.0",
|
|
52
|
-
"@wordpress/priority-queue": "^3.43.0",
|
|
53
|
-
"@wordpress/private-apis": "^1.43.0",
|
|
54
|
-
"@wordpress/redux-routine": "^5.43.0",
|
|
48
|
+
"@wordpress/compose": "^7.43.1-next.v.202604091042.0+668146787",
|
|
49
|
+
"@wordpress/deprecated": "^4.43.1-next.v.202604091042.0+668146787",
|
|
50
|
+
"@wordpress/element": "^6.44.1-next.v.202604091042.0+668146787",
|
|
51
|
+
"@wordpress/is-shallow-equal": "^5.43.1-next.v.202604091042.0+668146787",
|
|
52
|
+
"@wordpress/priority-queue": "^3.43.1-next.v.202604091042.0+668146787",
|
|
53
|
+
"@wordpress/private-apis": "^1.43.1-next.v.202604091042.0+668146787",
|
|
54
|
+
"@wordpress/redux-routine": "^5.43.1-next.v.202604091042.0+668146787",
|
|
55
55
|
"deepmerge": "^4.3.0",
|
|
56
56
|
"equivalent-key-map": "^0.2.2",
|
|
57
57
|
"is-plain-object": "^5.0.0",
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"publishConfig": {
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "73606df74f1c38a084bfa5db97205259ef817593"
|
|
73
73
|
}
|
|
@@ -94,7 +94,7 @@ export function createPersistenceInterface(
|
|
|
94
94
|
} else {
|
|
95
95
|
try {
|
|
96
96
|
data = JSON.parse( persisted );
|
|
97
|
-
} catch
|
|
97
|
+
} catch {
|
|
98
98
|
// Similarly, should any error be thrown during parse of
|
|
99
99
|
// the string (malformed JSON), fall back to empty object.
|
|
100
100
|
data = {};
|
package/src/registry.ts
CHANGED
|
@@ -261,7 +261,7 @@ export function createRegistry(
|
|
|
261
261
|
unlock( store.store ).registerPrivateSelectors(
|
|
262
262
|
unlock( parent ).privateSelectorsOf( name )
|
|
263
263
|
);
|
|
264
|
-
} catch
|
|
264
|
+
} catch {
|
|
265
265
|
// unlock() throws if store.store was not locked.
|
|
266
266
|
// The error indicates there's nothing to do here so let's
|
|
267
267
|
// ignore it.
|
|
@@ -389,7 +389,7 @@ export function createRegistry(
|
|
|
389
389
|
privateActionsOf: ( name: string ) => {
|
|
390
390
|
try {
|
|
391
391
|
return unlock( stores[ name ].store ).privateActions;
|
|
392
|
-
} catch
|
|
392
|
+
} catch {
|
|
393
393
|
// unlock() throws an error the store was not locked – this means
|
|
394
394
|
// there no private actions are available
|
|
395
395
|
return {};
|
|
@@ -398,7 +398,7 @@ export function createRegistry(
|
|
|
398
398
|
privateSelectorsOf: ( name: string ) => {
|
|
399
399
|
try {
|
|
400
400
|
return unlock( stores[ name ].store ).privateSelectors;
|
|
401
|
-
} catch
|
|
401
|
+
} catch {
|
|
402
402
|
return {};
|
|
403
403
|
}
|
|
404
404
|
},
|