@wordpress/data 6.8.0 → 6.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +39 -4
- package/build/components/use-select/index.js +113 -0
- package/build/components/use-select/index.js.map +1 -1
- package/build/components/with-registry/index.js.map +1 -1
- package/build/controls.js.map +1 -1
- package/build/index.js +22 -3
- package/build/index.js.map +1 -1
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/redux-store/index.js +52 -5
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/registry.js +31 -4
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/store/index.js.map +1 -1
- package/build-module/components/use-select/index.js +111 -0
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/components/with-registry/index.js.map +1 -1
- package/build-module/controls.js.map +1 -1
- package/build-module/index.js +13 -1
- package/build-module/index.js.map +1 -1
- package/build-module/plugins/persistence/index.js.map +1 -1
- package/build-module/redux-store/index.js +52 -5
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/registry.js +31 -4
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/store/index.js.map +1 -1
- package/build-types/redux-store/metadata/utils.d.ts.map +1 -1
- package/build-types/types.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/components/use-select/index.js +127 -0
- package/src/components/use-select/test/index.js +71 -0
- package/src/components/use-select/test/suspense.js +164 -0
- package/src/components/with-dispatch/test/index.js +4 -5
- package/src/components/with-registry/index.js +8 -7
- package/src/components/with-select/test/index.js +12 -18
- package/src/controls.js +16 -11
- package/src/index.js +16 -1
- package/src/plugins/persistence/index.js +2 -4
- package/src/redux-store/index.js +51 -5
- package/src/redux-store/metadata/test/utils.js +1 -2
- package/src/redux-store/metadata/utils.ts +24 -24
- package/src/redux-store/test/index.js +4 -3
- package/src/registry.js +30 -4
- package/src/resolvers-cache-middleware.js +33 -34
- package/src/store/index.js +10 -6
- package/src/test/registry.js +6 -7
- package/src/types.ts +4 -5
- package/tsconfig.json +2 -2
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/redux-store/index.js"],"names":["trimUndefinedValues","array","result","i","length","undefined","splice","createResolversCache","cache","isRunning","selectorName","args","get","clear","delete","markAsRunning","EquivalentKeyMap","set","createReduxStore","key","options","name","instantiate","registry","reducer","thunkArgs","dispatch","Object","assign","action","store","getActions","select","selector","__unstableOriginalGetState","getSelectors","resolveSelect","getResolveSelectors","instantiateReduxStore","resolversCache","resolvers","actions","mapActions","metadataActions","selectors","mapSelectors","metadataSelectors","state","metadata","isRegistrySelector","root","mapResolvers","resolveSelectors","mapResolveSelectors","getState","subscribe","listener","lastState","hasChanged","controls","builtinControls","normalizedControls","control","isRegistryControl","middlewares","promise","enhancers","window","__REDUX_DEVTOOLS_EXTENSION__","push","instanceId","initialState","enhancedReducer","metadataReducer","createStateSelector","registrySelector","runSelector","argsLength","arguments","Array","hasResolver","createBoundAction","Promise","resolve","storeSelectors","apply","reject","hasFinished","hasFinishedResolution","finalize","hasFailed","hasResolutionFailed","error","getResolutionError","getResult","unsubscribe","mappedResolvers","resolver","fulfill","mapSelector","selectorResolver","fulfillSelector","isFulfilled","hasStartedResolution","setTimeout","startResolution","fulfillResolver","finishResolution","failResolution"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAtBA;AACA;AACA;;AAMA;AACA;AACA;;AAGA;AACA;AACA;;AASA;;AACA;;AACA;AAEA,MAAMA,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAMC,MAAM,GAAG,CAAE,GAAGD,KAAL,CAAf;;AACA,OAAM,IAAIE,CAAC,GAAG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,GAA+B,IAA/B;AACA,WAAOoB,gBAAP;AACA,GApED;;AAsEA,SAAO;AACN5D,IAAAA,SAAS,EAAEwD,eADL;AAENpD,IAAAA,SAAS,EAAE,uBAAWA,SAAX,EAAsBuD,WAAtB;AAFL,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeO,eAAf,CAAgC5E,KAAhC,EAAuCU,SAAvC,EAAkD9B,YAAlD,EAA0E;AACzE,QAAMuF,QAAQ,GAAG,iBAAKzD,SAAL,EAAgB,CAAE9B,YAAF,CAAhB,CAAjB;;AACA,MAAK,CAAEuF,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAPtF,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMkB,MAAM,GAAGoE,QAAQ,CAACC,OAAT,CAAkB,GAAGvF,IAArB,CAAf;;AACA,MAAKkB,MAAL,EAAc;AACb,UAAMC,KAAK,CAACJ,QAAN,CAAgBG,MAAhB,CAAN;AACA;AACD","sourcesContent":["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport { flowRight, get, mapValues, omit } from 'lodash';\nimport combineReducers from 'turbo-combine-reducers';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport createReduxRoutineMiddleware from '@wordpress/redux-routine';\n\n/**\n * Internal dependencies\n */\nimport { builtinControls } from '../controls';\nimport promise from '../promise-middleware';\nimport createResolversCacheMiddleware from '../resolvers-cache-middleware';\nimport createThunkMiddleware from './thunk-middleware';\nimport metadataReducer from './metadata/reducer';\nimport * as metadataSelectors from './metadata/selectors';\nimport * as metadataActions from './metadata/actions';\n\n/** @typedef {import('../types').DataRegistry} DataRegistry */\n/** @typedef {import('../types').StoreDescriptor} StoreDescriptor */\n/** @typedef {import('../types').ReduxStoreConfig} ReduxStoreConfig */\n\nconst trimUndefinedValues = ( array ) => {\n\tconst result = [ ...array ];\n\tfor ( let i = result.length - 1; i >= 0; i-- ) {\n\t\tif ( result[ i ] === undefined ) {\n\t\t\tresult.splice( i, 1 );\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * Create a cache to track whether resolvers started running or not.\n *\n * @return {Object} Resolvers Cache.\n */\nfunction createResolversCache() {\n\tconst cache = {};\n\treturn {\n\t\tisRunning( selectorName, args ) {\n\t\t\treturn (\n\t\t\t\tcache[ selectorName ] &&\n\t\t\t\tcache[ selectorName ].get( trimUndefinedValues( args ) )\n\t\t\t);\n\t\t},\n\n\t\tclear( selectorName, args ) {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( trimUndefinedValues( args ) );\n\t\t\t}\n\t\t},\n\n\t\tmarkAsRunning( selectorName, args ) {\n\t\t\tif ( ! cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ] = new EquivalentKeyMap();\n\t\t\t}\n\n\t\t\tcache[ selectorName ].set( trimUndefinedValues( args ), true );\n\t\t},\n\t};\n}\n\n/**\n * Creates a data store descriptor for the provided Redux store configuration containing\n * properties describing reducer, actions, selectors, controls and resolvers.\n *\n * @example\n * ```js\n * import { createReduxStore } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * ```\n *\n * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor} Store Object.\n */\nexport default function createReduxStore( key, options ) {\n\treturn {\n\t\tname: key,\n\t\tinstantiate: ( registry ) => {\n\t\t\tconst reducer = options.reducer;\n\t\t\tconst thunkArgs = {\n\t\t\t\tregistry,\n\t\t\t\tget dispatch() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( action ) => store.dispatch( action ),\n\t\t\t\t\t\tgetActions()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget select() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\tselector( store.__unstableOriginalGetState() ),\n\t\t\t\t\t\tgetSelectors()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget resolveSelect() {\n\t\t\t\t\treturn getResolveSelectors();\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst store = instantiateReduxStore(\n\t\t\t\tkey,\n\t\t\t\toptions,\n\t\t\t\tregistry,\n\t\t\t\tthunkArgs\n\t\t\t);\n\t\t\tconst resolversCache = createResolversCache();\n\n\t\t\tlet resolvers;\n\t\t\tconst actions = mapActions(\n\t\t\t\t{\n\t\t\t\t\t...metadataActions,\n\t\t\t\t\t...options.actions,\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\n\t\t\tlet selectors = mapSelectors(\n\t\t\t\t{\n\t\t\t\t\t...mapValues(\n\t\t\t\t\t\tmetadataSelectors,\n\t\t\t\t\t\t( selector ) => ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.metadata, ...args )\n\t\t\t\t\t),\n\t\t\t\t\t...mapValues( options.selectors, ( selector ) => {\n\t\t\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\t\t\tselector.registry = registry;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.root, ...args );\n\t\t\t\t\t} ),\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\t\t\tif ( options.resolvers ) {\n\t\t\t\tconst result = mapResolvers(\n\t\t\t\t\toptions.resolvers,\n\t\t\t\t\tselectors,\n\t\t\t\t\tstore,\n\t\t\t\t\tresolversCache\n\t\t\t\t);\n\t\t\t\tresolvers = result.resolvers;\n\t\t\t\tselectors = result.selectors;\n\t\t\t}\n\n\t\t\tconst resolveSelectors = mapResolveSelectors( selectors, store );\n\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\n\n\t\t\t// We have some modules monkey-patching the store object\n\t\t\t// It's wrong to do so but until we refactor all of our effects to controls\n\t\t\t// We need to keep the same \"store\" instance here.\n\t\t\tstore.__unstableOriginalGetState = store.getState;\n\t\t\tstore.getState = () => store.__unstableOriginalGetState().root;\n\n\t\t\t// Customize subscribe behavior to call listeners only on effective change,\n\t\t\t// not on every dispatch.\n\t\t\tconst subscribe =\n\t\t\t\tstore &&\n\t\t\t\t( ( listener ) => {\n\t\t\t\t\tlet lastState = store.__unstableOriginalGetState();\n\t\t\t\t\treturn store.subscribe( () => {\n\t\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\t\t\tconst hasChanged = state !== lastState;\n\t\t\t\t\t\tlastState = state;\n\n\t\t\t\t\t\tif ( hasChanged ) {\n\t\t\t\t\t\t\tlistener();\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\t// This can be simplified to just { subscribe, getSelectors, getActions }\n\t\t\t// Once we remove the use function.\n\t\t\treturn {\n\t\t\t\treducer,\n\t\t\t\tstore,\n\t\t\t\tactions,\n\t\t\t\tselectors,\n\t\t\t\tresolvers,\n\t\t\t\tgetSelectors,\n\t\t\t\tgetResolveSelectors,\n\t\t\t\tgetActions,\n\t\t\t\tsubscribe,\n\t\t\t};\n\t\t},\n\t};\n}\n\n/**\n * Creates a redux store for a namespace.\n *\n * @param {string} key Unique namespace identifier.\n * @param {Object} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n * @param {DataRegistry} registry Registry reference.\n * @param {Object} thunkArgs Argument object for the thunk middleware.\n * @return {Object} Newly created redux store.\n */\nfunction instantiateReduxStore( key, options, registry, thunkArgs ) {\n\tconst controls = {\n\t\t...options.controls,\n\t\t...builtinControls,\n\t};\n\n\tconst normalizedControls = mapValues( controls, ( control ) =>\n\t\tcontrol.isRegistryControl ? control( registry ) : control\n\t);\n\n\tconst middlewares = [\n\t\tcreateResolversCacheMiddleware( registry, key ),\n\t\tpromise,\n\t\tcreateReduxRoutineMiddleware( normalizedControls ),\n\t\tcreateThunkMiddleware( thunkArgs ),\n\t];\n\n\tconst enhancers = [ applyMiddleware( ...middlewares ) ];\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__REDUX_DEVTOOLS_EXTENSION__\n\t) {\n\t\tenhancers.push(\n\t\t\twindow.__REDUX_DEVTOOLS_EXTENSION__( {\n\t\t\t\tname: key,\n\t\t\t\tinstanceId: key,\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst { reducer, initialState } = options;\n\tconst enhancedReducer = combineReducers( {\n\t\tmetadata: metadataReducer,\n\t\troot: reducer,\n\t} );\n\n\treturn createStore(\n\t\tenhancedReducer,\n\t\t{ root: initialState },\n\t\tflowRight( enhancers )\n\t);\n}\n\n/**\n * Maps selectors to a store.\n *\n * @param {Object} selectors Selectors to register. Keys will be used as the\n * public facing API. Selectors will get passed the\n * state as first argument.\n * @param {Object} store The store to which the selectors should be mapped.\n * @return {Object} Selectors mapped to the provided store.\n */\nfunction mapSelectors( selectors, store ) {\n\tconst createStateSelector = ( registrySelector ) => {\n\t\tconst selector = function runSelector() {\n\t\t\t// This function is an optimized implementation of:\n\t\t\t//\n\t\t\t// selector( store.getState(), ...arguments )\n\t\t\t//\n\t\t\t// Where the above would incur an `Array#concat` in its application,\n\t\t\t// the logic here instead efficiently constructs an arguments array via\n\t\t\t// direct assignment.\n\t\t\tconst argsLength = arguments.length;\n\t\t\tconst args = new Array( argsLength + 1 );\n\t\t\targs[ 0 ] = store.__unstableOriginalGetState();\n\t\t\tfor ( let i = 0; i < argsLength; i++ ) {\n\t\t\t\targs[ i + 1 ] = arguments[ i ];\n\t\t\t}\n\n\t\t\treturn registrySelector( ...args );\n\t\t};\n\t\tselector.hasResolver = false;\n\t\treturn selector;\n\t};\n\n\treturn mapValues( selectors, createStateSelector );\n}\n\n/**\n * Maps actions to dispatch from a given store.\n *\n * @param {Object} actions Actions to register.\n * @param {Object} store The redux store to which the actions should be mapped.\n *\n * @return {Object} Actions mapped to the redux store provided.\n */\nfunction mapActions( actions, store ) {\n\tconst createBoundAction = ( action ) => ( ...args ) => {\n\t\treturn Promise.resolve( store.dispatch( action( ...args ) ) );\n\t};\n\n\treturn mapValues( actions, createBoundAction );\n}\n\n/**\n * Maps selectors to functions that return a resolution promise for them\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their resolution functions.\n */\nfunction mapResolveSelectors( selectors, store ) {\n\tconst storeSelectors = omit( selectors, [\n\t\t'getIsResolving',\n\t\t'hasStartedResolution',\n\t\t'hasFinishedResolution',\n\t\t'hasResolutionFailed',\n\t\t'isResolving',\n\t\t'getCachedResolvers',\n\t\t'getResolutionState',\n\t\t'getResolutionError',\n\t] );\n\n\treturn mapValues( storeSelectors, ( selector, selectorName ) => {\n\t\t// If the selector doesn't have a resolver, just convert the return value\n\t\t// (including exceptions) to a Promise, no additional extra behavior is needed.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn async ( ...args ) => selector.apply( null, args );\n\t\t}\n\n\t\treturn ( ...args ) => {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\tconst hasFinished = () =>\n\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args );\n\t\t\t\tconst finalize = ( result ) => {\n\t\t\t\t\tconst hasFailed = selectors.hasResolutionFailed(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t\tif ( hasFailed ) {\n\t\t\t\t\t\tconst error = selectors.getResolutionError(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresolve( result );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst getResult = () => selector.apply( null, args );\n\t\t\t\t// Trigger the selector (to trigger the resolver)\n\t\t\t\tconst result = getResult();\n\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\treturn finalize( result );\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tfinalize( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t} );\n}\n\n/**\n * Returns resolvers with matched selectors for a given namespace.\n * Resolvers are side effects invoked once per argument set of a given selector call,\n * used in ensuring that the data needs for the selector are satisfied.\n *\n * @param {Object} resolvers Resolvers to register.\n * @param {Object} selectors The current selectors to be modified.\n * @param {Object} store The redux store to which the resolvers should be mapped.\n * @param {Object} resolversCache Resolvers Cache.\n */\nfunction mapResolvers( resolvers, selectors, store, resolversCache ) {\n\t// The `resolver` can be either a function that does the resolution, or, in more advanced\n\t// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`.\n\t// Here we normalize the `resolver` function to an object with `fulfill` method.\n\tconst mappedResolvers = mapValues( resolvers, ( resolver ) => {\n\t\tif ( resolver.fulfill ) {\n\t\t\treturn resolver;\n\t\t}\n\n\t\treturn {\n\t\t\t...resolver, // Copy the enumerable properties of the resolver function.\n\t\t\tfulfill: resolver, // Add the fulfill method.\n\t\t};\n\t} );\n\n\tconst mapSelector = ( selector, selectorName ) => {\n\t\tconst resolver = resolvers[ selectorName ];\n\t\tif ( ! resolver ) {\n\t\t\tselector.hasResolver = false;\n\t\t\treturn selector;\n\t\t}\n\n\t\tconst selectorResolver = ( ...args ) => {\n\t\t\tasync function fulfillSelector() {\n\t\t\t\tconst state = store.getState();\n\n\t\t\t\tif (\n\t\t\t\t\tresolversCache.isRunning( selectorName, args ) ||\n\t\t\t\t\t( typeof resolver.isFulfilled === 'function' &&\n\t\t\t\t\t\tresolver.isFulfilled( state, ...args ) )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { metadata } = store.__unstableOriginalGetState();\n\n\t\t\t\tif (\n\t\t\t\t\tmetadataSelectors.hasStartedResolution(\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tresolversCache.markAsRunning( selectorName, args );\n\n\t\t\t\tsetTimeout( async () => {\n\t\t\t\t\tresolversCache.clear( selectorName, args );\n\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\tmetadataActions.startResolution( selectorName, args )\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait fulfillResolver(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\tmappedResolvers,\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t...args\n\t\t\t\t\t\t);\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.finishResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch ( error ) {\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.failResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs,\n\t\t\t\t\t\t\t\terror\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfulfillSelector( ...args );\n\t\t\treturn selector( ...args );\n\t\t};\n\t\tselectorResolver.hasResolver = true;\n\t\treturn selectorResolver;\n\t};\n\n\treturn {\n\t\tresolvers: mappedResolvers,\n\t\tselectors: mapValues( selectors, mapSelector ),\n\t};\n}\n\n/**\n * Calls a resolver given arguments\n *\n * @param {Object} store Store reference, for fulfilling via resolvers\n * @param {Object} resolvers Store Resolvers\n * @param {string} selectorName Selector name to fulfill.\n * @param {Array} args Selector Arguments.\n */\nasync function fulfillResolver( store, resolvers, selectorName, ...args ) {\n\tconst resolver = get( resolvers, [ selectorName ] );\n\tif ( ! resolver ) {\n\t\treturn;\n\t}\n\n\tconst action = resolver.fulfill( ...args );\n\tif ( action ) {\n\t\tawait store.dispatch( action );\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/redux-store/index.js"],"names":["trimUndefinedValues","array","result","i","length","undefined","splice","createResolversCache","cache","isRunning","selectorName","args","get","clear","delete","markAsRunning","EquivalentKeyMap","set","createReduxStore","key","options","name","instantiate","registry","reducer","thunkArgs","dispatch","Object","assign","action","store","getActions","select","selector","__unstableOriginalGetState","getSelectors","resolveSelect","getResolveSelectors","instantiateReduxStore","resolversCache","resolvers","actions","mapActions","metadataActions","selectors","mapSelectors","metadataSelectors","state","metadata","isRegistrySelector","root","mapResolvers","resolveSelectors","mapResolveSelectors","suspendSelectors","mapSuspendSelectors","getSuspendSelectors","getState","subscribe","listener","lastState","hasChanged","controls","builtinControls","normalizedControls","control","isRegistryControl","middlewares","promise","enhancers","window","__REDUX_DEVTOOLS_EXTENSION__","push","instanceId","initialState","enhancedReducer","metadataReducer","createStateSelector","registrySelector","runSelector","argsLength","arguments","Array","hasResolver","createBoundAction","Promise","resolve","storeSelectors","apply","reject","hasFinished","hasFinishedResolution","finalize","hasFailed","hasResolutionFailed","error","getResolutionError","getResult","unsubscribe","mappedResolvers","resolver","fulfill","mapSelector","selectorResolver","fulfillSelector","isFulfilled","hasStartedResolution","setTimeout","startResolution","fulfillResolver","finishResolution","failResolution"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AAKA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAtBA;AACA;AACA;;AAMA;AACA;AACA;;AAGA;AACA;AACA;;AASA;;AACA;;AACA;AAEA,MAAMA,mBAAmB,GAAKC,KAAF,IAAa;AACxC,QAAMC,MAAM,GAAG,CAAE,GAAGD,KAAL,CAAf;;AACA,OAAM,IAAIE,C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AS,EAAE,uBAAWA,SAAX,EAAsB0D,WAAtB;AAFL,GAAP;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAeO,eAAf,CAAgC/E,KAAhC,EAAuCU,SAAvC,EAAkD9B,YAAlD,EAA0E;AACzE,QAAM0F,QAAQ,GAAG,iBAAK5D,SAAL,EAAgB,CAAE9B,YAAF,CAAhB,CAAjB;;AACA,MAAK,CAAE0F,QAAP,EAAkB;AACjB;AACA;;AAJwE,qCAAPzF,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAMzE,QAAMkB,MAAM,GAAGuE,QAAQ,CAACC,OAAT,CAAkB,GAAG1F,IAArB,CAAf;;AACA,MAAKkB,MAAL,EAAc;AACb,UAAMC,KAAK,CAACJ,QAAN,CAAgBG,MAAhB,CAAN;AACA;AACD","sourcesContent":["/**\n * External dependencies\n */\nimport { createStore, applyMiddleware } from 'redux';\nimport { flowRight, get, mapValues, omit } from 'lodash';\nimport combineReducers from 'turbo-combine-reducers';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * WordPress dependencies\n */\nimport createReduxRoutineMiddleware from '@wordpress/redux-routine';\n\n/**\n * Internal dependencies\n */\nimport { builtinControls } from '../controls';\nimport promise from '../promise-middleware';\nimport createResolversCacheMiddleware from '../resolvers-cache-middleware';\nimport createThunkMiddleware from './thunk-middleware';\nimport metadataReducer from './metadata/reducer';\nimport * as metadataSelectors from './metadata/selectors';\nimport * as metadataActions from './metadata/actions';\n\n/** @typedef {import('../types').DataRegistry} DataRegistry */\n/** @typedef {import('../types').StoreDescriptor} StoreDescriptor */\n/** @typedef {import('../types').ReduxStoreConfig} ReduxStoreConfig */\n\nconst trimUndefinedValues = ( array ) => {\n\tconst result = [ ...array ];\n\tfor ( let i = result.length - 1; i >= 0; i-- ) {\n\t\tif ( result[ i ] === undefined ) {\n\t\t\tresult.splice( i, 1 );\n\t\t}\n\t}\n\treturn result;\n};\n\n/**\n * Create a cache to track whether resolvers started running or not.\n *\n * @return {Object} Resolvers Cache.\n */\nfunction createResolversCache() {\n\tconst cache = {};\n\treturn {\n\t\tisRunning( selectorName, args ) {\n\t\t\treturn (\n\t\t\t\tcache[ selectorName ] &&\n\t\t\t\tcache[ selectorName ].get( trimUndefinedValues( args ) )\n\t\t\t);\n\t\t},\n\n\t\tclear( selectorName, args ) {\n\t\t\tif ( cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ].delete( trimUndefinedValues( args ) );\n\t\t\t}\n\t\t},\n\n\t\tmarkAsRunning( selectorName, args ) {\n\t\t\tif ( ! cache[ selectorName ] ) {\n\t\t\t\tcache[ selectorName ] = new EquivalentKeyMap();\n\t\t\t}\n\n\t\t\tcache[ selectorName ].set( trimUndefinedValues( args ), true );\n\t\t},\n\t};\n}\n\n/**\n * Creates a data store descriptor for the provided Redux store configuration containing\n * properties describing reducer, actions, selectors, controls and resolvers.\n *\n * @example\n * ```js\n * import { createReduxStore } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * ```\n *\n * @param {string} key Unique namespace identifier.\n * @param {ReduxStoreConfig} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n *\n * @return {StoreDescriptor} Store Object.\n */\nexport default function createReduxStore( key, options ) {\n\treturn {\n\t\tname: key,\n\t\tinstantiate: ( registry ) => {\n\t\t\tconst reducer = options.reducer;\n\t\t\tconst thunkArgs = {\n\t\t\t\tregistry,\n\t\t\t\tget dispatch() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( action ) => store.dispatch( action ),\n\t\t\t\t\t\tgetActions()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget select() {\n\t\t\t\t\treturn Object.assign(\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\tselector( store.__unstableOriginalGetState() ),\n\t\t\t\t\t\tgetSelectors()\n\t\t\t\t\t);\n\t\t\t\t},\n\t\t\t\tget resolveSelect() {\n\t\t\t\t\treturn getResolveSelectors();\n\t\t\t\t},\n\t\t\t};\n\n\t\t\tconst store = instantiateReduxStore(\n\t\t\t\tkey,\n\t\t\t\toptions,\n\t\t\t\tregistry,\n\t\t\t\tthunkArgs\n\t\t\t);\n\t\t\tconst resolversCache = createResolversCache();\n\n\t\t\tlet resolvers;\n\t\t\tconst actions = mapActions(\n\t\t\t\t{\n\t\t\t\t\t...metadataActions,\n\t\t\t\t\t...options.actions,\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\n\t\t\tlet selectors = mapSelectors(\n\t\t\t\t{\n\t\t\t\t\t...mapValues(\n\t\t\t\t\t\tmetadataSelectors,\n\t\t\t\t\t\t( selector ) =>\n\t\t\t\t\t\t\t( state, ...args ) =>\n\t\t\t\t\t\t\t\tselector( state.metadata, ...args )\n\t\t\t\t\t),\n\t\t\t\t\t...mapValues( options.selectors, ( selector ) => {\n\t\t\t\t\t\tif ( selector.isRegistrySelector ) {\n\t\t\t\t\t\t\tselector.registry = registry;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn ( state, ...args ) =>\n\t\t\t\t\t\t\tselector( state.root, ...args );\n\t\t\t\t\t} ),\n\t\t\t\t},\n\t\t\t\tstore\n\t\t\t);\n\t\t\tif ( options.resolvers ) {\n\t\t\t\tconst result = mapResolvers(\n\t\t\t\t\toptions.resolvers,\n\t\t\t\t\tselectors,\n\t\t\t\t\tstore,\n\t\t\t\t\tresolversCache\n\t\t\t\t);\n\t\t\t\tresolvers = result.resolvers;\n\t\t\t\tselectors = result.selectors;\n\t\t\t}\n\n\t\t\tconst resolveSelectors = mapResolveSelectors( selectors, store );\n\t\t\tconst suspendSelectors = mapSuspendSelectors( selectors, store );\n\n\t\t\tconst getSelectors = () => selectors;\n\t\t\tconst getActions = () => actions;\n\t\t\tconst getResolveSelectors = () => resolveSelectors;\n\t\t\tconst getSuspendSelectors = () => suspendSelectors;\n\n\t\t\t// We have some modules monkey-patching the store object\n\t\t\t// It's wrong to do so but until we refactor all of our effects to controls\n\t\t\t// We need to keep the same \"store\" instance here.\n\t\t\tstore.__unstableOriginalGetState = store.getState;\n\t\t\tstore.getState = () => store.__unstableOriginalGetState().root;\n\n\t\t\t// Customize subscribe behavior to call listeners only on effective change,\n\t\t\t// not on every dispatch.\n\t\t\tconst subscribe =\n\t\t\t\tstore &&\n\t\t\t\t( ( listener ) => {\n\t\t\t\t\tlet lastState = store.__unstableOriginalGetState();\n\t\t\t\t\treturn store.subscribe( () => {\n\t\t\t\t\t\tconst state = store.__unstableOriginalGetState();\n\t\t\t\t\t\tconst hasChanged = state !== lastState;\n\t\t\t\t\t\tlastState = state;\n\n\t\t\t\t\t\tif ( hasChanged ) {\n\t\t\t\t\t\t\tlistener();\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t} );\n\n\t\t\t// This can be simplified to just { subscribe, getSelectors, getActions }\n\t\t\t// Once we remove the use function.\n\t\t\treturn {\n\t\t\t\treducer,\n\t\t\t\tstore,\n\t\t\t\tactions,\n\t\t\t\tselectors,\n\t\t\t\tresolvers,\n\t\t\t\tgetSelectors,\n\t\t\t\tgetResolveSelectors,\n\t\t\t\tgetSuspendSelectors,\n\t\t\t\tgetActions,\n\t\t\t\tsubscribe,\n\t\t\t};\n\t\t},\n\t};\n}\n\n/**\n * Creates a redux store for a namespace.\n *\n * @param {string} key Unique namespace identifier.\n * @param {Object} options Registered store options, with properties\n * describing reducer, actions, selectors,\n * and resolvers.\n * @param {DataRegistry} registry Registry reference.\n * @param {Object} thunkArgs Argument object for the thunk middleware.\n * @return {Object} Newly created redux store.\n */\nfunction instantiateReduxStore( key, options, registry, thunkArgs ) {\n\tconst controls = {\n\t\t...options.controls,\n\t\t...builtinControls,\n\t};\n\n\tconst normalizedControls = mapValues( controls, ( control ) =>\n\t\tcontrol.isRegistryControl ? control( registry ) : control\n\t);\n\n\tconst middlewares = [\n\t\tcreateResolversCacheMiddleware( registry, key ),\n\t\tpromise,\n\t\tcreateReduxRoutineMiddleware( normalizedControls ),\n\t\tcreateThunkMiddleware( thunkArgs ),\n\t];\n\n\tconst enhancers = [ applyMiddleware( ...middlewares ) ];\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\twindow.__REDUX_DEVTOOLS_EXTENSION__\n\t) {\n\t\tenhancers.push(\n\t\t\twindow.__REDUX_DEVTOOLS_EXTENSION__( {\n\t\t\t\tname: key,\n\t\t\t\tinstanceId: key,\n\t\t\t} )\n\t\t);\n\t}\n\n\tconst { reducer, initialState } = options;\n\tconst enhancedReducer = combineReducers( {\n\t\tmetadata: metadataReducer,\n\t\troot: reducer,\n\t} );\n\n\treturn createStore(\n\t\tenhancedReducer,\n\t\t{ root: initialState },\n\t\tflowRight( enhancers )\n\t);\n}\n\n/**\n * Maps selectors to a store.\n *\n * @param {Object} selectors Selectors to register. Keys will be used as the\n * public facing API. Selectors will get passed the\n * state as first argument.\n * @param {Object} store The store to which the selectors should be mapped.\n * @return {Object} Selectors mapped to the provided store.\n */\nfunction mapSelectors( selectors, store ) {\n\tconst createStateSelector = ( registrySelector ) => {\n\t\tconst selector = function runSelector() {\n\t\t\t// This function is an optimized implementation of:\n\t\t\t//\n\t\t\t// selector( store.getState(), ...arguments )\n\t\t\t//\n\t\t\t// Where the above would incur an `Array#concat` in its application,\n\t\t\t// the logic here instead efficiently constructs an arguments array via\n\t\t\t// direct assignment.\n\t\t\tconst argsLength = arguments.length;\n\t\t\tconst args = new Array( argsLength + 1 );\n\t\t\targs[ 0 ] = store.__unstableOriginalGetState();\n\t\t\tfor ( let i = 0; i < argsLength; i++ ) {\n\t\t\t\targs[ i + 1 ] = arguments[ i ];\n\t\t\t}\n\n\t\t\treturn registrySelector( ...args );\n\t\t};\n\t\tselector.hasResolver = false;\n\t\treturn selector;\n\t};\n\n\treturn mapValues( selectors, createStateSelector );\n}\n\n/**\n * Maps actions to dispatch from a given store.\n *\n * @param {Object} actions Actions to register.\n * @param {Object} store The redux store to which the actions should be mapped.\n *\n * @return {Object} Actions mapped to the redux store provided.\n */\nfunction mapActions( actions, store ) {\n\tconst createBoundAction =\n\t\t( action ) =>\n\t\t( ...args ) => {\n\t\t\treturn Promise.resolve( store.dispatch( action( ...args ) ) );\n\t\t};\n\n\treturn mapValues( actions, createBoundAction );\n}\n\n/**\n * Maps selectors to functions that return a resolution promise for them\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their resolution functions.\n */\nfunction mapResolveSelectors( selectors, store ) {\n\tconst storeSelectors = omit( selectors, [\n\t\t'getIsResolving',\n\t\t'hasStartedResolution',\n\t\t'hasFinishedResolution',\n\t\t'hasResolutionFailed',\n\t\t'isResolving',\n\t\t'getCachedResolvers',\n\t\t'getResolutionState',\n\t\t'getResolutionError',\n\t] );\n\n\treturn mapValues( storeSelectors, ( selector, selectorName ) => {\n\t\t// If the selector doesn't have a resolver, just convert the return value\n\t\t// (including exceptions) to a Promise, no additional extra behavior is needed.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn async ( ...args ) => selector.apply( null, args );\n\t\t}\n\n\t\treturn ( ...args ) => {\n\t\t\treturn new Promise( ( resolve, reject ) => {\n\t\t\t\tconst hasFinished = () =>\n\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args );\n\t\t\t\tconst finalize = ( result ) => {\n\t\t\t\t\tconst hasFailed = selectors.hasResolutionFailed(\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t);\n\t\t\t\t\tif ( hasFailed ) {\n\t\t\t\t\t\tconst error = selectors.getResolutionError(\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\targs\n\t\t\t\t\t\t);\n\t\t\t\t\t\treject( error );\n\t\t\t\t\t} else {\n\t\t\t\t\t\tresolve( result );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t\tconst getResult = () => selector.apply( null, args );\n\t\t\t\t// Trigger the selector (to trigger the resolver)\n\t\t\t\tconst result = getResult();\n\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\treturn finalize( result );\n\t\t\t\t}\n\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif ( hasFinished() ) {\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t\tfinalize( getResult() );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t} );\n}\n\n/**\n * Maps selectors to functions that throw a suspense promise if not yet resolved.\n *\n * @param {Object} selectors Selectors to map.\n * @param {Object} store The redux store the selectors select from.\n *\n * @return {Object} Selectors mapped to their suspense functions.\n */\nfunction mapSuspendSelectors( selectors, store ) {\n\treturn mapValues( selectors, ( selector, selectorName ) => {\n\t\t// Selector without a resolver doesn't have any extra suspense behavior.\n\t\tif ( ! selector.hasResolver ) {\n\t\t\treturn selector;\n\t\t}\n\n\t\treturn ( ...args ) => {\n\t\t\tconst result = selector.apply( null, args );\n\n\t\t\tif ( selectors.hasFinishedResolution( selectorName, args ) ) {\n\t\t\t\tif ( selectors.hasResolutionFailed( selectorName, args ) ) {\n\t\t\t\t\tthrow selectors.getResolutionError( selectorName, args );\n\t\t\t\t}\n\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tthrow new Promise( ( resolve ) => {\n\t\t\t\tconst unsubscribe = store.subscribe( () => {\n\t\t\t\t\tif (\n\t\t\t\t\t\tselectors.hasFinishedResolution( selectorName, args )\n\t\t\t\t\t) {\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t\tunsubscribe();\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t} );\n\t\t};\n\t} );\n}\n\n/**\n * Returns resolvers with matched selectors for a given namespace.\n * Resolvers are side effects invoked once per argument set of a given selector call,\n * used in ensuring that the data needs for the selector are satisfied.\n *\n * @param {Object} resolvers Resolvers to register.\n * @param {Object} selectors The current selectors to be modified.\n * @param {Object} store The redux store to which the resolvers should be mapped.\n * @param {Object} resolversCache Resolvers Cache.\n */\nfunction mapResolvers( resolvers, selectors, store, resolversCache ) {\n\t// The `resolver` can be either a function that does the resolution, or, in more advanced\n\t// cases, an object with a `fullfill` method and other optional methods like `isFulfilled`.\n\t// Here we normalize the `resolver` function to an object with `fulfill` method.\n\tconst mappedResolvers = mapValues( resolvers, ( resolver ) => {\n\t\tif ( resolver.fulfill ) {\n\t\t\treturn resolver;\n\t\t}\n\n\t\treturn {\n\t\t\t...resolver, // Copy the enumerable properties of the resolver function.\n\t\t\tfulfill: resolver, // Add the fulfill method.\n\t\t};\n\t} );\n\n\tconst mapSelector = ( selector, selectorName ) => {\n\t\tconst resolver = resolvers[ selectorName ];\n\t\tif ( ! resolver ) {\n\t\t\tselector.hasResolver = false;\n\t\t\treturn selector;\n\t\t}\n\n\t\tconst selectorResolver = ( ...args ) => {\n\t\t\tasync function fulfillSelector() {\n\t\t\t\tconst state = store.getState();\n\n\t\t\t\tif (\n\t\t\t\t\tresolversCache.isRunning( selectorName, args ) ||\n\t\t\t\t\t( typeof resolver.isFulfilled === 'function' &&\n\t\t\t\t\t\tresolver.isFulfilled( state, ...args ) )\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst { metadata } = store.__unstableOriginalGetState();\n\n\t\t\t\tif (\n\t\t\t\t\tmetadataSelectors.hasStartedResolution(\n\t\t\t\t\t\tmetadata,\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\targs\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tresolversCache.markAsRunning( selectorName, args );\n\n\t\t\t\tsetTimeout( async () => {\n\t\t\t\t\tresolversCache.clear( selectorName, args );\n\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\tmetadataActions.startResolution( selectorName, args )\n\t\t\t\t\t);\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait fulfillResolver(\n\t\t\t\t\t\t\tstore,\n\t\t\t\t\t\t\tmappedResolvers,\n\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t...args\n\t\t\t\t\t\t);\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.finishResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch ( error ) {\n\t\t\t\t\t\tstore.dispatch(\n\t\t\t\t\t\t\tmetadataActions.failResolution(\n\t\t\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\t\t\targs,\n\t\t\t\t\t\t\t\terror\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t}\n\n\t\t\tfulfillSelector( ...args );\n\t\t\treturn selector( ...args );\n\t\t};\n\t\tselectorResolver.hasResolver = true;\n\t\treturn selectorResolver;\n\t};\n\n\treturn {\n\t\tresolvers: mappedResolvers,\n\t\tselectors: mapValues( selectors, mapSelector ),\n\t};\n}\n\n/**\n * Calls a resolver given arguments\n *\n * @param {Object} store Store reference, for fulfilling via resolvers\n * @param {Object} resolvers Store Resolvers\n * @param {string} selectorName Selector name to fulfill.\n * @param {Array} args Selector Arguments.\n */\nasync function fulfillResolver( store, resolvers, selectorName, ...args ) {\n\tconst resolver = get( resolvers, [ selectorName ] );\n\tif ( ! resolver ) {\n\t\treturn;\n\t}\n\n\tconst action = resolver.fulfill( ...args );\n\tif ( action ) {\n\t\tawait store.dispatch( action );\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/utils.ts"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState","selectorArgsToStateKey","args","len","length","idx","slice"],"mappings":";;;;;;;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/redux-store/metadata/utils.ts"],"names":["onSubKey","actionProperty","reducer","state","action","key","undefined","nextKeyState","selectorArgsToStateKey","args","len","length","idx","slice"],"mappings":";;;;;;;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAEnBC,cADD,IAICC,OADD,IAGA,YAAoD;AAAA,MAAlDC,KAAkD,uEAAhB,EAAgB;AAAA,MAAZC,MAAY;AACnD;AACA;AACA,QAAMC,GAAG,GAAGD,MAAM,CAAEH,cAAF,CAAlB;;AACA,MAAKI,GAAG,KAAKC,SAAb,EAAyB;AACxB,WAAOH,KAAP;AACA,GANkD,CAQnD;AACA;;;AACA,QAAMI,YAAY,GAAGL,OAAO,CAAEC,KAAK,CAAEE,GAAF,CAAP,EAAgBD,MAAhB,CAA5B;;AACA,MAAKG,YAAY,KAAKJ,KAAK,CAAEE,GAAF,CAA3B,EAAqC;AACpC,WAAOF,KAAP;AACA;;AAED,SAAO,EACN,GAAGA,KADG;AAEN,KAAEE,GAAF,GAASE;AAFH,GAAP;AAIA,CA1BK;AA4BP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,SAASC,sBAAT,CAAiCC,IAAjC,EAAsE;AAC5E,MAAKA,IAAI,KAAKH,SAAT,IAAsBG,IAAI,KAAK,IAApC,EAA2C;AAC1C,WAAO,EAAP;AACA;;AAED,QAAMC,GAAG,GAAGD,IAAI,CAACE,MAAjB;AACA,MAAIC,GAAG,GAAGF,GAAV;;AACA,SAAQE,GAAG,GAAG,CAAN,IAAWH,IAAI,CAAEG,GAAG,GAAG,CAAR,CAAJ,KAAoBN,SAAvC,EAAmD;AAClDM,IAAAA,GAAG;AACH;;AACD,SAAOA,GAAG,KAAKF,GAAR,GAAcD,IAAd,GAAqBA,IAAI,CAACI,KAAL,CAAY,CAAZ,EAAeD,GAAf,CAA5B;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport type { AnyAction, Reducer } from 'redux';\n\n/**\n * Higher-order reducer creator which creates a combined reducer object, keyed\n * by a property on the action object.\n *\n * @param actionProperty Action property by which to key object.\n * @return Higher-order reducer.\n */\nexport const onSubKey =\n\t< TState extends unknown, TAction extends AnyAction >(\n\t\tactionProperty: string\n\t) =>\n\t(\n\t\treducer: Reducer< TState, TAction >\n\t): Reducer< Record< string, TState >, TAction > =>\n\t( state: Record< string, TState > = {}, action ) => {\n\t\t// Retrieve subkey from action. Do not track if undefined; useful for cases\n\t\t// where reducer is scoped by action shape.\n\t\tconst key = action[ actionProperty ];\n\t\tif ( key === undefined ) {\n\t\t\treturn state;\n\t\t}\n\n\t\t// Avoid updating state if unchanged. Note that this also accounts for a\n\t\t// reducer which returns undefined on a key which is not yet tracked.\n\t\tconst nextKeyState = reducer( state[ key ], action );\n\t\tif ( nextKeyState === state[ key ] ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn {\n\t\t\t...state,\n\t\t\t[ key ]: nextKeyState,\n\t\t};\n\t};\n\n/**\n * Normalize selector argument array by defaulting `undefined` value to an empty array\n * and removing trailing `undefined` values.\n *\n * @param args Selector argument array\n * @return Normalized state key array\n */\nexport function selectorArgsToStateKey( args: unknown[] | null | undefined ) {\n\tif ( args === undefined || args === null ) {\n\t\treturn [];\n\t}\n\n\tconst len = args.length;\n\tlet idx = len;\n\twhile ( idx > 0 && args[ idx - 1 ] === undefined ) {\n\t\tidx--;\n\t}\n\treturn idx === len ? args : args.slice( 0, idx );\n}\n"]}
|
package/build/registry.js
CHANGED
|
@@ -110,14 +110,17 @@ function createRegistry() {
|
|
|
110
110
|
return store.getSelectors();
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
-
return parent
|
|
113
|
+
return parent === null || parent === void 0 ? void 0 : parent.select(storeName);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
function __unstableMarkListeningStores(callback, ref) {
|
|
117
117
|
listeningStores.clear();
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
return callback.call(this);
|
|
121
|
+
} finally {
|
|
122
|
+
ref.current = Array.from(listeningStores);
|
|
123
|
+
}
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
126
|
* Given the name of a registered store, returns an object containing the store's
|
|
@@ -143,6 +146,29 @@ function createRegistry() {
|
|
|
143
146
|
|
|
144
147
|
return parent && parent.resolveSelect(storeName);
|
|
145
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Given the name of a registered store, returns an object containing the store's
|
|
151
|
+
* selectors pre-bound to state so that you only need to supply additional arguments,
|
|
152
|
+
* and modified so that they throw promises in case the selector is not resolved yet.
|
|
153
|
+
*
|
|
154
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
155
|
+
* or the store descriptor.
|
|
156
|
+
*
|
|
157
|
+
* @return {Object} Object containing the store's suspense-wrapped selectors.
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
function suspendSelect(storeNameOrDescriptor) {
|
|
162
|
+
const storeName = (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor;
|
|
163
|
+
listeningStores.add(storeName);
|
|
164
|
+
const store = stores[storeName];
|
|
165
|
+
|
|
166
|
+
if (store) {
|
|
167
|
+
return store.getSuspendSelectors();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return parent && parent.suspendSelect(storeName);
|
|
171
|
+
}
|
|
146
172
|
/**
|
|
147
173
|
* Returns the available actions for a part of the state.
|
|
148
174
|
*
|
|
@@ -302,6 +328,7 @@ function createRegistry() {
|
|
|
302
328
|
subscribe,
|
|
303
329
|
select,
|
|
304
330
|
resolveSelect,
|
|
331
|
+
suspendSelect,
|
|
305
332
|
dispatch,
|
|
306
333
|
use,
|
|
307
334
|
register,
|
package/build/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["createRegistry","storeConfigs","parent","stores","emitter","listeningStores","Set","globalListener","emit","subscribe","listener","select","storeNameOrDescriptor","storeName","name","add","store","getSelectors","__unstableMarkListeningStores","callback","ref","clear","result","call","current","Array","from","resolveSelect","getResolveSelectors","dispatch","getActions","withPlugins","attributes","attribute","key","registry","apply","arguments","registerStoreInstance","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","__unstableSubscribeStore","handler","batch","pause","resume","namespaces","use","plugin","coreDataStore","config","Object","entries"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AACA;;AACA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,cAAT,GAA4D;AAAA,MAAnCC,YAAmC,uEAApB,EAAoB;AAAA,MAAhBC,MAAgB,uEAAP,IAAO;AAClE,QAAMC,MAAM,GAAG,EAAf;AACA,QAAMC,OAAO,GAAG,6BAAhB;AACA,QAAMC,eAAe,GAAG,IAAIC,GAAJ,EAAxB;AAEA;AACD;AACA;;AACC,WAASC,cAAT,GAA0B;AACzBH,IAAAA,OAAO,CAACI,IAAR;AACA;AAED;AACD;AACA;AACA;AACA;AACA;AACA;;;AACC,QAAMC,SAAS,GAAKC,QAAF,IAAgB;AACjC,WAAON,OAAO,CAACK,SAAR,CAAmBC,QAAnB,CAAP;AACA,GAFD;AAIA;AACD;AACA;AACA;AACA;AACA;AACA;AACA;;;AACC,WAASC,MAAT,CAAiBC,qBAAjB,EAAyC;AACxC,UAAMC,SAAS,GAAG,sBAAUD,qBAAV,IACfA,qBAAqB,CAACE,IADP,GAEfF,qBAFH;AAGAP,IAAAA,eAAe,CAACU,GAAhB,CAAqBF,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AAQ+C,MAAR,CAAZ,IAAgCC,MAAM,CAACC,OAAP,CAAgB9D,YAAhB,CAAhC,EAAiE;AAChEkC,IAAAA,QAAQ,CAACS,QAAT,CAAmB,yBAAkB9B,IAAlB,EAAwB+C,MAAxB,CAAnB;AACA;;AAED,MAAK3D,MAAL,EAAc;AACbA,IAAAA,MAAM,CAACO,SAAP,CAAkBF,cAAlB;AACA;;AAED,SAAOwB,WAAW,CAAEI,QAAF,CAAlB;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues, isObject, forEach } from 'lodash';\n\n/**\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';\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\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\tconst listeningStores = new Set();\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.\n\t *\n\t * @param {Function} listener Listener function.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener ) => {\n\t\treturn emitter.subscribe( listener );\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 = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: 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 && parent.select( storeName );\n\t}\n\n\tfunction __unstableMarkListeningStores( callback, ref ) {\n\t\tlisteningStores.clear();\n\t\tconst result = callback.call( this );\n\t\tref.current = Array.from( listeningStores );\n\t\treturn result;\n\t}\n\n\t/**\n\t * Given the name of a registered store, returns an object containing the store's\n\t * selectors pre-bound to state so that you only need to supply additional arguments,\n\t * and modified so that they return promises that resolve to their eventual values,\n\t * after any resolvers have ran.\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 {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: 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 * 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 = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: 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 mapValues( attributes, ( attribute, key ) => {\n\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\treturn attribute;\n\t\t\t}\n\t\t\treturn function () {\n\t\t\t\treturn registry[ key ].apply( null, arguments );\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 {Object} store Store instance object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, store ) {\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\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, store.instantiate( registry ) );\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 = createReduxStore( storeName, options ).instantiate(\n\t\t\tregistry\n\t\t);\n\t\tregisterStoreInstance( storeName, store );\n\t\treturn store.store;\n\t}\n\n\t/**\n\t * Subscribe handler to a store.\n\t *\n\t * @param {string[]} storeName The store name.\n\t * @param {Function} handler The function subscribed to the store.\n\t * @return {Function} A function to unsubscribe the handler.\n\t */\n\tfunction __unstableSubscribeStore( storeName, handler ) {\n\t\tif ( storeName in stores ) {\n\t\t\treturn stores[ storeName ].subscribe( handler );\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 regular `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 subscribe( handler );\n\t\t}\n\n\t\treturn parent.__unstableSubscribeStore( storeName, handler );\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tforEach( stores, ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tforEach( stores, ( 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\tdispatch,\n\t\tuse,\n\t\tregister,\n\t\tregisterGenericStore,\n\t\tregisterStore,\n\t\t__unstableMarkListeningStores,\n\t\t__unstableSubscribeStore,\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\treturn withPlugins( registry );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/registry.js"],"names":["createRegistry","storeConfigs","parent","stores","emitter","listeningStores","Set","globalListener","emit","subscribe","listener","select","storeNameOrDescriptor","storeName","name","add","store","getSelectors","__unstableMarkListeningStores","callback","ref","clear","call","current","Array","from","resolveSelect","getResolveSelectors","suspendSelect","getSuspendSelectors","dispatch","getActions","withPlugins","attributes","attribute","key","registry","apply","arguments","registerStoreInstance","TypeError","currentSubscribe","unsubscribeFromEmitter","unsubscribeFromStore","isPaused","register","instantiate","registerGenericStore","since","alternative","registerStore","options","reducer","__unstableSubscribeStore","handler","batch","pause","resume","namespaces","use","plugin","coreDataStore","config","Object","entries"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AACA;;AACA;;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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CC,MAAM,CAACC,OAAP,CAAgB/D,YAAhB,CAAhC,EAAiE;AAChEmC,IAAAA,QAAQ,CAACS,QAAT,CAAmB,yBAAkB/B,IAAlB,EAAwBgD,MAAxB,CAAnB;AACA;;AAED,MAAK5D,MAAL,EAAc;AACbA,IAAAA,MAAM,CAACO,SAAP,CAAkBF,cAAlB;AACA;;AAED,SAAOyB,WAAW,CAAEI,QAAF,CAAlB;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { mapValues, isObject, forEach } from 'lodash';\n\n/**\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';\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\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\tconst listeningStores = new Set();\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.\n\t *\n\t * @param {Function} listener Listener function.\n\t *\n\t * @return {Function} Unsubscribe function.\n\t */\n\tconst subscribe = ( listener ) => {\n\t\treturn emitter.subscribe( listener );\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 = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: 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.clear();\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}\n\t}\n\n\t/**\n\t * Given the name of a registered store, returns an object containing the store's\n\t * selectors pre-bound to state so that you only need to supply additional arguments,\n\t * and modified so that they return promises that resolve to their eventual values,\n\t * after any resolvers have ran.\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 {Object} Each key of the object matches the name of a selector.\n\t */\n\tfunction resolveSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: 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 the name of a registered store, returns an object containing the store's\n\t * selectors pre-bound to state so that you only need to supply additional arguments,\n\t * and modified so that they throw promises in case the selector is not resolved yet.\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 {Object} Object containing the store's suspense-wrapped selectors.\n\t */\n\tfunction suspendSelect( storeNameOrDescriptor ) {\n\t\tconst storeName = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: 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 = isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: 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 mapValues( attributes, ( attribute, key ) => {\n\t\t\tif ( typeof attribute !== 'function' ) {\n\t\t\t\treturn attribute;\n\t\t\t}\n\t\t\treturn function () {\n\t\t\t\treturn registry[ key ].apply( null, arguments );\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 {Object} store Store instance object (getSelectors, getActions, subscribe).\n\t */\n\tfunction registerStoreInstance( name, store ) {\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\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, store.instantiate( registry ) );\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 = createReduxStore( storeName, options ).instantiate(\n\t\t\tregistry\n\t\t);\n\t\tregisterStoreInstance( storeName, store );\n\t\treturn store.store;\n\t}\n\n\t/**\n\t * Subscribe handler to a store.\n\t *\n\t * @param {string[]} storeName The store name.\n\t * @param {Function} handler The function subscribed to the store.\n\t * @return {Function} A function to unsubscribe the handler.\n\t */\n\tfunction __unstableSubscribeStore( storeName, handler ) {\n\t\tif ( storeName in stores ) {\n\t\t\treturn stores[ storeName ].subscribe( handler );\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 regular `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 subscribe( handler );\n\t\t}\n\n\t\treturn parent.__unstableSubscribeStore( storeName, handler );\n\t}\n\n\tfunction batch( callback ) {\n\t\temitter.pause();\n\t\tforEach( stores, ( store ) => store.emitter.pause() );\n\t\tcallback();\n\t\temitter.resume();\n\t\tforEach( stores, ( 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\t__unstableSubscribeStore,\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\treturn withPlugins( registry );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"names":["createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","coreDataStore","getCachedResolvers","Object","entries","forEach","selectorName","resolversByArgs","resolver","stores","shouldInvalidate","value","args","status","dispatch","invalidateResolution"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,8BAA8B,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/resolvers-cache-middleware.js"],"names":["createResolversCacheMiddleware","registry","reducerKey","next","action","resolvers","select","coreDataStore","getCachedResolvers","Object","entries","forEach","selectorName","resolversByArgs","resolver","stores","shouldInvalidate","value","args","status","dispatch","invalidateResolution"],"mappings":";;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,8BAA8B,GACnC,CAAEC,QAAF,EAAYC,UAAZ,KAA4B,MAAQC,IAAF,IAAcC,MAAF,IAAc;AAC3D,QAAMC,SAAS,GAAGJ,QAAQ,CACxBK,MADgB,CACRC,cADQ,EAEhBC,kBAFgB,CAEIN,UAFJ,CAAlB;AAGAO,EAAAA,MAAM,CAACC,OAAP,CAAgBL,SAAhB,EAA4BM,OAA5B,CACC,QAAyC;AAAA,QAAvC,CAAEC,YAAF,EAAgBC,eAAhB,CAAuC;AACxC,UAAMC,QAAQ,GAAG,iBAAKb,QAAQ,CAACc,MAAd,EAAsB,CACtCb,UADsC,EAEtC,WAFsC,EAGtCU,YAHsC,CAAtB,CAAjB;;AAKA,QAAK,CAAEE,QAAF,IAAc,CAAEA,QAAQ,CAACE,gBAA9B,EAAiD;AAChD;AACA;;AACDH,IAAAA,eAAe,CAACF,OAAhB,CAAyB,CAAEM,KAAF,EAASC,IAAT,KAAmB;AAC3C;AACA;AACA;AACA,UACG,CAAAD,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEE,MAAP,MAAkB,UAAlB,IACD,CAAAF,KAAK,SAAL,IAAAA,KAAK,WAAL,YAAAA,KAAK,CAAEE,MAAP,MAAkB,OADnB,IAEA,CAAEL,QAAQ,CAACE,gBAAT,CAA2BZ,MAA3B,EAAmC,GAAGc,IAAtC,CAHH,EAIE;AACD;AACA,OAV0C,CAY3C;;;AACAjB,MAAAA,QAAQ,CACNmB,QADF,CACYb,cADZ,EAEEc,oBAFF,CAEwBnB,UAFxB,EAEoCU,YAFpC,EAEkDM,IAFlD;AAGA,KAhBD;AAiBA,GA3BF;AA6BA,SAAOf,IAAI,CAAEC,MAAF,CAAX;AACA,CAnCF;;eAqCeJ,8B","sourcesContent":["/**\n * External dependencies\n */\nimport { get } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport coreDataStore from './store';\n\n/** @typedef {import('./registry').WPDataRegistry} WPDataRegistry */\n\n/**\n * Creates a middleware handling resolvers cache invalidation.\n *\n * @param {WPDataRegistry} registry The registry reference for which to create\n * the middleware.\n * @param {string} reducerKey The namespace for which to create the\n * middleware.\n *\n * @return {Function} Middleware function.\n */\nconst createResolversCacheMiddleware =\n\t( registry, reducerKey ) => () => ( next ) => ( action ) => {\n\t\tconst resolvers = registry\n\t\t\t.select( coreDataStore )\n\t\t\t.getCachedResolvers( reducerKey );\n\t\tObject.entries( resolvers ).forEach(\n\t\t\t( [ selectorName, resolversByArgs ] ) => {\n\t\t\t\tconst resolver = get( registry.stores, [\n\t\t\t\t\treducerKey,\n\t\t\t\t\t'resolvers',\n\t\t\t\t\tselectorName,\n\t\t\t\t] );\n\t\t\t\tif ( ! resolver || ! resolver.shouldInvalidate ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tresolversByArgs.forEach( ( value, args ) => {\n\t\t\t\t\t// resolversByArgs is the map Map([ args ] => boolean) storing the cache resolution status for a given selector.\n\t\t\t\t\t// If the value is \"finished\" or \"error\" it means this resolver has finished its resolution which means we need\n\t\t\t\t\t// to invalidate it, if it's true it means it's inflight and the invalidation is not necessary.\n\t\t\t\t\tif (\n\t\t\t\t\t\t( value?.status !== 'finished' &&\n\t\t\t\t\t\t\tvalue?.status !== 'error' ) ||\n\t\t\t\t\t\t! resolver.shouldInvalidate( action, ...args )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Trigger cache invalidation\n\t\t\t\t\tregistry\n\t\t\t\t\t\t.dispatch( coreDataStore )\n\t\t\t\t\t\t.invalidateResolution( reducerKey, selectorName, args );\n\t\t\t\t} );\n\t\t\t}\n\t\t);\n\t\treturn next( action );\n\t};\n\nexport default createResolversCacheMiddleware;\n"]}
|
package/build/store/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/store/index.js"],"names":["coreDataStore","name","instantiate","registry","getCoreDataSelector","selectorName","key","args","select","getCoreDataAction","actionName","dispatch","getSelectors","Object","fromEntries","map","getActions","subscribe"],"mappings":";;;;;;AAAA,MAAMA,aAAa,GAAG;AACrBC,EAAAA,IAAI,EAAE,WADe;;AAErBC,EAAAA,WAAW,CAAEC,QAAF,EAAa;AACvB,UAAMC,mBAAmB,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/store/index.js"],"names":["coreDataStore","name","instantiate","registry","getCoreDataSelector","selectorName","key","args","select","getCoreDataAction","actionName","dispatch","getSelectors","Object","fromEntries","map","getActions","subscribe"],"mappings":";;;;;;AAAA,MAAMA,aAAa,GAAG;AACrBC,EAAAA,IAAI,EAAE,WADe;;AAErBC,EAAAA,WAAW,CAAEC,QAAF,EAAa;AACvB,UAAMC,mBAAmB,GACtBC,YAAF,IACA,UAAEC,GAAF,EAAoB;AAAA,wCAAVC,IAAU;AAAVA,QAAAA,IAAU;AAAA;;AACnB,aAAOJ,QAAQ,CAACK,MAAT,CAAiBF,GAAjB,EAAwBD,YAAxB,EAAwC,GAAGE,IAA3C,CAAP;AACA,KAJF;;AAMA,UAAME,iBAAiB,GACpBC,UAAF,IACA,UAAEJ,GAAF,EAAoB;AAAA,yCAAVC,IAAU;AAAVA,QAAAA,IAAU;AAAA;;AACnB,aAAOJ,QAAQ,CAACQ,QAAT,CAAmBL,GAAnB,EAA0BI,UAA1B,EAAwC,GAAGH,IAA3C,CAAP;AACA,KAJF;;AAMA,WAAO;AACNK,MAAAA,YAAY,GAAG;AACd,eAAOC,MAAM,CAACC,WAAP,CACN,CACC,gBADD,EAEC,sBAFD,EAGC,uBAHD,EAIC,aAJD,EAKC,oBALD,EAMEC,GANF,CAMSV,YAAF,IAAoB,CAC1BA,YAD0B,EAE1BD,mBAAmB,CAAEC,YAAF,CAFO,CAN3B,CADM,CAAP;AAYA,OAdK;;AAgBNW,MAAAA,UAAU,GAAG;AACZ,eAAOH,MAAM,CAACC,WAAP,CACN,CACC,iBADD,EAEC,kBAFD,EAGC,sBAHD,EAIC,8BAJD,EAKC,sCALD,EAMEC,GANF,CAMSL,UAAF,IAAkB,CACxBA,UADwB,EAExBD,iBAAiB,CAAEC,UAAF,CAFO,CANzB,CADM,CAAP;AAYA,OA7BK;;AA+BNO,MAAAA,SAAS,GAAG;AACX;AACA;AACA;AACA;AACA,eAAO,MAAM,MAAM,CAAE,CAArB;AACA;;AArCK,KAAP;AAuCA;;AAtDoB,CAAtB;eAyDejB,a","sourcesContent":["const coreDataStore = {\n\tname: 'core/data',\n\tinstantiate( registry ) {\n\t\tconst getCoreDataSelector =\n\t\t\t( selectorName ) =>\n\t\t\t( key, ...args ) => {\n\t\t\t\treturn registry.select( key )[ selectorName ]( ...args );\n\t\t\t};\n\n\t\tconst getCoreDataAction =\n\t\t\t( actionName ) =>\n\t\t\t( key, ...args ) => {\n\t\t\t\treturn registry.dispatch( key )[ actionName ]( ...args );\n\t\t\t};\n\n\t\treturn {\n\t\t\tgetSelectors() {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'getIsResolving',\n\t\t\t\t\t\t'hasStartedResolution',\n\t\t\t\t\t\t'hasFinishedResolution',\n\t\t\t\t\t\t'isResolving',\n\t\t\t\t\t\t'getCachedResolvers',\n\t\t\t\t\t].map( ( selectorName ) => [\n\t\t\t\t\t\tselectorName,\n\t\t\t\t\t\tgetCoreDataSelector( selectorName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tgetActions() {\n\t\t\t\treturn Object.fromEntries(\n\t\t\t\t\t[\n\t\t\t\t\t\t'startResolution',\n\t\t\t\t\t\t'finishResolution',\n\t\t\t\t\t\t'invalidateResolution',\n\t\t\t\t\t\t'invalidateResolutionForStore',\n\t\t\t\t\t\t'invalidateResolutionForStoreSelector',\n\t\t\t\t\t].map( ( actionName ) => [\n\t\t\t\t\t\tactionName,\n\t\t\t\t\t\tgetCoreDataAction( actionName ),\n\t\t\t\t\t] )\n\t\t\t\t);\n\t\t\t},\n\n\t\t\tsubscribe() {\n\t\t\t\t// There's no reasons to trigger any listener when we subscribe to this store\n\t\t\t\t// because there's no state stored in this store that need to retrigger selectors\n\t\t\t\t// if a change happens, the corresponding store where the tracking stated live\n\t\t\t\t// would have already triggered a \"subscribe\" call.\n\t\t\t\treturn () => () => {};\n\t\t\t},\n\t\t};\n\t},\n};\n\nexport default coreDataStore;\n"]}
|
|
@@ -218,4 +218,115 @@ export default function useSelect(mapSelect, deps) {
|
|
|
218
218
|
}, [registry, wrapSelect, hasMappingFunction, depsChangedFlag]);
|
|
219
219
|
return hasMappingFunction ? mapOutput : registry.select(mapSelect);
|
|
220
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* A variant of the `useSelect` hook that has the same API, but will throw a
|
|
223
|
+
* suspense Promise if any of the called selectors is in an unresolved state.
|
|
224
|
+
*
|
|
225
|
+
* @param {Function} mapSelect Function called on every state change. The
|
|
226
|
+
* returned value is exposed to the component
|
|
227
|
+
* using this hook. The function receives the
|
|
228
|
+
* `registry.suspendSelect` method as the first
|
|
229
|
+
* argument and the `registry` as the second one.
|
|
230
|
+
* @param {Array} deps A dependency array used to memoize the `mapSelect`
|
|
231
|
+
* so that the same `mapSelect` is invoked on every
|
|
232
|
+
* state change unless the dependencies change.
|
|
233
|
+
*
|
|
234
|
+
* @return {Object} Data object returned by the `mapSelect` function.
|
|
235
|
+
*/
|
|
236
|
+
|
|
237
|
+
export function useSuspenseSelect(mapSelect, deps) {
|
|
238
|
+
const _mapSelect = useCallback(mapSelect, deps);
|
|
239
|
+
|
|
240
|
+
const registry = useRegistry();
|
|
241
|
+
const isAsync = useAsyncMode();
|
|
242
|
+
const latestRegistry = useRef(registry);
|
|
243
|
+
const latestMapSelect = useRef();
|
|
244
|
+
const latestIsAsync = useRef(isAsync);
|
|
245
|
+
const latestMapOutput = useRef();
|
|
246
|
+
const latestMapOutputError = useRef(); // Keep track of the stores being selected in the `mapSelect` function,
|
|
247
|
+
// and only subscribe to those stores later.
|
|
248
|
+
|
|
249
|
+
const listeningStores = useRef([]);
|
|
250
|
+
const wrapSelect = useCallback(callback => registry.__unstableMarkListeningStores(() => callback(registry.suspendSelect, registry), listeningStores), [registry]); // Generate a "flag" for used in the effect dependency array.
|
|
251
|
+
// It's different than just using `mapSelect` since deps could be undefined,
|
|
252
|
+
// in that case, we would still want to memoize it.
|
|
253
|
+
|
|
254
|
+
const depsChangedFlag = useMemo(() => ({}), deps || []);
|
|
255
|
+
let mapOutput = latestMapOutput.current;
|
|
256
|
+
let mapOutputError = latestMapOutputError.current;
|
|
257
|
+
const hasReplacedRegistry = latestRegistry.current !== registry;
|
|
258
|
+
const hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;
|
|
259
|
+
const hasLeftAsyncMode = latestIsAsync.current && !isAsync;
|
|
260
|
+
|
|
261
|
+
if (hasReplacedRegistry || hasReplacedMapSelect || hasLeftAsyncMode) {
|
|
262
|
+
try {
|
|
263
|
+
mapOutput = wrapSelect(_mapSelect);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
mapOutputError = error;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
useIsomorphicLayoutEffect(() => {
|
|
270
|
+
latestRegistry.current = registry;
|
|
271
|
+
latestMapSelect.current = _mapSelect;
|
|
272
|
+
latestIsAsync.current = isAsync;
|
|
273
|
+
latestMapOutput.current = mapOutput;
|
|
274
|
+
latestMapOutputError.current = mapOutputError;
|
|
275
|
+
}); // React can sometimes clear the `useMemo` cache.
|
|
276
|
+
// We use the cache-stable `useMemoOne` to avoid
|
|
277
|
+
// losing queues.
|
|
278
|
+
|
|
279
|
+
const queueContext = useMemoOne(() => ({
|
|
280
|
+
queue: true
|
|
281
|
+
}), [registry]);
|
|
282
|
+
const [, forceRender] = useReducer(s => s + 1, 0);
|
|
283
|
+
const isMounted = useRef(false);
|
|
284
|
+
useIsomorphicLayoutEffect(() => {
|
|
285
|
+
const onStoreChange = () => {
|
|
286
|
+
try {
|
|
287
|
+
const newMapOutput = wrapSelect(latestMapSelect.current);
|
|
288
|
+
|
|
289
|
+
if (isShallowEqual(latestMapOutput.current, newMapOutput)) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
latestMapOutput.current = newMapOutput;
|
|
294
|
+
} catch (error) {
|
|
295
|
+
latestMapOutputError.current = error;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
forceRender();
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
const onChange = () => {
|
|
302
|
+
if (!isMounted.current) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (latestIsAsync.current) {
|
|
307
|
+
renderQueue.add(queueContext, onStoreChange);
|
|
308
|
+
} else {
|
|
309
|
+
onStoreChange();
|
|
310
|
+
}
|
|
311
|
+
}; // catch any possible state changes during mount before the subscription
|
|
312
|
+
// could be set.
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
onStoreChange();
|
|
316
|
+
const unsubscribers = listeningStores.current.map(storeName => registry.__unstableSubscribeStore(storeName, onChange));
|
|
317
|
+
isMounted.current = true;
|
|
318
|
+
return () => {
|
|
319
|
+
// The return value of the subscribe function could be undefined if the store is a custom generic store.
|
|
320
|
+
unsubscribers.forEach(unsubscribe => unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
|
|
321
|
+
renderQueue.cancel(queueContext);
|
|
322
|
+
isMounted.current = false;
|
|
323
|
+
};
|
|
324
|
+
}, [registry, wrapSelect, depsChangedFlag]);
|
|
325
|
+
|
|
326
|
+
if (mapOutputError) {
|
|
327
|
+
throw mapOutputError;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
return mapOutput;
|
|
331
|
+
}
|
|
221
332
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["useMemoOne","createQueue","useRef","useCallback","useMemo","useReducer","isShallowEqual","useIsomorphicLayoutEffect","useRegistry","useAsyncMode","noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","latestRegistry","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","listeningStores","wrapSelect","callback","__unstableMarkListeningStores","select","depsChangedFlag","mapOutput","current","hasReplacedRegistry","hasReplacedMapSelect","hasLeftAsyncMode","lastMapSelectFailed","error","errorMessage","message","stack","console","undefined","queueContext","queue","forceRender","s","isMounted","onStoreChange","newMapOutput","onChange","add","unsubscribers","map","storeName","__unstableSubscribeStore","forEach","unsubscribe","cancel"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,cAA3B;AAEA;AACA;AACA;;AACA,SAASC,WAAT,QAA4B,2BAA5B;AACA,SAASC,MAAT,EAAiBC,WAAjB,EAA8BC,OAA9B,EAAuCC,UAAvC,QAAyD,oBAAzD;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AACA,SAASC,yBAAT,QAA0C,oBAA1C;AAEA;AACA;AACA;;AACA,OAAOC,WAAP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,CAACwC,GAAZ,CAAiBR,YAAjB,EAA+BK,aAA/B;AACA,OAFD,MAEO;AACNA,QAAAA,aAAa;AACb;AACD,KAVD,CAnBgC,CA+BhC;AACA;;;AACAA,IAAAA,aAAa;AAEb,UAAMI,aAAa,GAAG3B,eAAe,CAACO,OAAhB,CAAwBqB,GAAxB,CAA+BC,SAAF,IAClDpC,QAAQ,CAACqC,wBAAT,CAAmCD,SAAnC,EAA8CJ,QAA9C,CADqB,CAAtB;AAIAH,IAAAA,SAAS,CAACf,OAAV,GAAoB,IAApB;AAEA,WAAO,MAAM;AACZ;AACAoB,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA9C,MAAAA,WAAW,CAAC+C,MAAZ,CAAoBf,YAApB;AACAI,MAAAA,SAAS,CAACf,OAAV,GAAoB,KAApB;AACA,KALD,CAzCgC,CA+ChC;AACA;AACA;AACA,GAlDwB,EAkDtB,CAAEd,QAAF,EAAYQ,UAAZ,EAAwBX,kBAAxB,EAA4Ce,eAA5C,CAlDsB,CAAzB;AAoDA,SAAOf,kBAAkB,GAAGgB,SAAH,GAAeb,QAAQ,CAACW,MAAT,CAAiBhB,SAAjB,CAAxC;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return {Function} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif (\n\t\t\thasReplacedRegistry ||\n\t\t\thasReplacedMapSelect ||\n\t\t\thasLeftAsyncMode ||\n\t\t\tlastMapSelectFailed\n\t\t) {\n\t\t\ttry {\n\t\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, wrapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["useMemoOne","createQueue","useRef","useCallback","useMemo","useReducer","isShallowEqual","useIsomorphicLayoutEffect","useRegistry","useAsyncMode","noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","latestRegistry","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","listeningStores","wrapSelect","callback","__unstableMarkListeningStores","select","depsChangedFlag","mapOutput","current","hasReplacedRegistry","hasReplacedMapSelect","hasLeftAsyncMode","lastMapSelectFailed","error","errorMessage","message","stack","console","undefined","queueContext","queue","forceRender","s","isMounted","onStoreChange","newMapOutput","onChange","add","unsubscribers","map","storeName","__unstableSubscribeStore","forEach","unsubscribe","cancel","useSuspenseSelect","suspendSelect","mapOutputError"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,cAA3B;AAEA;AACA;AACA;;AACA,SAASC,WAAT,QAA4B,2BAA5B;AACA,SAASC,MAAT,EAAiBC,WAAjB,EAA8BC,OAA9B,EAAuCC,UAAvC,QAAyD,oBAAzD;AACA,OAAOC,cAAP,MAA2B,6BAA3B;AAC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AAT,CAAmCD,SAAnC,EAA8CJ,QAA9C,CADqB,CAAtB;AAIAH,IAAAA,SAAS,CAACf,OAAV,GAAoB,IAApB;AAEA,WAAO,MAAM;AACZ;AACAoB,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA9C,MAAAA,WAAW,CAAC+C,MAAZ,CAAoBf,YAApB;AACAI,MAAAA,SAAS,CAACf,OAAV,GAAoB,KAApB;AACA,KALD;AAMA,GA5CwB,EA4CtB,CAAEd,QAAF,EAAYQ,UAAZ,EAAwBI,eAAxB,CA5CsB,CAAzB;;AA8CA,MAAK+B,cAAL,EAAsB;AACrB,UAAMA,cAAN;AACA;;AAED,SAAO9B,SAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { createQueue } from '@wordpress/priority-queue';\nimport { useRef, useCallback, useMemo, useReducer } from '@wordpress/element';\nimport isShallowEqual from '@wordpress/is-shallow-equal';\nimport { useIsomorphicLayoutEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport useRegistry from '../registry-provider/use-registry';\nimport useAsyncMode from '../async-mode-provider/use-async-mode';\n\nconst noop = () => {};\nconst renderQueue = createQueue();\n\n/** @typedef {import('../../types').StoreDescriptor} StoreDescriptor */\n\n/**\n * Custom react hook for retrieving props from registered selectors.\n *\n * In general, this custom React hook follows the\n * [rules of hooks](https://reactjs.org/docs/hooks-rules.html).\n *\n * @param {Function|StoreDescriptor|string} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * implementing this hook. The function receives\n * the `registry.select` method on the first\n * argument and the `registry` on the second\n * argument.\n * When a store key is passed, all selectors for\n * the store will be returned. This is only meant\n * for usage of these selectors in event\n * callbacks, not for data needed to create the\n * element tree.\n * @param {Array} deps If provided, this memoizes the mapSelect so the\n * same `mapSelect` is invoked on every state\n * change unless the dependencies change.\n *\n * @example\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function HammerPriceDisplay( { currency } ) {\n * const price = useSelect( ( select ) => {\n * return select( 'my-shop' ).getPrice( 'hammer', currency )\n * }, [ currency ] );\n * return new Intl.NumberFormat( 'en-US', {\n * style: 'currency',\n * currency,\n * } ).format( price );\n * }\n *\n * // Rendered in the application:\n * // <HammerPriceDisplay currency=\"USD\" />\n * ```\n *\n * In the above example, when `HammerPriceDisplay` is rendered into an\n * application, the price will be retrieved from the store state using the\n * `mapSelect` callback on `useSelect`. If the currency prop changes then\n * any price in the state for that currency is retrieved. If the currency prop\n * doesn't change and other props are passed in that do change, the price will\n * not change because the dependency is just the currency.\n *\n * When data is only used in an event callback, the data should not be retrieved\n * on render, so it may be useful to get the selectors function instead.\n *\n * **Don't use `useSelect` this way when calling the selectors in the render\n * function because your component won't re-render on a data change.**\n *\n * ```js\n * import { useSelect } from '@wordpress/data';\n *\n * function Paste( { children } ) {\n * const { getSettings } = useSelect( 'my-shop' );\n * function onPaste() {\n * // Do something with the settings.\n * const settings = getSettings();\n * }\n * return <div onPaste={ onPaste }>{ children }</div>;\n * }\n * ```\n *\n * @return {Function} A custom react hook.\n */\nexport default function useSelect( mapSelect, deps ) {\n\tconst hasMappingFunction = 'function' === typeof mapSelect;\n\n\t// If we're recalling a store by its name or by\n\t// its descriptor then we won't be caching the\n\t// calls to `mapSelect` because we won't be calling it.\n\tif ( ! hasMappingFunction ) {\n\t\tdeps = [];\n\t}\n\n\t// Because of the \"rule of hooks\" we have to call `useCallback`\n\t// on every invocation whether or not we have a real function\n\t// for `mapSelect`. we'll create this intermediate variable to\n\t// fulfill that need and then reference it with our \"real\"\n\t// `_mapSelect` if we can.\n\tconst callbackMapper = useCallback(\n\t\thasMappingFunction ? mapSelect : noop,\n\t\tdeps\n\t);\n\tconst _mapSelect = hasMappingFunction ? callbackMapper : null;\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the _mapSelect function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.select, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput;\n\n\tif ( _mapSelect ) {\n\t\tmapOutput = latestMapOutput.current;\n\t\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\t\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif (\n\t\t\thasReplacedRegistry ||\n\t\t\thasReplacedMapSelect ||\n\t\t\thasLeftAsyncMode ||\n\t\t\tlastMapSelectFailed\n\t\t) {\n\t\t\ttry {\n\t\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t\t} catch ( error ) {\n\t\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t\t}\n\n\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\tconsole.error( errorMessage );\n\t\t\t}\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// Catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t\t// If you're tempted to eliminate the spread dependencies below don't do it!\n\t\t// We're passing these in from the calling function and want to make sure we're\n\t\t// examining every individual value inside the `deps` array.\n\t}, [ registry, wrapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n\n/**\n * A variant of the `useSelect` hook that has the same API, but will throw a\n * suspense Promise if any of the called selectors is in an unresolved state.\n *\n * @param {Function} mapSelect Function called on every state change. The\n * returned value is exposed to the component\n * using this hook. The function receives the\n * `registry.suspendSelect` method as the first\n * argument and the `registry` as the second one.\n * @param {Array} deps A dependency array used to memoize the `mapSelect`\n * so that the same `mapSelect` is invoked on every\n * state change unless the dependencies change.\n *\n * @return {Object} Data object returned by the `mapSelect` function.\n */\nexport function useSuspenseSelect( mapSelect, deps ) {\n\tconst _mapSelect = useCallback( mapSelect, deps );\n\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\n\n\tconst latestRegistry = useRef( registry );\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\n\t// Keep track of the stores being selected in the `mapSelect` function,\n\t// and only subscribe to those stores later.\n\tconst listeningStores = useRef( [] );\n\tconst wrapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__unstableMarkListeningStores(\n\t\t\t\t() => callback( registry.suspendSelect, registry ),\n\t\t\t\tlisteningStores\n\t\t\t),\n\t\t[ registry ]\n\t);\n\n\t// Generate a \"flag\" for used in the effect dependency array.\n\t// It's different than just using `mapSelect` since deps could be undefined,\n\t// in that case, we would still want to memoize it.\n\tconst depsChangedFlag = useMemo( () => ( {} ), deps || [] );\n\n\tlet mapOutput = latestMapOutput.current;\n\tlet mapOutputError = latestMapOutputError.current;\n\n\tconst hasReplacedRegistry = latestRegistry.current !== registry;\n\tconst hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\tconst hasLeftAsyncMode = latestIsAsync.current && ! isAsync;\n\n\tif ( hasReplacedRegistry || hasReplacedMapSelect || hasLeftAsyncMode ) {\n\t\ttry {\n\t\t\tmapOutput = wrapSelect( _mapSelect );\n\t\t} catch ( error ) {\n\t\t\tmapOutputError = error;\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tlatestRegistry.current = registry;\n\t\tlatestMapSelect.current = _mapSelect;\n\t\tlatestIsAsync.current = isAsync;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = mapOutputError;\n\t} );\n\n\t// React can sometimes clear the `useMemo` cache.\n\t// We use the cache-stable `useMemoOne` to avoid\n\t// losing queues.\n\tconst queueContext = useMemoOne( () => ( { queue: true } ), [ registry ] );\n\tconst [ , forceRender ] = useReducer( ( s ) => s + 1, 0 );\n\tconst isMounted = useRef( false );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tconst onStoreChange = () => {\n\t\t\ttry {\n\t\t\t\tconst newMapOutput = wrapSelect( latestMapSelect.current );\n\n\t\t\t\tif ( isShallowEqual( latestMapOutput.current, newMapOutput ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t} catch ( error ) {\n\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t}\n\n\t\t\tforceRender();\n\t\t};\n\n\t\tconst onChange = () => {\n\t\t\tif ( ! isMounted.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( latestIsAsync.current ) {\n\t\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t\t} else {\n\t\t\t\tonStoreChange();\n\t\t\t}\n\t\t};\n\n\t\t// catch any possible state changes during mount before the subscription\n\t\t// could be set.\n\t\tonStoreChange();\n\n\t\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__unstableSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\tisMounted.current = true;\n\n\t\treturn () => {\n\t\t\t// The return value of the subscribe function could be undefined if the store is a custom generic store.\n\t\t\tunsubscribers.forEach( ( unsubscribe ) => unsubscribe?.() );\n\t\t\trenderQueue.cancel( queueContext );\n\t\t\tisMounted.current = false;\n\t\t};\n\t}, [ registry, wrapSelect, depsChangedFlag ] );\n\n\tif ( mapOutputError ) {\n\t\tthrow mapOutputError;\n\t}\n\n\treturn mapOutput;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/with-registry/index.js"],"names":["createHigherOrderComponent","RegistryConsumer","withRegistry","OriginalComponent","props","registry"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,0BAAT,QAA2C,oBAA3C;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAGF,0BAA0B,CAC5CG,iBAAF,IAA2BC,KAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/components/with-registry/index.js"],"names":["createHigherOrderComponent","RegistryConsumer","withRegistry","OriginalComponent","props","registry"],"mappings":";;;AAAA;AACA;AACA;AACA,SAASA,0BAAT,QAA2C,oBAA3C;AAEA;AACA;AACA;;AACA,SAASC,gBAAT,QAAiC,sBAAjC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,YAAY,GAAGF,0BAA0B,CAC5CG,iBAAF,IAA2BC,KAAF,IAEvB,cAAC,gBAAD,QACKC,QAAF,IACD,cAAC,iBAAD,eAAwBD,KAAxB;AAAgC,EAAA,QAAQ,EAAGC;AAA3C,GAFF,CAH4C,EAS9C,cAT8C,CAA/C;AAYA,eAAeH,YAAf","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createHigherOrderComponent } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { RegistryConsumer } from '../registry-provider';\n\n/**\n * Higher-order component which renders the original component with the current\n * registry context passed as its `registry` prop.\n *\n * @param {WPComponent} OriginalComponent Original component.\n *\n * @return {WPComponent} Enhanced component.\n */\nconst withRegistry = createHigherOrderComponent(\n\t( OriginalComponent ) => ( props ) =>\n\t\t(\n\t\t\t<RegistryConsumer>\n\t\t\t\t{ ( registry ) => (\n\t\t\t\t\t<OriginalComponent { ...props } registry={ registry } />\n\t\t\t\t) }\n\t\t\t</RegistryConsumer>\n\t\t),\n\t'withRegistry'\n);\n\nexport default withRegistry;\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["isObject","createRegistryControl","SELECT","RESOLVE_SELECT","DISPATCH","select","storeNameOrDescriptor","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,QAAyB,QAAzB;AAEA;AACA;AACA;;AACA,SAASC,qBAAT,QAAsC,WAAtC;AAEA;;AAEA,MAAMC,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,MAAT,CAAiBC,qBAAjB,EAAwCC,YAAxC,EAAgE;AAAA,oCAAPC,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAC/D,SAAO;AACNC,IAAAA,IAAI,EAAEP,MADA;AAENQ,IAAAA,QAAQ,EAAEV,QAAQ,CAAEM,qBAAF,CAAR,GACPA,qBAAqB,CAACK,IADf,GAEPL,qBAJG;AAKNC,IAAAA,YALM;AAMNC,IAAAA;AANM,GAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASI,aAAT,CAAwBN,qBAAxB,EAA+CC,YAA/C,EAAuE;AAAA,qCAAPC,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AACtE,SAAO;AACNC,IAAAA,IAAI,EAAEN,cADA;AAENO,IAAAA,QAAQ,EAAEV,QAAQ,CAAEM,qBAAF,CAAR,GACPA,qBAAqB,CAACK,IADf,GAEPL,qBAJG;AAKNC,IAAAA,YALM;AAMNC,IAAAA;AANM,GAAP;AAQA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASK,QAAT,CAAmBP,qBAAnB,EAA0CQ,UAA1C,EAAgE;AAAA,qCAAPN,IAAO;AAAPA,IAAAA,IAAO;AAAA;;AAC/D,SAAO;AACNC,IAAAA,IAAI,EAAEL,QADA;AAENM,IAAAA,QAAQ,EAAEV,QAAQ,CAAEM,qBAAF,CAAR,GACPA,qBAAqB,CAACK,IADf,GAEPL,qBAJG;AAKNQ,IAAAA,UALM;AAMNN,IAAAA;AANM,GAAP;AAQA;;AAED,OAAO,MAAMO,QAAQ,GAAG;AAAEV,EAAAA,MAAF;AAAUO,EAAAA,aAAV;AAAyBC,EAAAA;AAAzB,CAAjB;AAEP,OAAO,MAAMG,eAAe,GAAG;AAC9B,GAAEd,MAAF,GAAYD,qBAAqB,CAC9BgB,QAAF,
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["isObject","createRegistryControl","SELECT","RESOLVE_SELECT","DISPATCH","select","storeNameOrDescriptor","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAT,QAAyB,QAAzB;AAEA;AACA;AACA;;AACA,SAASC,qBAAT,QAAsC,WAAtC;AAEA;;AAEA,MAAMC,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,QAAQ,GAAG,iBAAjB;A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O,QAAQ,GAAG;AAAEV,EAAAA,MAAF;AAAUO,EAAAA,aAAV;AAAyBC,EAAAA;AAAzB,CAAjB;AAEP,OAAO,MAAMG,eAAe,GAAG;AAC9B,GAAEd,MAAF,GAAYD,qBAAqB,CAC9BgB,QAAF,IACC;AAAA,QAAE;AAAEP,MAAAA,QAAF;AAAYH,MAAAA,YAAZ;AAA0BC,MAAAA;AAA1B,KAAF;AAAA,WACCS,QAAQ,CAACZ,MAAT,CAAiBK,QAAjB,EAA6BH,YAA7B,EAA6C,GAAGC,IAAhD,CADD;AAAA,GAF+B,CADH;AAM9B,GAAEL,cAAF,GAAoBF,qBAAqB,CACtCgB,QAAF,IACC,SAAwC;AAAA,QAAtC;AAAEP,MAAAA,QAAF;AAAYH,MAAAA,YAAZ;AAA0BC,MAAAA;AAA1B,KAAsC;AACvC,UAAMU,MAAM,GAAGD,QAAQ,CAACZ,MAAT,CAAiBK,QAAjB,EAA6BH,YAA7B,EACbY,WADa,GAEZ,eAFY,GAGZ,QAHH;AAIA,WAAOF,QAAQ,CAAEC,MAAF,CAAR,CAAoBR,QAApB,EAAgCH,YAAhC,EACN,GAAGC,IADG,CAAP;AAGA,GAVsC,CANX;AAkB9B,GAAEJ,QAAF,GAAcH,qBAAqB,CAChCgB,QAAF,IACC;AAAA,QAAE;AAAEP,MAAAA,QAAF;AAAYI,MAAAA,UAAZ;AAAwBN,MAAAA;AAAxB,KAAF;AAAA,WACCS,QAAQ,CAACJ,QAAT,CAAmBH,QAAnB,EAA+BI,UAA/B,EAA6C,GAAGN,IAAhD,CADD;AAAA,GAFiC;AAlBL,CAAxB","sourcesContent":["/**\n * External dependencies\n */\nimport { isObject } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { createRegistryControl } from './factory';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nconst SELECT = '@@data/SELECT';\nconst RESOLVE_SELECT = '@@data/RESOLVE_SELECT';\nconst DISPATCH = '@@data/DISPATCH';\n\n/**\n * Dispatches a control action for triggering a synchronous registry select.\n *\n * Note: This control synchronously returns the current selector value, triggering the\n * resolution, but not waiting for it.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector.\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using `select`.\n * export function* myAction() {\n * const isEditorSideBarOpened = yield controls.select( 'core/edit-post', 'isEditorSideBarOpened' );\n * // Do stuff with the result from the `select`.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction select( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering and resolving a registry select.\n *\n * Note: when this control action is handled, it automatically considers\n * selectors that may have a resolver. In such case, it will return a `Promise` that resolves\n * after the selector finishes resolving, with the final result value.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} selectorName The name of the selector\n * @param {Array} args Arguments for the selector.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data';\n *\n * // Action generator using resolveSelect\n * export function* myAction() {\n * \tconst isSidebarOpened = yield controls.resolveSelect( 'core/edit-post', 'isEditorSideBarOpened' );\n * \t// do stuff with the result from the select.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction resolveSelect( storeNameOrDescriptor, selectorName, ...args ) {\n\treturn {\n\t\ttype: RESOLVE_SELECT,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tselectorName,\n\t\targs,\n\t};\n}\n\n/**\n * Dispatches a control action for triggering a registry dispatch.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * @param {string} actionName The name of the action to dispatch\n * @param {Array} args Arguments for the dispatch action.\n *\n * @example\n * ```js\n * import { controls } from '@wordpress/data-controls';\n *\n * // Action generator using dispatch\n * export function* myAction() {\n * yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );\n * // do some other things.\n * }\n * ```\n *\n * @return {Object} The control descriptor.\n */\nfunction dispatch( storeNameOrDescriptor, actionName, ...args ) {\n\treturn {\n\t\ttype: DISPATCH,\n\t\tstoreKey: isObject( storeNameOrDescriptor )\n\t\t\t? storeNameOrDescriptor.name\n\t\t\t: storeNameOrDescriptor,\n\t\tactionName,\n\t\targs,\n\t};\n}\n\nexport const controls = { select, resolveSelect, dispatch };\n\nexport const builtinControls = {\n\t[ SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) =>\n\t\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, selectorName, args } ) => {\n\t\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t\t.hasResolver\n\t\t\t\t\t? 'resolveSelect'\n\t\t\t\t\t: 'select';\n\t\t\t\treturn registry[ method ]( storeKey )[ selectorName ](\n\t\t\t\t\t...args\n\t\t\t\t);\n\t\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) =>\n\t\t\t( { storeKey, actionName, args } ) =>\n\t\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}
|