@wordpress/data 9.5.0 → 9.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/with-dispatch/index.js +3 -5
- package/build/components/with-dispatch/index.js.map +1 -1
- package/build/components/with-registry/index.js +2 -6
- package/build/components/with-registry/index.js.map +1 -1
- package/build/components/with-select/index.js +3 -3
- package/build/components/with-select/index.js.map +1 -1
- package/build/factory.js +1 -1
- package/build/factory.js.map +1 -1
- package/build/{private-apis.js → lock-unlock.js} +1 -1
- package/build/lock-unlock.js.map +1 -0
- package/build/redux-store/index.js +64 -38
- package/build/redux-store/index.js.map +1 -1
- package/build/registry.js +6 -6
- package/build/registry.js.map +1 -1
- package/build-module/components/with-dispatch/index.js +3 -2
- package/build-module/components/with-dispatch/index.js.map +1 -1
- package/build-module/components/with-registry/index.js +2 -3
- package/build-module/components/with-registry/index.js.map +1 -1
- package/build-module/components/with-select/index.js +3 -2
- package/build-module/components/with-select/index.js.map +1 -1
- package/build-module/factory.js +1 -1
- package/build-module/factory.js.map +1 -1
- package/build-module/{private-apis.js → lock-unlock.js} +1 -1
- package/build-module/lock-unlock.js.map +1 -0
- package/build-module/redux-store/index.js +62 -36
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/registry.js +1 -1
- package/build-module/registry.js.map +1 -1
- package/build-types/{private-apis.d.ts → lock-unlock.d.ts} +1 -1
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/factory.js +1 -1
- package/src/redux-store/index.js +92 -65
- package/src/registry.js +1 -1
- package/src/test/privateAPIs.js +87 -11
- package/tsconfig.tsbuildinfo +1 -1
- package/build/private-apis.js.map +0 -1
- package/build-module/private-apis.js.map +0 -1
- package/build-types/private-apis.d.ts.map +0 -1
- /package/src/{private-apis.js → lock-unlock.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["deprecated","createReduxStore","coreDataStore","createEmitter","lock","unlock","getStoreName","storeNameOrDescriptor","name","createRegistry","storeConfigs","parent","stores","emitter","listeningStores","globalListener","emit","subscribe","listener","storeName","store","select","add","getSelectors","__unstableMarkListeningStores","callback","ref","Set","call","current","Array","from","resolveSelect","getResolveSelectors","suspendSelect","getSuspendSelectors","dispatch","getActions","withPlugins","attributes","Object","fromEntries","entries","map","key","attribute","registry","apply","arguments","registerStoreInstance","createStore","console","error","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","registerPrivateActions","privateActionsOf","registerPrivateSelectors","privateSelectorsOf","e","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","batch","pause","values","forEach","resume","namespaces","use","plugin","config","registryWithPlugins","privateActions","privateSelectors"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,gBAAP,MAA6B,eAA7B;AACA,OAAOC,aAAP,MAA0B,SAA1B;AACA,SAASC,aAAT,QAA8B,iBAA9B;AACA,SAASC,IAAT,EAAeC,MAAf,QAA6B,gBAA7B;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA,SAASC,YAAT,CAAuBC,qBAAvB,EAA+C;AAC9C,SAAO,OAAOA,qBAAP,KAAiC,QAAjC,GACJA,qBADI,GAEJA,qBAAqB,CAACC,IAFzB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASC,cAAT,CAAyBC,YAAY,GAAG,EAAxC,EAA4CC,MAAM,GAAG,IAArD,EAA4D;AAClE,QAAMC,MAAM,GAAG,EAAf;AACA,QAAMC,OAAO,GAAGV,aAAa,EAA7B;AACA,MAAIW,eAAe,GAAG,IAAtB;AAEA;AACD;AACA;;AACC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SAAOkB,mBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\nimport { lock, unlock } from './private-apis';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\nfunction getStoreName( storeNameOrDescriptor ) {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {Object?} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores = null;\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param {Function} listener Listener function.\n\t * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener, storeNameOrDescriptor ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to global `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores( callback, ref ) {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins( attributes ) {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\tfunction () {\n\t\t\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} )\n\t\t);\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param {string} name Store registry name.\n\t * @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, createStore ) {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store = createStore();\n\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param {StoreDescriptor} store Store descriptor.\n\t */\n\tfunction register( store ) {\n\t\tregisterStoreInstance( store.name, () =>\n\t\t\tstore.instantiate( registry )\n\t\t);\n\t}\n\n\tfunction registerGenericStore( name, store ) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, () => store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tfunction registerStore( storeName, options ) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance( storeName, () =>\n\t\t\tcreateReduxStore( storeName, options ).instantiate( registry )\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.resume() );\n\t}\n\n\tlet registry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t};\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin, options ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\tconst registryWithPlugins = withPlugins( registry );\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws an error the store was not locked – this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["deprecated","createReduxStore","coreDataStore","createEmitter","lock","unlock","getStoreName","storeNameOrDescriptor","name","createRegistry","storeConfigs","parent","stores","emitter","listeningStores","globalListener","emit","subscribe","listener","storeName","store","select","add","getSelectors","__unstableMarkListeningStores","callback","ref","Set","call","current","Array","from","resolveSelect","getResolveSelectors","suspendSelect","getSuspendSelectors","dispatch","getActions","withPlugins","attributes","Object","fromEntries","entries","map","key","attribute","registry","apply","arguments","registerStoreInstance","createStore","console","error","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","registerPrivateActions","privateActionsOf","registerPrivateSelectors","privateSelectorsOf","e","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","batch","pause","values","forEach","resume","namespaces","use","plugin","config","registryWithPlugins","privateActions","privateSelectors"],"mappings":"A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CAACiB,QAAT,CAAmB9D,gBAAgB,CAAEO,IAAF,EAAQuE,MAAR,CAAnC;AACA;;AAED,MAAKpE,MAAL,EAAc;AACbA,IAAAA,MAAM,CAACM,SAAP,CAAkBF,cAAlB;AACA;;AAED,QAAMiE,mBAAmB,GAAG1C,WAAW,CAAEQ,QAAF,CAAvC;AACA1C,EAAAA,IAAI,CAAE4E,mBAAF,EAAuB;AAC1BrB,IAAAA,gBAAgB,EAAInD,IAAF,IAAY;AAC7B,UAAI;AACH,eAAOH,MAAM,CAAEO,MAAM,CAAEJ,IAAF,CAAN,CAAeY,KAAjB,CAAN,CAA+B6D,cAAtC;AACA,OAFD,CAEE,OAAQnB,CAAR,EAAY;AACb;AACA;AACA,eAAO,EAAP;AACA;AACD,KATyB;AAU1BD,IAAAA,kBAAkB,EAAIrD,IAAF,IAAY;AAC/B,UAAI;AACH,eAAOH,MAAM,CAAEO,MAAM,CAAEJ,IAAF,CAAN,CAAeY,KAAjB,CAAN,CAA+B8D,gBAAtC;AACA,OAFD,CAEE,OAAQpB,CAAR,EAAY;AACb,eAAO,EAAP;AACA;AACD;AAhByB,GAAvB,CAAJ;AAkBA,SAAOkB,mBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport createReduxStore from './redux-store';\nimport coreDataStore from './store';\nimport { createEmitter } from './utils/emitter';\nimport { lock, unlock } from './lock-unlock';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\n/**\n * @typedef {Object} WPDataRegistry An isolated orchestrator of store registrations.\n *\n * @property {Function} registerGenericStore Given a namespace key and settings\n * object, registers a new generic\n * store.\n * @property {Function} registerStore Given a namespace key and settings\n * object, registers a new namespace\n * store.\n * @property {Function} subscribe Given a function callback, invokes\n * the callback on any change to state\n * within any registered store.\n * @property {Function} select Given a namespace key, returns an\n * object of the store's registered\n * selectors.\n * @property {Function} dispatch Given a namespace key, returns an\n * object of the store's registered\n * action dispatchers.\n */\n\n/**\n * @typedef {Object} WPDataPlugin An object of registry function overrides.\n *\n * @property {Function} registerStore registers store.\n */\n\nfunction getStoreName( storeNameOrDescriptor ) {\n\treturn typeof storeNameOrDescriptor === 'string'\n\t\t? storeNameOrDescriptor\n\t\t: storeNameOrDescriptor.name;\n}\n/**\n * Creates a new store registry, given an optional object of initial store\n * configurations.\n *\n * @param {Object} storeConfigs Initial store configurations.\n * @param {Object?} parent Parent registry.\n *\n * @return {WPDataRegistry} Data registry.\n */\nexport function createRegistry( storeConfigs = {}, parent = null ) {\n\tconst stores = {};\n\tconst emitter = createEmitter();\n\tlet listeningStores = null;\n\n\t/**\n\t * Global listener called for each store's update.\n\t */\n\tfunction globalListener() {\n\t\temitter.emit();\n\t}\n\n\t/**\n\t * Subscribe to changes to any data, either in all stores in registry, or\n\t * in one specific store.\n\t *\n\t * @param {Function} listener Listener function.\n\t * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener, storeNameOrDescriptor ) => {\n\t\t// subscribe to all stores\n\t\tif ( ! storeNameOrDescriptor ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\t// subscribe to one store\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.subscribe( listener );\n\t\t}\n\n\t\t// Trying to access a store that hasn't been registered,\n\t\t// this is a pattern rarely used but seen in some places.\n\t\t// We fallback to global `subscribe` here for backward-compatibility for now.\n\t\t// See https://github.com/WordPress/gutenberg/pull/27466 for more info.\n\t\tif ( ! parent ) {\n\t\t\treturn emitter.subscribe( listener );\n\t\t}\n\n\t\treturn parent.subscribe( listener, storeNameOrDescriptor );\n\t};\n\n\t/**\n\t * Calls a selector given the current state and extra arguments.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The selector's returned value.\n\t */\n\tfunction select( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSelectors();\n\t\t}\n\n\t\treturn parent?.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores( callback, ref ) {\n\t\tlisteningStores = new Set();\n\t\ttry {\n\t\t\treturn callback.call( this );\n\t\t} finally {\n\t\t\tref.current = Array.from( listeningStores );\n\t\t\tlisteningStores = null;\n\t\t}\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they return\n\t * promises that resolve to their eventual values, after any resolvers have ran.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getResolveSelectors();\n\t\t}\n\n\t\treturn parent && parent.resolveSelect( storeName );\n\t}\n\n\t/**\n\t * Given a store descriptor, returns an object containing the store's selectors pre-bound to\n\t * state so that you only need to supply additional arguments, and modified so that they throw\n\t * promises in case the selector is not resolved yet.\n\t *\n\t * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n\t * convention of passing the store name is\n\t * also supported.\n\t *\n\t * @return {Object} Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tlisteningStores?.add( storeName );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getSuspendSelectors();\n\t\t}\n\n\t\treturn parent && parent.suspendSelect( storeName );\n\t}\n\n\t/**\n\t * Returns the available actions for a part of the state.\n\t *\n\t * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n\t * or the store descriptor.\n\t *\n\t * @return {*} The action's returned value.\n\t */\n\tfunction dispatch( storeNameOrDescriptor ) {\n\t\tconst storeName = getStoreName( storeNameOrDescriptor );\n\t\tconst store = stores[ storeName ];\n\t\tif ( store ) {\n\t\t\treturn store.getActions();\n\t\t}\n\n\t\treturn parent && parent.dispatch( storeName );\n\t}\n\n\t//\n\t// Deprecated\n\t// TODO: Remove this after `use()` is removed.\n\tfunction withPlugins( attributes ) {\n\t\treturn Object.fromEntries(\n\t\t\tObject.entries( attributes ).map( ( [ key, attribute ] ) => {\n\t\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\t\treturn [ key, attribute ];\n\t\t\t\t}\n\t\t\t\treturn [\n\t\t\t\t\tkey,\n\t\t\t\t\tfunction () {\n\t\t\t\t\t\treturn registry[ key ].apply( null, arguments );\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t} )\n\t\t);\n\t}\n\n\t/**\n\t * Registers a store instance.\n\t *\n\t * @param {string} name Store registry name.\n\t * @param {Function} createStore Function that creates a store object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, createStore ) {\n\t\tif ( stores[ name ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( 'Store \"' + name + '\" is already registered.' );\n\t\t\treturn stores[ name ];\n\t\t}\n\n\t\tconst store = createStore();\n\n\t\tif ( typeof store.getSelectors !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getSelectors must be a function' );\n\t\t}\n\t\tif ( typeof store.getActions !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.getActions must be a function' );\n\t\t}\n\t\tif ( typeof store.subscribe !== 'function' ) {\n\t\t\tthrow new TypeError( 'store.subscribe must be a function' );\n\t\t}\n\t\t// The emitter is used to keep track of active listeners when the registry\n\t\t// get paused, that way, when resumed we should be able to call all these\n\t\t// pending listeners.\n\t\tstore.emitter = createEmitter();\n\t\tconst currentSubscribe = store.subscribe;\n\t\tstore.subscribe = ( listener ) => {\n\t\t\tconst unsubscribeFromEmitter = store.emitter.subscribe( listener );\n\t\t\tconst unsubscribeFromStore = currentSubscribe( () => {\n\t\t\t\tif ( store.emitter.isPaused ) {\n\t\t\t\t\tstore.emitter.emit();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlistener();\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tunsubscribeFromStore?.();\n\t\t\t\tunsubscribeFromEmitter?.();\n\t\t\t};\n\t\t};\n\t\tstores[ name ] = store;\n\t\tstore.subscribe( globalListener );\n\n\t\t// Copy private actions and selectors from the parent store.\n\t\tif ( parent ) {\n\t\t\ttry {\n\t\t\t\tunlock( store.store ).registerPrivateActions(\n\t\t\t\t\tunlock( parent ).privateActionsOf( name )\n\t\t\t\t);\n\t\t\t\tunlock( store.store ).registerPrivateSelectors(\n\t\t\t\t\tunlock( parent ).privateSelectorsOf( name )\n\t\t\t\t);\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws if store.store was not locked.\n\t\t\t\t// The error indicates there's nothing to do here so let's\n\t\t\t\t// ignore it.\n\t\t\t}\n\t\t}\n\n\t\treturn store;\n\t}\n\n\t/**\n\t * Registers a new store given a store descriptor.\n\t *\n\t * @param {StoreDescriptor} store Store descriptor.\n\t */\n\tfunction register( store ) {\n\t\tregisterStoreInstance( store.name, () =>\n\t\t\tstore.instantiate( registry )\n\t\t);\n\t}\n\n\tfunction registerGenericStore( name, store ) {\n\t\tdeprecated( 'wp.data.registerGenericStore', {\n\t\t\tsince: '5.9',\n\t\t\talternative: 'wp.data.register( storeDescriptor )',\n\t\t} );\n\t\tregisterStoreInstance( name, () => store );\n\t}\n\n\t/**\n\t * Registers a standard `@wordpress/data` store.\n\t *\n\t * @param {string} storeName Unique namespace identifier.\n\t * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n\t *\n\t * @return {Object} Registered store object.\n\t */\n\tfunction registerStore( storeName, options ) {\n\t\tif ( ! options.reducer ) {\n\t\t\tthrow new TypeError( 'Must specify store reducer' );\n\t\t}\n\n\t\tconst store = registerStoreInstance( storeName, () =>\n\t\t\tcreateReduxStore( storeName, options ).instantiate( registry )\n\t\t);\n\n\t\treturn store.store;\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tObject.values( stores ).forEach( ( store ) => store.emitter.resume() );\n\t}\n\n\tlet registry = {\n\t\tbatch,\n\t\tstores,\n\t\tnamespaces: stores, // TODO: Deprecate/remove this.\n\t\tsubscribe,\n\t\tselect,\n\t\tresolveSelect,\n\t\tsuspendSelect,\n\t\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t};\n\n\t//\n\t// TODO:\n\t// This function will be deprecated as soon as it is no longer internally referenced.\n\tfunction use( plugin, options ) {\n\t\tif ( ! plugin ) {\n\t\t\treturn;\n\t\t}\n\n\t\tregistry = {\n\t\t\t...registry,\n\t\t\t...plugin( registry, options ),\n\t\t};\n\n\t\treturn registry;\n\t}\n\n\tregistry.register( coreDataStore );\n\n\tfor ( const [ name, config ] of Object.entries( storeConfigs ) ) {\n\t\tregistry.register( createReduxStore( name, config ) );\n\t}\n\n\tif ( parent ) {\n\t\tparent.subscribe( globalListener );\n\t}\n\n\tconst registryWithPlugins = withPlugins( registry );\n\tlock( registryWithPlugins, {\n\t\tprivateActionsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateActions;\n\t\t\t} catch ( e ) {\n\t\t\t\t// unlock() throws an error the store was not locked – this means\n\t\t\t\t// there no private actions are available\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t\tprivateSelectorsOf: ( name ) => {\n\t\t\ttry {\n\t\t\t\treturn unlock( stores[ name ].store ).privateSelectors;\n\t\t\t} catch ( e ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t},\n\t} );\n\treturn registryWithPlugins;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock-unlock.d.ts","sourceRoot":"","sources":["../src/lock-unlock.js"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redux-store/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/redux-store/index.js"],"names":[],"mappings":"AAsHA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qGAPW,MAAM,+KAqMhB;2BArTa,OAAO,UAAU,EAAE,YAAY;sEAEhC,OAAO,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC;sFAIrC,OAAO,UAAU,EAAE,gBAAgB,CAAC,KAAK,EAAC,OAAO,EAAC,SAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/data",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.2",
|
|
4
4
|
"description": "Data module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
"sideEffects": false,
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.16.0",
|
|
32
|
-
"@wordpress/compose": "^6.12.
|
|
33
|
-
"@wordpress/deprecated": "^3.35.
|
|
34
|
-
"@wordpress/element": "^5.12.
|
|
35
|
-
"@wordpress/is-shallow-equal": "^4.35.
|
|
36
|
-
"@wordpress/priority-queue": "^2.35.
|
|
37
|
-
"@wordpress/private-apis": "^0.17.
|
|
38
|
-
"@wordpress/redux-routine": "^4.35.
|
|
32
|
+
"@wordpress/compose": "^6.12.1",
|
|
33
|
+
"@wordpress/deprecated": "^3.35.1",
|
|
34
|
+
"@wordpress/element": "^5.12.1",
|
|
35
|
+
"@wordpress/is-shallow-equal": "^4.35.1",
|
|
36
|
+
"@wordpress/priority-queue": "^2.35.1",
|
|
37
|
+
"@wordpress/private-apis": "^0.17.1",
|
|
38
|
+
"@wordpress/redux-routine": "^4.35.1",
|
|
39
39
|
"deepmerge": "^4.3.0",
|
|
40
40
|
"equivalent-key-map": "^0.2.2",
|
|
41
41
|
"is-plain-object": "^5.0.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "65fb4cd5187a47ca274c24c04a220bcdb2ddfa67"
|
|
54
54
|
}
|
package/src/factory.js
CHANGED
|
@@ -47,7 +47,7 @@ export function createRegistrySelector( registrySelector ) {
|
|
|
47
47
|
|
|
48
48
|
/**
|
|
49
49
|
* Flag indicating that the selector is a registry selector that needs the correct registry
|
|
50
|
-
* reference to be assigned to `
|
|
50
|
+
* reference to be assigned to `selector.registry` to make it work correctly.
|
|
51
51
|
* be mapped as a registry selector.
|
|
52
52
|
*
|
|
53
53
|
* @type {boolean}
|
package/src/redux-store/index.js
CHANGED
|
@@ -15,7 +15,7 @@ import { compose } from '@wordpress/compose';
|
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
17
|
import { builtinControls } from '../controls';
|
|
18
|
-
import { lock } from '../
|
|
18
|
+
import { lock } from '../lock-unlock';
|
|
19
19
|
import promise from '../promise-middleware';
|
|
20
20
|
import createResolversCacheMiddleware from '../resolvers-cache-middleware';
|
|
21
21
|
import createThunkMiddleware from './thunk-middleware';
|
|
@@ -101,6 +101,21 @@ function createResolversCache() {
|
|
|
101
101
|
};
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
+
function createBindingCache( bind ) {
|
|
105
|
+
const cache = new WeakMap();
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
get( item, itemName ) {
|
|
109
|
+
let boundItem = cache.get( item );
|
|
110
|
+
if ( ! boundItem ) {
|
|
111
|
+
boundItem = bind( item, itemName );
|
|
112
|
+
cache.set( item, boundItem );
|
|
113
|
+
}
|
|
114
|
+
return boundItem;
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
104
119
|
/**
|
|
105
120
|
* Creates a data store descriptor for the provided Redux store configuration containing
|
|
106
121
|
* properties describing reducer, actions, selectors, controls and resolvers.
|
|
@@ -147,17 +162,10 @@ export default function createReduxStore( key, options ) {
|
|
|
147
162
|
const thunkArgs = {
|
|
148
163
|
registry,
|
|
149
164
|
get dispatch() {
|
|
150
|
-
return
|
|
151
|
-
( action ) => store.dispatch( action ),
|
|
152
|
-
getActions()
|
|
153
|
-
);
|
|
165
|
+
return thunkActions;
|
|
154
166
|
},
|
|
155
167
|
get select() {
|
|
156
|
-
return
|
|
157
|
-
( selector ) =>
|
|
158
|
-
selector( store.__unstableOriginalGetState() ),
|
|
159
|
-
getSelectors()
|
|
160
|
-
);
|
|
168
|
+
return thunkSelectors;
|
|
161
169
|
},
|
|
162
170
|
get resolveSelect() {
|
|
163
171
|
return getResolveSelectors();
|
|
@@ -185,19 +193,28 @@ export default function createReduxStore( key, options ) {
|
|
|
185
193
|
...mapValues( options.actions, bindAction ),
|
|
186
194
|
};
|
|
187
195
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
196
|
+
const boundPrivateActions = createBindingCache( bindAction );
|
|
197
|
+
const allActions = new Proxy( () => {}, {
|
|
198
|
+
get: ( target, prop ) => {
|
|
199
|
+
const privateAction = privateActions[ prop ];
|
|
200
|
+
return privateAction
|
|
201
|
+
? boundPrivateActions.get( privateAction, prop )
|
|
202
|
+
: actions[ prop ];
|
|
203
|
+
},
|
|
204
|
+
} );
|
|
205
|
+
|
|
206
|
+
const thunkActions = new Proxy( allActions, {
|
|
207
|
+
apply: ( target, thisArg, [ action ] ) =>
|
|
208
|
+
store.dispatch( action ),
|
|
209
|
+
} );
|
|
210
|
+
|
|
211
|
+
lock( actions, allActions );
|
|
212
|
+
|
|
213
|
+
const resolvers = options.resolvers
|
|
214
|
+
? mapResolvers( options.resolvers )
|
|
215
|
+
: {};
|
|
199
216
|
|
|
200
|
-
function bindSelector( selector ) {
|
|
217
|
+
function bindSelector( selector, selectorName ) {
|
|
201
218
|
if ( selector.isRegistrySelector ) {
|
|
202
219
|
selector.registry = registry;
|
|
203
220
|
}
|
|
@@ -205,8 +222,20 @@ export default function createReduxStore( key, options ) {
|
|
|
205
222
|
const state = store.__unstableOriginalGetState();
|
|
206
223
|
return selector( state.root, ...args );
|
|
207
224
|
};
|
|
208
|
-
|
|
209
|
-
|
|
225
|
+
|
|
226
|
+
const resolver = resolvers[ selectorName ];
|
|
227
|
+
if ( ! resolver ) {
|
|
228
|
+
boundSelector.hasResolver = false;
|
|
229
|
+
return boundSelector;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return mapSelectorWithResolver(
|
|
233
|
+
boundSelector,
|
|
234
|
+
selectorName,
|
|
235
|
+
resolver,
|
|
236
|
+
store,
|
|
237
|
+
resolversCache
|
|
238
|
+
);
|
|
210
239
|
}
|
|
211
240
|
|
|
212
241
|
function bindMetadataSelector( selector ) {
|
|
@@ -218,33 +247,36 @@ export default function createReduxStore( key, options ) {
|
|
|
218
247
|
return boundSelector;
|
|
219
248
|
}
|
|
220
249
|
|
|
221
|
-
|
|
250
|
+
const selectors = {
|
|
222
251
|
...mapValues( metadataSelectors, bindMetadataSelector ),
|
|
223
252
|
...mapValues( options.selectors, bindSelector ),
|
|
224
253
|
};
|
|
225
254
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
);
|
|
255
|
+
const boundPrivateSelectors = createBindingCache( bindSelector );
|
|
256
|
+
|
|
257
|
+
// Pre-bind the private selectors that have been registered by the time of
|
|
258
|
+
// instantiation, so that registry selectors are bound to the registry.
|
|
259
|
+
for ( const [ selectorName, selector ] of Object.entries(
|
|
260
|
+
privateSelectors
|
|
261
|
+
) ) {
|
|
262
|
+
boundPrivateSelectors.get( selector, selectorName );
|
|
235
263
|
}
|
|
236
264
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
265
|
+
const allSelectors = new Proxy( () => {}, {
|
|
266
|
+
get: ( target, prop ) => {
|
|
267
|
+
const privateSelector = privateSelectors[ prop ];
|
|
268
|
+
return privateSelector
|
|
269
|
+
? boundPrivateSelectors.get( privateSelector, prop )
|
|
270
|
+
: selectors[ prop ];
|
|
271
|
+
},
|
|
272
|
+
} );
|
|
273
|
+
|
|
274
|
+
const thunkSelectors = new Proxy( allSelectors, {
|
|
275
|
+
apply: ( target, thisArg, [ selector ] ) =>
|
|
276
|
+
selector( store.__unstableOriginalGetState() ),
|
|
277
|
+
} );
|
|
278
|
+
|
|
279
|
+
lock( selectors, allSelectors );
|
|
248
280
|
|
|
249
281
|
const resolveSelectors = mapResolveSelectors( selectors, store );
|
|
250
282
|
const suspendSelectors = mapSuspendSelectors( selectors, store );
|
|
@@ -484,22 +516,24 @@ function mapResolvers( resolvers ) {
|
|
|
484
516
|
}
|
|
485
517
|
|
|
486
518
|
/**
|
|
487
|
-
* Returns
|
|
519
|
+
* Returns a selector with a matched resolver.
|
|
488
520
|
* Resolvers are side effects invoked once per argument set of a given selector call,
|
|
489
521
|
* used in ensuring that the data needs for the selector are satisfied.
|
|
490
522
|
*
|
|
491
|
-
* @param {Object}
|
|
492
|
-
* @param {
|
|
523
|
+
* @param {Object} selector The selector function to be bound.
|
|
524
|
+
* @param {string} selectorName The selector name.
|
|
525
|
+
* @param {Object} resolver Resolver to call.
|
|
493
526
|
* @param {Object} store The redux store to which the resolvers should be mapped.
|
|
494
527
|
* @param {Object} resolversCache Resolvers Cache.
|
|
495
528
|
*/
|
|
496
|
-
function
|
|
497
|
-
|
|
498
|
-
|
|
529
|
+
function mapSelectorWithResolver(
|
|
530
|
+
selector,
|
|
531
|
+
selectorName,
|
|
532
|
+
resolver,
|
|
499
533
|
store,
|
|
500
534
|
resolversCache
|
|
501
535
|
) {
|
|
502
|
-
function fulfillSelector(
|
|
536
|
+
function fulfillSelector( args ) {
|
|
503
537
|
const state = store.getState();
|
|
504
538
|
|
|
505
539
|
if (
|
|
@@ -545,17 +579,10 @@ function mapSelectorsWithResolvers(
|
|
|
545
579
|
}, 0 );
|
|
546
580
|
}
|
|
547
581
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
const selectorResolver = ( ...args ) => {
|
|
555
|
-
fulfillSelector( resolver, selectorName, args );
|
|
556
|
-
return selector( ...args );
|
|
557
|
-
};
|
|
558
|
-
selectorResolver.hasResolver = true;
|
|
559
|
-
return selectorResolver;
|
|
560
|
-
} );
|
|
582
|
+
const selectorResolver = ( ...args ) => {
|
|
583
|
+
fulfillSelector( args );
|
|
584
|
+
return selector( ...args );
|
|
585
|
+
};
|
|
586
|
+
selectorResolver.hasResolver = true;
|
|
587
|
+
return selectorResolver;
|
|
561
588
|
}
|
package/src/registry.js
CHANGED
|
@@ -9,7 +9,7 @@ import deprecated from '@wordpress/deprecated';
|
|
|
9
9
|
import createReduxStore from './redux-store';
|
|
10
10
|
import coreDataStore from './store';
|
|
11
11
|
import { createEmitter } from './utils/emitter';
|
|
12
|
-
import { lock, unlock } from './
|
|
12
|
+
import { lock, unlock } from './lock-unlock';
|
|
13
13
|
|
|
14
14
|
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
15
15
|
|
package/src/test/privateAPIs.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { createRegistry } from '../registry';
|
|
5
5
|
import createReduxStore from '../redux-store';
|
|
6
|
-
import { unlock } from '../
|
|
6
|
+
import { unlock } from '../lock-unlock';
|
|
7
|
+
import { createRegistrySelector } from '../factory';
|
|
7
8
|
|
|
8
9
|
describe( 'Private data APIs', () => {
|
|
9
10
|
let registry;
|
|
@@ -32,23 +33,19 @@ describe( 'Private data APIs', () => {
|
|
|
32
33
|
getState: ( state ) => state,
|
|
33
34
|
},
|
|
34
35
|
actions: { setPublicPrice },
|
|
35
|
-
reducer: ( state, action ) => {
|
|
36
|
-
if ( action
|
|
36
|
+
reducer: ( state = { price: 1000, secretDiscount: 800 }, action ) => {
|
|
37
|
+
if ( action.type === 'SET_PRIVATE_PRICE' ) {
|
|
37
38
|
return {
|
|
38
39
|
...state,
|
|
39
|
-
secretDiscount: action
|
|
40
|
+
secretDiscount: action.price,
|
|
40
41
|
};
|
|
41
|
-
} else if ( action
|
|
42
|
+
} else if ( action.type === 'SET_PUBLIC_PRICE' ) {
|
|
42
43
|
return {
|
|
43
44
|
...state,
|
|
44
|
-
price: action
|
|
45
|
+
price: action.price,
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
|
-
return
|
|
48
|
-
price: 1000,
|
|
49
|
-
secretDiscount: 800,
|
|
50
|
-
...( state || {} ),
|
|
51
|
-
};
|
|
48
|
+
return state;
|
|
52
49
|
},
|
|
53
50
|
};
|
|
54
51
|
function createStore() {
|
|
@@ -147,6 +144,16 @@ describe( 'Private data APIs', () => {
|
|
|
147
144
|
expect( unlockedSelectors.getPublicPrice() ).toEqual( 1000 );
|
|
148
145
|
} );
|
|
149
146
|
|
|
147
|
+
it( 'should return stable references to selectors', () => {
|
|
148
|
+
const groceryStore = createStore();
|
|
149
|
+
unlock( groceryStore ).registerPrivateSelectors( {
|
|
150
|
+
getSecretDiscount,
|
|
151
|
+
} );
|
|
152
|
+
const select = unlock( registry.select( groceryStore ) );
|
|
153
|
+
expect( select.getPublicPrice ).toBe( select.getPublicPrice );
|
|
154
|
+
expect( select.getSecretDiscount ).toBe( select.getSecretDiscount );
|
|
155
|
+
} );
|
|
156
|
+
|
|
150
157
|
it( 'should support registerStore', () => {
|
|
151
158
|
const groceryStore = registry.registerStore(
|
|
152
159
|
storeName,
|
|
@@ -195,6 +202,42 @@ describe( 'Private data APIs', () => {
|
|
|
195
202
|
);
|
|
196
203
|
expect( subPrivateSelectors.getSecretDiscount() ).toEqual( 800 );
|
|
197
204
|
} );
|
|
205
|
+
|
|
206
|
+
it( 'should support private registry selectors', () => {
|
|
207
|
+
const groceryStore = createStore();
|
|
208
|
+
const otherStore = createReduxStore( 'other', {
|
|
209
|
+
reducer: ( state = {} ) => state,
|
|
210
|
+
} );
|
|
211
|
+
unlock( otherStore ).registerPrivateSelectors( {
|
|
212
|
+
getPrice: createRegistrySelector(
|
|
213
|
+
( select ) => () => select( groceryStore ).getPublicPrice()
|
|
214
|
+
),
|
|
215
|
+
} );
|
|
216
|
+
registry.register( otherStore );
|
|
217
|
+
const privateSelectors = unlock( registry.select( otherStore ) );
|
|
218
|
+
expect( privateSelectors.getPrice() ).toEqual( 1000 );
|
|
219
|
+
} );
|
|
220
|
+
|
|
221
|
+
it( 'should support calling a private registry selector from a public selector', () => {
|
|
222
|
+
const groceryStore = createStore();
|
|
223
|
+
const getPriceWithShipping = createRegistrySelector(
|
|
224
|
+
( select ) => () => select( groceryStore ).getPublicPrice() + 5
|
|
225
|
+
);
|
|
226
|
+
const store = createReduxStore( 'a', {
|
|
227
|
+
reducer: ( state = {} ) => state,
|
|
228
|
+
selectors: {
|
|
229
|
+
getPriceWithShippingAndTax: ( state ) =>
|
|
230
|
+
getPriceWithShipping( state ) * 1.1,
|
|
231
|
+
},
|
|
232
|
+
} );
|
|
233
|
+
unlock( store ).registerPrivateSelectors( {
|
|
234
|
+
getPriceWithShipping,
|
|
235
|
+
} );
|
|
236
|
+
registry.register( store );
|
|
237
|
+
expect(
|
|
238
|
+
registry.select( store ).getPriceWithShippingAndTax()
|
|
239
|
+
).toEqual( 1105.5 );
|
|
240
|
+
} );
|
|
198
241
|
} );
|
|
199
242
|
|
|
200
243
|
describe( 'private actions', () => {
|
|
@@ -263,6 +306,16 @@ describe( 'Private data APIs', () => {
|
|
|
263
306
|
).toEqual( 400 );
|
|
264
307
|
} );
|
|
265
308
|
|
|
309
|
+
it( 'should return stable references to actions', () => {
|
|
310
|
+
const groceryStore = createStore();
|
|
311
|
+
unlock( groceryStore ).registerPrivateActions( {
|
|
312
|
+
setSecretDiscount,
|
|
313
|
+
} );
|
|
314
|
+
const disp = unlock( registry.dispatch( groceryStore ) );
|
|
315
|
+
expect( disp.setPublicPrice ).toBe( disp.setPublicPrice );
|
|
316
|
+
expect( disp.setSecretDiscount ).toBe( disp.setSecretDiscount );
|
|
317
|
+
} );
|
|
318
|
+
|
|
266
319
|
it( 'should dispatch public actions on the unlocked store', () => {
|
|
267
320
|
const groceryStore = createStore();
|
|
268
321
|
unlock( groceryStore ).registerPrivateActions( {
|
|
@@ -294,6 +347,29 @@ describe( 'Private data APIs', () => {
|
|
|
294
347
|
).toEqual( 100 );
|
|
295
348
|
} );
|
|
296
349
|
|
|
350
|
+
it( 'should expose unlocked private selectors and actions to thunks', () => {
|
|
351
|
+
const groceryStore = createStore();
|
|
352
|
+
unlock( groceryStore ).registerPrivateSelectors( {
|
|
353
|
+
getSecretDiscount,
|
|
354
|
+
} );
|
|
355
|
+
unlock( groceryStore ).registerPrivateActions( {
|
|
356
|
+
setSecretDiscount,
|
|
357
|
+
doubleSecretDiscount() {
|
|
358
|
+
return ( { dispatch, select } ) => {
|
|
359
|
+
dispatch.setSecretDiscount(
|
|
360
|
+
select.getSecretDiscount() * 2
|
|
361
|
+
);
|
|
362
|
+
};
|
|
363
|
+
},
|
|
364
|
+
} );
|
|
365
|
+
const privateActions = unlock( registry.dispatch( groceryStore ) );
|
|
366
|
+
privateActions.setSecretDiscount( 100 );
|
|
367
|
+
privateActions.doubleSecretDiscount();
|
|
368
|
+
expect(
|
|
369
|
+
unlock( registry.select( groceryStore ) ).getSecretDiscount()
|
|
370
|
+
).toEqual( 200 );
|
|
371
|
+
} );
|
|
372
|
+
|
|
297
373
|
it( 'should support registerStore', () => {
|
|
298
374
|
const groceryStore = registry.registerStore(
|
|
299
375
|
storeName,
|