@wordpress/data 6.1.3 → 6.2.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 +12 -0
- package/LICENSE.md +1 -1
- package/README.md +68 -68
- package/build/components/async-mode-provider/context.js +1 -1
- package/build/components/async-mode-provider/index.js +8 -6
- package/build/components/async-mode-provider/index.js.map +1 -1
- package/build/components/registry-provider/index.js +8 -6
- package/build/components/registry-provider/index.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js +3 -1
- package/build/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build/components/use-dispatch/use-dispatch.js +8 -8
- package/build/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build/components/use-select/index.js +58 -43
- package/build/components/use-select/index.js.map +1 -1
- package/build/controls.js +51 -32
- package/build/controls.js.map +1 -1
- package/build/factory.js +4 -2
- package/build/factory.js.map +1 -1
- package/build/index.js +49 -47
- package/build/index.js.map +1 -1
- package/build/plugins/persistence/index.js +2 -1
- package/build/plugins/persistence/index.js.map +1 -1
- package/build/redux-store/index.js +62 -34
- package/build/redux-store/index.js.map +1 -1
- package/build/redux-store/metadata/actions.js +2 -2
- package/build/redux-store/metadata/reducer.js +8 -2
- package/build/redux-store/metadata/reducer.js.map +1 -1
- package/build/redux-store/metadata/selectors.js +8 -5
- package/build/redux-store/metadata/selectors.js.map +1 -1
- package/build/redux-store/metadata/utils.js +5 -5
- package/build/redux-store/metadata/utils.js.map +1 -1
- package/build/registry.js +81 -66
- package/build/registry.js.map +1 -1
- package/build/resolvers-cache-middleware.js +7 -4
- package/build/resolvers-cache-middleware.js.map +1 -1
- package/build/store/index.js +42 -35
- package/build/store/index.js.map +1 -1
- package/build/types.js +4 -0
- package/build/utils/emitter.js +1 -1
- package/build/utils/emitter.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js +3 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.js.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch.js +8 -8
- package/build-module/components/use-dispatch/use-dispatch.js.map +1 -1
- package/build-module/components/use-select/index.js +60 -44
- package/build-module/components/use-select/index.js.map +1 -1
- package/build-module/controls.js +50 -31
- package/build-module/controls.js.map +1 -1
- package/build-module/factory.js +3 -1
- package/build-module/factory.js.map +1 -1
- package/build-module/index.js +14 -14
- package/build-module/index.js.map +1 -1
- package/build-module/redux-store/index.js +58 -32
- package/build-module/redux-store/index.js.map +1 -1
- package/build-module/redux-store/metadata/reducer.js +8 -2
- package/build-module/redux-store/metadata/reducer.js.map +1 -1
- package/build-module/redux-store/metadata/selectors.js +6 -3
- package/build-module/redux-store/metadata/selectors.js.map +1 -1
- package/build-module/redux-store/metadata/utils.js +5 -5
- package/build-module/redux-store/metadata/utils.js.map +1 -1
- package/build-module/registry.js +81 -66
- package/build-module/registry.js.map +1 -1
- package/build-module/resolvers-cache-middleware.js +5 -4
- package/build-module/resolvers-cache-middleware.js.map +1 -1
- package/build-module/store/index.js +42 -34
- package/build-module/store/index.js.map +1 -1
- package/build-module/types.js +1 -1
- package/build-module/utils/emitter.js +1 -1
- package/build-module/utils/emitter.js.map +1 -1
- package/build-types/types.d.ts +29 -16
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/emitter.d.ts +2 -2
- package/build-types/utils/emitter.d.ts.map +1 -1
- package/package.json +11 -10
- package/src/components/use-dispatch/test/use-dispatch.js +1 -1
- package/src/components/use-dispatch/use-dispatch.js +9 -9
- package/src/components/use-select/index.js +61 -46
- package/src/components/use-select/test/index.js +32 -32
- package/src/controls.js +22 -22
- package/src/index.js +14 -14
- package/src/redux-store/index.js +15 -15
- package/src/registry.js +84 -75
- package/src/resolvers-cache-middleware.js +3 -3
- package/src/store/index.js +49 -48
- package/src/test/registry.js +33 -47
- package/src/types.ts +44 -16
- package/src/utils/emitter.js +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/store/name.js +0 -15
- package/build/store/name.js.map +0 -1
- package/build-module/store/name.js +0 -7
- package/build-module/store/name.js.map +0 -1
- package/src/store/name.js +0 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["renderQueue","useSelect","_mapSelect","deps","isWithoutMapping","mapSelect","registry","isAsync","queueContext","queue","forceRender","s","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","isMountedAndNotUnsubscribing","listeningStores","trapSelect","callback","__experimentalMarkListeningStores","depsChangedFlag","mapOutput","current","select","error","errorMessage","message","stack","console","undefined","flush","onStoreChange","newMapOutput","add","onChange","unsubscribers","map","storeName","__experimentalSubscribeStore","forEach","unsubscribe"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAIA,MAAMA,WAAW,GAAG,iCAApB;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACe,SAASC,SAAT,CAAoBC,UAApB,EAAgCC,IAAhC,EAAuC;AACrD,QAAMC,gBAAgB,GAAG,OAAOF,UAAP,KAAsB,UAA/C;;AAEA,MAAKE,gBAAL,EAAwB;AACvBD,IAAAA,IAAI,GAAG,EAAP;AACA;;AAED,QAAME,SAAS,GAAG,0BAAaH,UAAb,EAAyBC,IAAzB,CAAlB;AACA,QAAMG,QAAQ,GAAG,2BAAjB;AACA,QAAMC,OAAO,GAAG,4BAAhB,CATqD,CAUrD;AACA;AACA;;AACA,Q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AAKG,aAAa,CAACU,OAAnB,EAA6B;AAC5BvB,MAAAA,WAAW,CAACkC,GAAZ,CAAiB1B,YAAjB,EAA+BwB,aAA/B;AACA,KAFD,MAEO;AACNA,MAAAA,aAAa;AACb;;AAED,UAAMG,QAAQ,GAAG,MAAM;AACtB,UAAKtB,aAAa,CAACU,OAAnB,EAA6B;AAC5BvB,QAAAA,WAAW,CAACkC,GAAZ,CAAiB1B,YAAjB,EAA+BwB,aAA/B;AACA,OAFD,MAEO;AACNA,QAAAA,aAAa;AACb;AACD,KAND;;AAQA,UAAMI,aAAa,GAAGnB,eAAe,CAACM,OAAhB,CAAwBc,GAAxB,CAA+BC,SAAF,IAClDhC,QAAQ,CAACiC,4BAAT,CAAuCD,SAAvC,EAAkDH,QAAlD,CADqB,CAAtB;AAIA,WAAO,MAAM;AACZnB,MAAAA,4BAA4B,CAACO,OAA7B,GAAuC,KAAvC,CADY,CAEZ;;AACAa,MAAAA,aAAa,CAACI,OAAd,CAAyBC,WAAF,IAAmBA,WAAnB,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACAzC,MAAAA,WAAW,CAAC+B,KAAZ,CAAmBvB,YAAnB;AACA,KALD;AAMA,GAnDD,EAmDG,CAAEF,QAAF,EAAYY,UAAZ,EAAwBG,eAAxB,EAAyCjB,gBAAzC,CAnDH;AAqDA,SAAOA,gBAAgB,GAAGE,QAAQ,CAACkB,MAAT,CAAiBtB,UAAjB,CAAH,GAAmCoB,SAA1D;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, useReducer, useMemo } 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 renderQueue = createQueue();\n\n/** @typedef {import('./types').WPDataStore} WPDataStore */\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|WPDataStore|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 isWithoutMapping = typeof _mapSelect !== 'function';\n\n\tif ( isWithoutMapping ) {\n\t\tdeps = [];\n\t}\n\n\tconst mapSelect = useCallback( _mapSelect, deps );\n\tconst registry = useRegistry();\n\tconst isAsync = useAsyncMode();\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\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\tconst isMountedAndNotUnsubscribing = 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 trapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__experimentalMarkListeningStores(\n\t\t\t\tcallback,\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 ( ! isWithoutMapping ) {\n\t\ttry {\n\t\t\tif (\n\t\t\t\tlatestMapSelect.current !== mapSelect ||\n\t\t\t\tlatestMapOutputError.current\n\t\t\t) {\n\t\t\t\tmapOutput = trapSelect( () =>\n\t\t\t\t\tmapSelect( registry.select, registry )\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tmapOutput = latestMapOutput.current;\n\t\t\t}\n\t\t} catch ( error ) {\n\t\t\tlet errorMessage = `An error occurred while running 'mapSelect': ${ error.message }`;\n\n\t\t\tif ( latestMapOutputError.current ) {\n\t\t\t\terrorMessage += `\\nThe error may be correlated with this previous error:\\n`;\n\t\t\t\terrorMessage += `${ latestMapOutputError.current.stack }\\n\\n`;\n\t\t\t\terrorMessage += 'Original stack trace:';\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.error( errorMessage );\n\t\t\tmapOutput = latestMapOutput.current;\n\t\t}\n\t}\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( isWithoutMapping ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlatestMapSelect.current = mapSelect;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t\tisMountedAndNotUnsubscribing.current = true;\n\n\t\t// This has to run after the other ref updates\n\t\t// to avoid using stale values in the flushed\n\t\t// callbacks or potentially overwriting a\n\t\t// changed `latestMapOutput.current`.\n\t\tif ( latestIsAsync.current !== isAsync ) {\n\t\t\tlatestIsAsync.current = isAsync;\n\t\t\trenderQueue.flush( queueContext );\n\t\t}\n\t} );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( isWithoutMapping ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\tif ( isMountedAndNotUnsubscribing.current ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst newMapOutput = trapSelect( () =>\n\t\t\t\t\t\tlatestMapSelect.current( registry.select, registry )\n\t\t\t\t\t);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisShallowEqual( latestMapOutput.current, newMapOutput )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t\t}\n\t\t\t\tforceRender();\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\tif ( latestIsAsync.current ) {\n\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t} else {\n\t\t\tonStoreChange();\n\t\t}\n\n\t\tconst onChange = () => {\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\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__experimentalSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\treturn () => {\n\t\t\tisMountedAndNotUnsubscribing.current = false;\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.flush( queueContext );\n\t\t};\n\t}, [ registry, trapSelect, depsChangedFlag, isWithoutMapping ] );\n\n\treturn isWithoutMapping ? registry.select( _mapSelect ) : mapOutput;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/components/use-select/index.js"],"names":["noop","renderQueue","useSelect","mapSelect","deps","hasMappingFunction","callbackMapper","_mapSelect","registry","isAsync","queueContext","queue","forceRender","s","latestMapSelect","latestIsAsync","latestMapOutput","latestMapOutputError","isMountedAndNotUnsubscribing","listeningStores","trapSelect","callback","__experimentalMarkListeningStores","depsChangedFlag","mapOutput","current","hasReplacedMapSelect","lastMapSelectFailed","select","error","errorMessage","message","stack","console","undefined","flush","onStoreChange","newMapOutput","add","onChange","unsubscribers","map","storeName","__experimentalSubscribeStore","forEach","unsubscribe"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AAjBA;AACA;AACA;;AAGA;AACA;AACA;;AAMA;AACA;AACA;AAIA,MAAMA,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,WAAW,GAAG,iCAApB;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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,aAAmBA,WAAnB,uBAAmBA,WAAW,EAArD;AACA5C,MAAAA,WAAW,CAACkC,KAAZ,CAAmBzB,YAAnB;AACA,KALD,CA7CgC,CAmDhC;AACA;AACA;AACA,GAtDD,EAsDG,CAAEF,QAAF,EAAYY,UAAZ,EAAwBf,kBAAxB,EAA4CkB,eAA5C,CAtDH;AAwDA,SAAOlB,kBAAkB,GAAGmB,SAAH,GAAehB,QAAQ,CAACoB,MAAT,CAAiBzB,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\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\n\tconst latestMapSelect = useRef();\n\tconst latestIsAsync = useRef( isAsync );\n\tconst latestMapOutput = useRef();\n\tconst latestMapOutputError = useRef();\n\tconst isMountedAndNotUnsubscribing = 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 trapSelect = useCallback(\n\t\t( callback ) =>\n\t\t\tregistry.__experimentalMarkListeningStores(\n\t\t\t\tcallback,\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 hasReplacedMapSelect = latestMapSelect.current !== _mapSelect;\n\t\tconst lastMapSelectFailed = !! latestMapOutputError.current;\n\n\t\tif ( hasReplacedMapSelect || lastMapSelectFailed ) {\n\t\t\ttry {\n\t\t\t\tmapOutput = trapSelect( () =>\n\t\t\t\t\t_mapSelect( registry.select, registry )\n\t\t\t\t);\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\tlatestMapSelect.current = _mapSelect;\n\t\tlatestMapOutput.current = mapOutput;\n\t\tlatestMapOutputError.current = undefined;\n\t\tisMountedAndNotUnsubscribing.current = true;\n\n\t\t// This has to run after the other ref updates\n\t\t// to avoid using stale values in the flushed\n\t\t// callbacks or potentially overwriting a\n\t\t// changed `latestMapOutput.current`.\n\t\tif ( latestIsAsync.current !== isAsync ) {\n\t\t\tlatestIsAsync.current = isAsync;\n\t\t\trenderQueue.flush( queueContext );\n\t\t}\n\t} );\n\n\tuseIsomorphicLayoutEffect( () => {\n\t\tif ( ! hasMappingFunction ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst onStoreChange = () => {\n\t\t\tif ( isMountedAndNotUnsubscribing.current ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst newMapOutput = trapSelect( () =>\n\t\t\t\t\t\tlatestMapSelect.current( registry.select, registry )\n\t\t\t\t\t);\n\n\t\t\t\t\tif (\n\t\t\t\t\t\tisShallowEqual( latestMapOutput.current, newMapOutput )\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tlatestMapOutput.current = newMapOutput;\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\tlatestMapOutputError.current = error;\n\t\t\t\t}\n\t\t\t\tforceRender();\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\tif ( latestIsAsync.current ) {\n\t\t\trenderQueue.add( queueContext, onStoreChange );\n\t\t} else {\n\t\t\tonStoreChange();\n\t\t}\n\n\t\tconst onChange = () => {\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\tconst unsubscribers = listeningStores.current.map( ( storeName ) =>\n\t\t\tregistry.__experimentalSubscribeStore( storeName, onChange )\n\t\t);\n\n\t\treturn () => {\n\t\t\tisMountedAndNotUnsubscribing.current = false;\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.flush( queueContext );\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, trapSelect, hasMappingFunction, depsChangedFlag ] );\n\n\treturn hasMappingFunction ? mapOutput : registry.select( mapSelect );\n}\n"]}
|
package/build/controls.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.controls = exports.builtinControls = void 0;
|
|
7
7
|
|
|
8
8
|
var _lodash = require("lodash");
|
|
9
9
|
|
|
@@ -17,7 +17,7 @@ var _factory = require("./factory");
|
|
|
17
17
|
* Internal dependencies
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
/** @typedef {import('./types').
|
|
20
|
+
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
21
21
|
const SELECT = '@@data/SELECT';
|
|
22
22
|
const RESOLVE_SELECT = '@@data/RESOLVE_SELECT';
|
|
23
23
|
const DISPATCH = '@@data/DISPATCH';
|
|
@@ -27,9 +27,9 @@ const DISPATCH = '@@data/DISPATCH';
|
|
|
27
27
|
* Note: This control synchronously returns the current selector value, triggering the
|
|
28
28
|
* resolution, but not waiting for it.
|
|
29
29
|
*
|
|
30
|
-
* @param {string|
|
|
31
|
-
* @param {string}
|
|
32
|
-
* @param {Array}
|
|
30
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
31
|
+
* @param {string} selectorName The name of the selector.
|
|
32
|
+
* @param {Array} args Arguments for the selector.
|
|
33
33
|
*
|
|
34
34
|
* @example
|
|
35
35
|
* ```js
|
|
@@ -45,10 +45,14 @@ const DISPATCH = '@@data/DISPATCH';
|
|
|
45
45
|
* @return {Object} The control descriptor.
|
|
46
46
|
*/
|
|
47
47
|
|
|
48
|
-
function select(
|
|
48
|
+
function select(storeNameOrDescriptor, selectorName) {
|
|
49
|
+
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
50
|
+
args[_key - 2] = arguments[_key];
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
return {
|
|
50
54
|
type: SELECT,
|
|
51
|
-
storeKey: (0, _lodash.isObject)(
|
|
55
|
+
storeKey: (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
52
56
|
selectorName,
|
|
53
57
|
args
|
|
54
58
|
};
|
|
@@ -60,9 +64,9 @@ function select(storeNameOrDefinition, selectorName, ...args) {
|
|
|
60
64
|
* selectors that may have a resolver. In such case, it will return a `Promise` that resolves
|
|
61
65
|
* after the selector finishes resolving, with the final result value.
|
|
62
66
|
*
|
|
63
|
-
* @param {string|
|
|
64
|
-
* @param {string}
|
|
65
|
-
* @param {Array}
|
|
67
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
68
|
+
* @param {string} selectorName The name of the selector
|
|
69
|
+
* @param {Array} args Arguments for the selector.
|
|
66
70
|
*
|
|
67
71
|
* @example
|
|
68
72
|
* ```js
|
|
@@ -79,10 +83,14 @@ function select(storeNameOrDefinition, selectorName, ...args) {
|
|
|
79
83
|
*/
|
|
80
84
|
|
|
81
85
|
|
|
82
|
-
function resolveSelect(
|
|
86
|
+
function resolveSelect(storeNameOrDescriptor, selectorName) {
|
|
87
|
+
for (var _len2 = arguments.length, args = new Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
88
|
+
args[_key2 - 2] = arguments[_key2];
|
|
89
|
+
}
|
|
90
|
+
|
|
83
91
|
return {
|
|
84
92
|
type: RESOLVE_SELECT,
|
|
85
|
-
storeKey: (0, _lodash.isObject)(
|
|
93
|
+
storeKey: (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
86
94
|
selectorName,
|
|
87
95
|
args
|
|
88
96
|
};
|
|
@@ -90,9 +98,9 @@ function resolveSelect(storeNameOrDefinition, selectorName, ...args) {
|
|
|
90
98
|
/**
|
|
91
99
|
* Dispatches a control action for triggering a registry dispatch.
|
|
92
100
|
*
|
|
93
|
-
* @param {string|
|
|
94
|
-
* @param {string}
|
|
95
|
-
* @param {Array}
|
|
101
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
102
|
+
* @param {string} actionName The name of the action to dispatch
|
|
103
|
+
* @param {Array} args Arguments for the dispatch action.
|
|
96
104
|
*
|
|
97
105
|
* @example
|
|
98
106
|
* ```js
|
|
@@ -109,10 +117,14 @@ function resolveSelect(storeNameOrDefinition, selectorName, ...args) {
|
|
|
109
117
|
*/
|
|
110
118
|
|
|
111
119
|
|
|
112
|
-
function dispatch(
|
|
120
|
+
function dispatch(storeNameOrDescriptor, actionName) {
|
|
121
|
+
for (var _len3 = arguments.length, args = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
|
|
122
|
+
args[_key3 - 2] = arguments[_key3];
|
|
123
|
+
}
|
|
124
|
+
|
|
113
125
|
return {
|
|
114
126
|
type: DISPATCH,
|
|
115
|
-
storeKey: (0, _lodash.isObject)(
|
|
127
|
+
storeKey: (0, _lodash.isObject)(storeNameOrDescriptor) ? storeNameOrDescriptor.name : storeNameOrDescriptor,
|
|
116
128
|
actionName,
|
|
117
129
|
args
|
|
118
130
|
};
|
|
@@ -125,24 +137,31 @@ const controls = {
|
|
|
125
137
|
};
|
|
126
138
|
exports.controls = controls;
|
|
127
139
|
const builtinControls = {
|
|
128
|
-
[SELECT]: (0, _factory.createRegistryControl)(registry =>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
storeKey
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
140
|
+
[SELECT]: (0, _factory.createRegistryControl)(registry => _ref => {
|
|
141
|
+
let {
|
|
142
|
+
storeKey,
|
|
143
|
+
selectorName,
|
|
144
|
+
args
|
|
145
|
+
} = _ref;
|
|
146
|
+
return registry.select(storeKey)[selectorName](...args);
|
|
147
|
+
}),
|
|
148
|
+
[RESOLVE_SELECT]: (0, _factory.createRegistryControl)(registry => _ref2 => {
|
|
149
|
+
let {
|
|
150
|
+
storeKey,
|
|
151
|
+
selectorName,
|
|
152
|
+
args
|
|
153
|
+
} = _ref2;
|
|
138
154
|
const method = registry.select(storeKey)[selectorName].hasResolver ? 'resolveSelect' : 'select';
|
|
139
155
|
return registry[method](storeKey)[selectorName](...args);
|
|
140
156
|
}),
|
|
141
|
-
[DISPATCH]: (0, _factory.createRegistryControl)(registry =>
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
157
|
+
[DISPATCH]: (0, _factory.createRegistryControl)(registry => _ref3 => {
|
|
158
|
+
let {
|
|
159
|
+
storeKey,
|
|
160
|
+
actionName,
|
|
161
|
+
args
|
|
162
|
+
} = _ref3;
|
|
163
|
+
return registry.dispatch(storeKey)[actionName](...args);
|
|
164
|
+
})
|
|
146
165
|
};
|
|
147
166
|
exports.builtinControls = builtinControls;
|
|
148
167
|
//# sourceMappingURL=controls.js.map
|
package/build/controls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["SELECT","RESOLVE_SELECT","DISPATCH","select","
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/controls.js"],"names":["SELECT","RESOLVE_SELECT","DISPATCH","select","storeNameOrDescriptor","selectorName","args","type","storeKey","name","resolveSelect","dispatch","actionName","controls","builtinControls","registry","method","hasResolver"],"mappings":";;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AAEA,MAAMA,MAAM,GAAG,eAAf;AACA,MAAMC,cAAc,GAAG,uBAAvB;AACA,MAAMC,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AEV,EAAAA,MAAF;AAAUO,EAAAA,aAAV;AAAyBC,EAAAA;AAAzB,CAAjB;;AAEA,MAAMG,eAAe,GAAG;AAC9B,GAAEd,MAAF,GAAY,oCACTe,QAAF,IAAgB;AAAA,QAAE;AAAEP,MAAAA,QAAF;AAAYH,MAAAA,YAAZ;AAA0BC,MAAAA;AAA1B,KAAF;AAAA,WACfS,QAAQ,CAACZ,MAAT,CAAiBK,QAAjB,EAA6BH,YAA7B,EAA6C,GAAGC,IAAhD,CADe;AAAA,GADL,CADkB;AAK9B,GAAEL,cAAF,GAAoB,oCACjBc,QAAF,IAAgB,SAAwC;AAAA,QAAtC;AAAEP,MAAAA,QAAF;AAAYH,MAAAA,YAAZ;AAA0BC,MAAAA;AAA1B,KAAsC;AACvD,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,EAAgD,GAAGC,IAAnD,CAAP;AACA,GAPkB,CALU;AAc9B,GAAEJ,QAAF,GAAc,oCACXa,QAAF,IAAgB;AAAA,QAAE;AAAEP,MAAAA,QAAF;AAAYI,MAAAA,UAAZ;AAAwBN,MAAAA;AAAxB,KAAF;AAAA,WACfS,QAAQ,CAACJ,QAAT,CAAmBH,QAAnB,EAA+BI,UAA/B,EAA6C,GAAGN,IAAhD,CADe;AAAA,GADH;AAdgB,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 ) => ( { storeKey, selectorName, args } ) =>\n\t\t\tregistry.select( storeKey )[ selectorName ]( ...args )\n\t),\n\t[ RESOLVE_SELECT ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, selectorName, args } ) => {\n\t\t\tconst method = registry.select( storeKey )[ selectorName ]\n\t\t\t\t.hasResolver\n\t\t\t\t? 'resolveSelect'\n\t\t\t\t: 'select';\n\t\t\treturn registry[ method ]( storeKey )[ selectorName ]( ...args );\n\t\t}\n\t),\n\t[ DISPATCH ]: createRegistryControl(\n\t\t( registry ) => ( { storeKey, actionName, args } ) =>\n\t\t\tregistry.dispatch( storeKey )[ actionName ]( ...args )\n\t),\n};\n"]}
|
package/build/factory.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.createRegistrySelector = createRegistrySelector;
|
|
7
6
|
exports.createRegistryControl = createRegistryControl;
|
|
7
|
+
exports.createRegistrySelector = createRegistrySelector;
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a selector function that takes additional curried argument with the
|
|
@@ -47,7 +47,9 @@ function createRegistrySelector(registrySelector) {
|
|
|
47
47
|
// create a selector function that is bound to the registry referenced by `selector.registry`
|
|
48
48
|
// and that has the same API as a regular selector. Binding it in such a way makes it
|
|
49
49
|
// possible to call the selector directly from another selector.
|
|
50
|
-
const selector = (
|
|
50
|
+
const selector = function () {
|
|
51
|
+
return registrySelector(selector.registry.select)(...arguments);
|
|
52
|
+
};
|
|
51
53
|
/**
|
|
52
54
|
* Flag indicating that the selector is a registry selector that needs the correct registry
|
|
53
55
|
* reference to be assigned to `selecto.registry` to make it work correctly.
|
package/build/factory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/factory.js"],"names":["createRegistrySelector","registrySelector","selector","registry","select","isRegistrySelector","createRegistryControl","registryControl","isRegistryControl"],"mappings":";;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAT,CAAiCC,gBAAjC,EAAoD;AAC1D;AACA;AACA;AACA,QAAMC,QAAQ,GAAG;AAAA,WAChBD,gBAAgB,CAAEC,QAAQ,CAACC,QAAT,CAAkBC,MAApB,CAAhB,CAA8C,YAA9C,CADgB;AAAA,GAAjB;AAGA;AACD;AACA;AACA;AACA;AACA;AACA;;;AACCF,EAAAA,QAAQ,CAACG,kBAAT,GAA8B,IAA9B;AAEA,SAAOH,QAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,qBAAT,CAAgCC,eAAhC,EAAkD;AACxDA,EAAAA,eAAe,CAACC,iBAAhB,GAAoC,IAApC;AAEA,SAAOD,eAAP;AACA","sourcesContent":["/**\n * Creates a selector function that takes additional curried argument with the\n * registry `select` function. While a regular selector has signature\n * ```js\n * ( state, ...selectorArgs ) => ( result )\n * ```\n * that allows to select data from the store's `state`, a registry selector\n * has signature:\n * ```js\n * ( select ) => ( state, ...selectorArgs ) => ( result )\n * ```\n * that supports also selecting from other registered stores.\n *\n * @example\n * ```js\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( 'core/editor' ).getCurrentPostId();\n * } );\n *\n * const getPostEdits = createRegistrySelector( ( select ) => ( state ) => {\n * // calling another registry selector just like any other function\n * const postType = getCurrentPostType( state );\n * const postId = getCurrentPostId( state );\n *\t return select( 'core' ).getEntityRecordEdits( 'postType', postType, postId );\n * } );\n * ```\n *\n * Note how the `getCurrentPostId` selector can be called just like any other function,\n * (it works even inside a regular non-registry selector) and we don't need to pass the\n * registry as argument. The registry binding happens automatically when registering the selector\n * with a store.\n *\n * @param {Function} registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return {Function} Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector( registrySelector ) {\n\t// create a selector function that is bound to the registry referenced by `selector.registry`\n\t// and that has the same API as a regular selector. Binding it in such a way makes it\n\t// possible to call the selector directly from another selector.\n\tconst selector = ( ...args ) =>\n\t\tregistrySelector( selector.registry.select )( ...args );\n\n\t/**\n\t * Flag indicating that the selector is a registry selector that needs the correct registry\n\t * reference to be assigned to `selecto.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t *\n\t * @type {boolean}\n\t */\n\tselector.isRegistrySelector = true;\n\n\treturn selector;\n}\n\n/**\n * Creates a control function that takes additional curried argument with the `registry` object.\n * While a regular control has signature\n * ```js\n * ( action ) => ( iteratorOrPromise )\n * ```\n * where the control works with the `action` that it's bound to, a registry control has signature:\n * ```js\n * ( registry ) => ( action ) => ( iteratorOrPromise )\n * ```\n * A registry control is typically used to select data or dispatch an action to a registered\n * store.\n *\n * When registering a control created with `createRegistryControl` with a store, the store\n * knows which calling convention to use when executing the control.\n *\n * @param {Function} registryControl Function receiving a registry object and returning a control.\n *\n * @return {Function} Registry control that can be registered with a store.\n */\nexport function createRegistryControl( registryControl ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -1,103 +1,101 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
-
|
|
5
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
6
4
|
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
|
-
Object.defineProperty(exports, "
|
|
8
|
+
Object.defineProperty(exports, "AsyncModeProvider", {
|
|
11
9
|
enumerable: true,
|
|
12
10
|
get: function () {
|
|
13
|
-
return
|
|
11
|
+
return _asyncModeProvider.AsyncModeProvider;
|
|
14
12
|
}
|
|
15
13
|
});
|
|
16
|
-
Object.defineProperty(exports, "
|
|
14
|
+
Object.defineProperty(exports, "RegistryConsumer", {
|
|
17
15
|
enumerable: true,
|
|
18
16
|
get: function () {
|
|
19
|
-
return
|
|
17
|
+
return _registryProvider.RegistryConsumer;
|
|
20
18
|
}
|
|
21
19
|
});
|
|
22
|
-
Object.defineProperty(exports, "
|
|
20
|
+
Object.defineProperty(exports, "RegistryProvider", {
|
|
23
21
|
enumerable: true,
|
|
24
22
|
get: function () {
|
|
25
|
-
return
|
|
23
|
+
return _registryProvider.RegistryProvider;
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
|
-
Object.defineProperty(exports, "
|
|
26
|
+
Object.defineProperty(exports, "combineReducers", {
|
|
29
27
|
enumerable: true,
|
|
30
28
|
get: function () {
|
|
31
|
-
return
|
|
29
|
+
return _turboCombineReducers.default;
|
|
32
30
|
}
|
|
33
31
|
});
|
|
34
|
-
Object.defineProperty(exports, "
|
|
32
|
+
Object.defineProperty(exports, "controls", {
|
|
35
33
|
enumerable: true,
|
|
36
34
|
get: function () {
|
|
37
|
-
return
|
|
35
|
+
return _controls.controls;
|
|
38
36
|
}
|
|
39
37
|
});
|
|
40
|
-
Object.defineProperty(exports, "
|
|
38
|
+
Object.defineProperty(exports, "createReduxStore", {
|
|
41
39
|
enumerable: true,
|
|
42
40
|
get: function () {
|
|
43
|
-
return
|
|
41
|
+
return _reduxStore.default;
|
|
44
42
|
}
|
|
45
43
|
});
|
|
46
|
-
Object.defineProperty(exports, "
|
|
44
|
+
Object.defineProperty(exports, "createRegistry", {
|
|
47
45
|
enumerable: true,
|
|
48
46
|
get: function () {
|
|
49
|
-
return
|
|
47
|
+
return _registry.createRegistry;
|
|
50
48
|
}
|
|
51
49
|
});
|
|
52
|
-
Object.defineProperty(exports, "
|
|
50
|
+
Object.defineProperty(exports, "createRegistryControl", {
|
|
53
51
|
enumerable: true,
|
|
54
52
|
get: function () {
|
|
55
|
-
return
|
|
53
|
+
return _factory.createRegistryControl;
|
|
56
54
|
}
|
|
57
55
|
});
|
|
58
|
-
Object.defineProperty(exports, "
|
|
56
|
+
Object.defineProperty(exports, "createRegistrySelector", {
|
|
59
57
|
enumerable: true,
|
|
60
58
|
get: function () {
|
|
61
|
-
return
|
|
59
|
+
return _factory.createRegistrySelector;
|
|
62
60
|
}
|
|
63
61
|
});
|
|
64
|
-
|
|
62
|
+
exports.use = exports.subscribe = exports.select = exports.resolveSelect = exports.registerStore = exports.registerGenericStore = exports.register = exports.plugins = exports.dispatch = void 0;
|
|
63
|
+
Object.defineProperty(exports, "useDispatch", {
|
|
65
64
|
enumerable: true,
|
|
66
65
|
get: function () {
|
|
67
|
-
return
|
|
66
|
+
return _useDispatch.useDispatch;
|
|
68
67
|
}
|
|
69
68
|
});
|
|
70
|
-
Object.defineProperty(exports, "
|
|
69
|
+
Object.defineProperty(exports, "useRegistry", {
|
|
71
70
|
enumerable: true,
|
|
72
71
|
get: function () {
|
|
73
|
-
return
|
|
72
|
+
return _registryProvider.useRegistry;
|
|
74
73
|
}
|
|
75
74
|
});
|
|
76
|
-
Object.defineProperty(exports, "
|
|
75
|
+
Object.defineProperty(exports, "useSelect", {
|
|
77
76
|
enumerable: true,
|
|
78
77
|
get: function () {
|
|
79
|
-
return
|
|
78
|
+
return _useSelect.default;
|
|
80
79
|
}
|
|
81
80
|
});
|
|
82
|
-
Object.defineProperty(exports, "
|
|
81
|
+
Object.defineProperty(exports, "withDispatch", {
|
|
83
82
|
enumerable: true,
|
|
84
83
|
get: function () {
|
|
85
|
-
return
|
|
84
|
+
return _withDispatch.default;
|
|
86
85
|
}
|
|
87
86
|
});
|
|
88
|
-
Object.defineProperty(exports, "
|
|
87
|
+
Object.defineProperty(exports, "withRegistry", {
|
|
89
88
|
enumerable: true,
|
|
90
89
|
get: function () {
|
|
91
|
-
return
|
|
90
|
+
return _withRegistry.default;
|
|
92
91
|
}
|
|
93
92
|
});
|
|
94
|
-
Object.defineProperty(exports, "
|
|
93
|
+
Object.defineProperty(exports, "withSelect", {
|
|
95
94
|
enumerable: true,
|
|
96
95
|
get: function () {
|
|
97
|
-
return
|
|
96
|
+
return _withSelect.default;
|
|
98
97
|
}
|
|
99
98
|
});
|
|
100
|
-
exports.plugins = exports.register = exports.use = exports.registerStore = exports.registerGenericStore = exports.subscribe = exports.dispatch = exports.resolveSelect = exports.select = void 0;
|
|
101
99
|
|
|
102
100
|
var _turboCombineReducers = _interopRequireDefault(require("turbo-combine-reducers"));
|
|
103
101
|
|
|
@@ -129,6 +127,10 @@ var _controls = require("./controls");
|
|
|
129
127
|
|
|
130
128
|
var _reduxStore = _interopRequireDefault(require("./redux-store"));
|
|
131
129
|
|
|
130
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
131
|
+
|
|
132
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
133
|
+
|
|
132
134
|
/**
|
|
133
135
|
* External dependencies
|
|
134
136
|
*/
|
|
@@ -137,7 +139,7 @@ var _reduxStore = _interopRequireDefault(require("./redux-store"));
|
|
|
137
139
|
* Internal dependencies
|
|
138
140
|
*/
|
|
139
141
|
|
|
140
|
-
/** @typedef {import('./types').
|
|
142
|
+
/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */
|
|
141
143
|
|
|
142
144
|
/**
|
|
143
145
|
* Object of available plugins to use with a registry.
|
|
@@ -187,12 +189,12 @@ var _reduxStore = _interopRequireDefault(require("./redux-store"));
|
|
|
187
189
|
*/
|
|
188
190
|
|
|
189
191
|
/**
|
|
190
|
-
* Given the name or
|
|
192
|
+
* Given the name or descriptor of a registered store, returns an object of the store's selectors.
|
|
191
193
|
* The selector functions are been pre-bound to pass the current state automatically.
|
|
192
194
|
* As a consumer, you need only pass arguments of the selector, if applicable.
|
|
193
195
|
*
|
|
194
|
-
* @param {string|
|
|
195
|
-
*
|
|
196
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
197
|
+
* or the store descriptor.
|
|
196
198
|
*
|
|
197
199
|
* @example
|
|
198
200
|
* ```js
|
|
@@ -210,8 +212,8 @@ const select = _defaultRegistry.default.select;
|
|
|
210
212
|
* and modified so that they return promises that resolve to their eventual values,
|
|
211
213
|
* after any resolvers have ran.
|
|
212
214
|
*
|
|
213
|
-
* @param {string|
|
|
214
|
-
*
|
|
215
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
216
|
+
* or the store descriptor.
|
|
215
217
|
*
|
|
216
218
|
* @example
|
|
217
219
|
* ```js
|
|
@@ -232,8 +234,8 @@ const resolveSelect = _defaultRegistry.default.resolveSelect;
|
|
|
232
234
|
* Note: Action creators returned by the dispatch will return a promise when
|
|
233
235
|
* they are called.
|
|
234
236
|
*
|
|
235
|
-
* @param {string|
|
|
236
|
-
*
|
|
237
|
+
* @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store
|
|
238
|
+
* or the store descriptor.
|
|
237
239
|
*
|
|
238
240
|
* @example
|
|
239
241
|
* ```js
|
|
@@ -270,12 +272,12 @@ const dispatch = _defaultRegistry.default.dispatch;
|
|
|
270
272
|
exports.dispatch = dispatch;
|
|
271
273
|
const subscribe = _defaultRegistry.default.subscribe;
|
|
272
274
|
/**
|
|
273
|
-
* Registers a generic store.
|
|
275
|
+
* Registers a generic store instance.
|
|
274
276
|
*
|
|
275
|
-
* @deprecated Use `register` instead.
|
|
277
|
+
* @deprecated Use `register( storeDescriptor )` instead.
|
|
276
278
|
*
|
|
277
|
-
* @param {string}
|
|
278
|
-
* @param {Object}
|
|
279
|
+
* @param {string} name Store registry name.
|
|
280
|
+
* @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).
|
|
279
281
|
*/
|
|
280
282
|
|
|
281
283
|
exports.subscribe = subscribe;
|
|
@@ -304,7 +306,7 @@ const registerStore = _defaultRegistry.default.registerStore;
|
|
|
304
306
|
exports.registerStore = registerStore;
|
|
305
307
|
const use = _defaultRegistry.default.use;
|
|
306
308
|
/**
|
|
307
|
-
* Registers a standard `@wordpress/data` store
|
|
309
|
+
* Registers a standard `@wordpress/data` store descriptor.
|
|
308
310
|
*
|
|
309
311
|
* @example
|
|
310
312
|
* ```js
|
|
@@ -319,7 +321,7 @@ const use = _defaultRegistry.default.use;
|
|
|
319
321
|
* register( store );
|
|
320
322
|
* ```
|
|
321
323
|
*
|
|
322
|
-
* @param {
|
|
324
|
+
* @param {StoreDescriptor} store Store descriptor.
|
|
323
325
|
*/
|
|
324
326
|
|
|
325
327
|
exports.use = use;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/data/src/index.js"],"names":["select","defaultRegistry","resolveSelect","dispatch","subscribe","registerGenericStore","registerStore","use","register"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/data/src/index.js"],"names":["select","defaultRegistry","resolveSelect","dispatch","subscribe","registerGenericStore","registerStore","use","register"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;;;AAIA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AA3BA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AAkBA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,MAAM,GAAGC,yBAAgBD,MAA/B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAME,aAAa,GAAGD,yBAAgBC,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGF,yBAAgBE,QAAjC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,SAAS,GAAGH,yBAAgBG,SAAlC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,oBAAoB,GAAGJ,yBAAgBI,oBAA7C;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,aAAa,GAAGL,yBAAgBK,aAAtC;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,GAAG,GAAGN,yBAAgBM,GAA5B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMC,QAAQ,GAAGP,yBAAgBO,QAAjC","sourcesContent":["/**\n * External dependencies\n */\nimport combineReducers from 'turbo-combine-reducers';\n\n/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\n\n/** @typedef {import('./types').StoreDescriptor} StoreDescriptor */\n\nexport { default as withSelect } from './components/with-select';\nexport { default as withDispatch } from './components/with-dispatch';\nexport { default as withRegistry } from './components/with-registry';\nexport {\n\tRegistryProvider,\n\tRegistryConsumer,\n\tuseRegistry,\n} from './components/registry-provider';\nexport { default as useSelect } from './components/use-select';\nexport { useDispatch } from './components/use-dispatch';\nexport { AsyncModeProvider } from './components/async-mode-provider';\nexport { createRegistry } from './registry';\nexport { createRegistrySelector, createRegistryControl } from './factory';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\n *\n * @type {Object}\n */\nexport { plugins };\n\n/**\n * The combineReducers helper function turns an object whose values are different\n * reducing functions into a single reducing function you can pass to registerReducer.\n *\n * @param {Object} reducers An object whose values correspond to different reducing\n * functions that need to be combined into one.\n *\n * @example\n * ```js\n * import { combineReducers, createReduxStore, register } from '@wordpress/data';\n *\n * const prices = ( state = {}, action ) => {\n * \treturn action.type === 'SET_PRICE' ?\n * \t\t{\n * \t\t\t...state,\n * \t\t\t[ action.item ]: action.price,\n * \t\t} :\n * \t\tstate;\n * };\n *\n * const discountPercent = ( state = 0, action ) => {\n * \treturn action.type === 'START_SALE' ?\n * \t\taction.discountPercent :\n * \t\tstate;\n * };\n *\n * const store = createReduxStore( 'my-shop', {\n * \treducer: combineReducers( {\n * \t\tprices,\n * \t\tdiscountPercent,\n * \t} ),\n * } );\n * register( store );\n * ```\n *\n * @return {Function} A reducer that invokes every reducer inside the reducers\n * object, and constructs a state object with the same shape.\n */\nexport { combineReducers };\n\n/**\n * Given the name or descriptor of a registered store, returns an object of the store's selectors.\n * The selector functions are been pre-bound to pass the current state automatically.\n * As a consumer, you need only pass arguments of the selector, if applicable.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * or the store descriptor.\n *\n * @example\n * ```js\n * import { select } from '@wordpress/data';\n *\n * select( 'my-shop' ).getPrice( 'hammer' );\n * ```\n *\n * @return {Object} Object containing the store's selectors.\n */\nexport const select = defaultRegistry.select;\n\n/**\n * Given the name of a registered store, returns an object containing the store's\n * selectors pre-bound to state so that you only need to supply additional arguments,\n * and modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * or the store descriptor.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n *\n * resolveSelect( 'my-shop' ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return {Object} Object containing the store's promise-wrapped selectors.\n */\nexport const resolveSelect = defaultRegistry.resolveSelect;\n\n/**\n * Given the name of a registered store, returns an object of the store's action creators.\n * Calling an action creator will cause it to be dispatched, updating the state value accordingly.\n *\n * Note: Action creators returned by the dispatch will return a promise when\n * they are called.\n *\n * @param {string|StoreDescriptor} storeNameOrDescriptor Unique namespace identifier for the store\n * or the store descriptor.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n *\n * dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );\n * ```\n * @return {Object} Object containing the action creators.\n */\nexport const dispatch = defaultRegistry.dispatch;\n\n/**\n * Given a listener function, the function will be called any time the state value\n * of one of the registered stores has changed. This function returns a `unsubscribe`\n * function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n *\n * @example\n * ```js\n * import { subscribe } from '@wordpress/data';\n *\n * const unsubscribe = subscribe( () => {\n * \t// You could use this opportunity to test whether the derived result of a\n * \t// selector has subsequently changed as the result of a state update.\n * } );\n *\n * // Later, if necessary...\n * unsubscribe();\n * ```\n */\nexport const subscribe = defaultRegistry.subscribe;\n\n/**\n * Registers a generic store instance.\n *\n * @deprecated Use `register( storeDescriptor )` instead.\n *\n * @param {string} name Store registry name.\n * @param {Object} store Store instance (`{ getSelectors, getActions, subscribe }`).\n */\nexport const registerGenericStore = defaultRegistry.registerGenericStore;\n\n/**\n * Registers a standard `@wordpress/data` store.\n *\n * @deprecated Use `register` instead.\n *\n * @param {string} storeName Unique namespace identifier for the store.\n * @param {Object} options Store description (reducer, actions, selectors, resolvers).\n *\n * @return {Object} Registered store object.\n */\nexport const registerStore = defaultRegistry.registerStore;\n\n/**\n * Extends a registry to inherit functionality provided by a given plugin. A\n * plugin is an object with properties aligning to that of a registry, merged\n * to extend the default registry behavior.\n *\n * @param {Object} plugin Plugin object.\n */\nexport const use = defaultRegistry.use;\n\n/**\n * Registers a standard `@wordpress/data` store descriptor.\n *\n * @example\n * ```js\n * import { createReduxStore, register } from '@wordpress/data';\n *\n * const store = createReduxStore( 'demo', {\n * reducer: ( state = 'OK' ) => state,\n * selectors: {\n * getValue: ( state ) => state,\n * },\n * } );\n * register( store );\n * ```\n *\n * @param {StoreDescriptor} store Store descriptor.\n */\nexport const register = defaultRegistry.register;\n"]}
|
|
@@ -6,8 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
8
|
exports.createPersistenceInterface = createPersistenceInterface;
|
|
9
|
+
exports.default = void 0;
|
|
9
10
|
exports.migrateFeaturePreferencesToInterfaceStore = migrateFeaturePreferencesToInterfaceStore;
|
|
10
|
-
exports.
|
|
11
|
+
exports.withLazySameState = void 0;
|
|
11
12
|
|
|
12
13
|
var _lodash = require("lodash");
|
|
13
14
|
|