@wordpress/data 10.41.0 → 10.41.1-next.v.202603102151.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/README.md +20 -28
- package/build/components/async-mode-provider/context.cjs +1 -1
- package/build/components/async-mode-provider/context.cjs.map +3 -3
- package/build/components/async-mode-provider/index.cjs +1 -1
- package/build/components/async-mode-provider/index.cjs.map +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs +1 -1
- package/build/components/async-mode-provider/use-async-mode.cjs.map +3 -3
- package/build/components/registry-provider/context.cjs +1 -1
- package/build/components/registry-provider/context.cjs.map +1 -1
- package/build/components/registry-provider/index.cjs +1 -1
- package/build/components/registry-provider/index.cjs.map +1 -1
- package/build/components/registry-provider/use-registry.cjs +1 -1
- package/build/components/registry-provider/use-registry.cjs.map +3 -3
- package/build/components/use-dispatch/index.cjs +1 -1
- package/build/components/use-dispatch/index.cjs.map +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch-with-map.cjs.map +3 -3
- package/build/components/use-dispatch/use-dispatch.cjs +1 -1
- package/build/components/use-dispatch/use-dispatch.cjs.map +3 -3
- package/build/components/use-select/index.cjs +2 -2
- package/build/components/use-select/index.cjs.map +3 -3
- package/build/components/with-dispatch/index.cjs +1 -1
- package/build/components/with-dispatch/index.cjs.map +3 -3
- package/build/components/with-registry/index.cjs +1 -1
- package/build/components/with-registry/index.cjs.map +3 -3
- package/build/components/with-select/index.cjs +1 -1
- package/build/components/with-select/index.cjs.map +3 -3
- package/build/controls.cjs +7 -6
- package/build/controls.cjs.map +3 -3
- package/build/default-registry.cjs +3 -2
- package/build/default-registry.cjs.map +3 -3
- package/build/dispatch.cjs +3 -1
- package/build/dispatch.cjs.map +2 -2
- package/build/factory.cjs.map +2 -2
- package/build/index.cjs +9 -8
- package/build/index.cjs.map +3 -3
- package/build/plugins/index.cjs +1 -1
- package/build/plugins/index.cjs.map +1 -1
- package/build/plugins/persistence/index.cjs +13 -8
- package/build/plugins/persistence/index.cjs.map +3 -3
- package/build/plugins/persistence/storage/default.cjs +1 -1
- package/build/plugins/persistence/storage/default.cjs.map +3 -3
- package/build/plugins/persistence/storage/object.cjs +1 -1
- package/build/plugins/persistence/storage/object.cjs.map +3 -3
- package/build/promise-middleware.cjs +2 -1
- package/build/promise-middleware.cjs.map +3 -3
- package/build/redux-store/index.cjs +32 -16
- package/build/redux-store/index.cjs.map +3 -3
- package/build/redux-store/metadata/selectors.cjs +1 -1
- package/build/redux-store/metadata/selectors.cjs.map +3 -3
- package/build/redux-store/metadata/types.cjs +19 -0
- package/build/redux-store/metadata/types.cjs.map +7 -0
- package/build/registry.cjs +11 -7
- package/build/registry.cjs.map +3 -3
- package/build/resolvers-cache-middleware.cjs +6 -3
- package/build/resolvers-cache-middleware.cjs.map +3 -3
- package/build/select.cjs +3 -1
- package/build/select.cjs.map +2 -2
- package/build/store/index.cjs +1 -1
- package/build/store/index.cjs.map +3 -3
- package/build/types.cjs.map +1 -1
- package/build-module/components/async-mode-provider/context.mjs +1 -1
- package/build-module/components/async-mode-provider/context.mjs.map +3 -3
- package/build-module/components/async-mode-provider/index.mjs +1 -1
- package/build-module/components/async-mode-provider/index.mjs.map +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs +1 -1
- package/build-module/components/async-mode-provider/use-async-mode.mjs.map +3 -3
- package/build-module/components/registry-provider/context.mjs +1 -1
- package/build-module/components/registry-provider/context.mjs.map +1 -1
- package/build-module/components/registry-provider/index.mjs +1 -1
- package/build-module/components/registry-provider/index.mjs.map +1 -1
- package/build-module/components/registry-provider/use-registry.mjs +1 -1
- package/build-module/components/registry-provider/use-registry.mjs.map +3 -3
- package/build-module/components/use-dispatch/index.mjs +1 -1
- package/build-module/components/use-dispatch/index.mjs.map +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch-with-map.mjs.map +3 -3
- package/build-module/components/use-dispatch/use-dispatch.mjs +1 -1
- package/build-module/components/use-dispatch/use-dispatch.mjs.map +3 -3
- package/build-module/components/use-select/index.mjs +2 -2
- package/build-module/components/use-select/index.mjs.map +3 -3
- package/build-module/components/with-dispatch/index.mjs +1 -1
- package/build-module/components/with-dispatch/index.mjs.map +3 -3
- package/build-module/components/with-registry/index.mjs +1 -1
- package/build-module/components/with-registry/index.mjs.map +3 -3
- package/build-module/components/with-select/index.mjs +1 -1
- package/build-module/components/with-select/index.mjs.map +3 -3
- package/build-module/controls.mjs +7 -6
- package/build-module/controls.mjs.map +3 -3
- package/build-module/default-registry.mjs +3 -2
- package/build-module/default-registry.mjs.map +3 -3
- package/build-module/dispatch.mjs +3 -1
- package/build-module/dispatch.mjs.map +2 -2
- package/build-module/factory.mjs.map +2 -2
- package/build-module/index.mjs +4 -3
- package/build-module/index.mjs.map +2 -2
- package/build-module/plugins/index.mjs +1 -1
- package/build-module/plugins/index.mjs.map +1 -1
- package/build-module/plugins/persistence/index.mjs +13 -8
- package/build-module/plugins/persistence/index.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/default.mjs +1 -1
- package/build-module/plugins/persistence/storage/default.mjs.map +3 -3
- package/build-module/plugins/persistence/storage/object.mjs +1 -1
- package/build-module/plugins/persistence/storage/object.mjs.map +3 -3
- package/build-module/promise-middleware.mjs +2 -1
- package/build-module/promise-middleware.mjs.map +3 -3
- package/build-module/redux-store/index.mjs +32 -16
- package/build-module/redux-store/index.mjs.map +3 -3
- package/build-module/redux-store/metadata/selectors.mjs +1 -1
- package/build-module/redux-store/metadata/selectors.mjs.map +3 -3
- package/build-module/redux-store/metadata/types.mjs +1 -0
- package/build-module/redux-store/metadata/types.mjs.map +7 -0
- package/build-module/registry.mjs +11 -7
- package/build-module/registry.mjs.map +3 -3
- package/build-module/resolvers-cache-middleware.mjs +6 -3
- package/build-module/resolvers-cache-middleware.mjs.map +3 -3
- package/build-module/select.mjs +3 -1
- package/build-module/select.mjs.map +2 -2
- package/build-module/store/index.mjs +1 -1
- package/build-module/store/index.mjs.map +3 -3
- package/build-types/components/async-mode-provider/context.d.ts +37 -3
- package/build-types/components/async-mode-provider/context.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/index.d.ts +2 -2
- package/build-types/components/async-mode-provider/index.d.ts.map +1 -1
- package/build-types/components/async-mode-provider/use-async-mode.d.ts.map +1 -1
- package/build-types/components/registry-provider/context.d.ts +10 -3
- package/build-types/components/registry-provider/context.d.ts.map +1 -1
- package/build-types/components/registry-provider/index.d.ts +2 -2
- package/build-types/components/registry-provider/index.d.ts.map +1 -1
- package/build-types/components/registry-provider/use-registry.d.ts +3 -2
- package/build-types/components/registry-provider/use-registry.d.ts.map +1 -1
- package/build-types/components/use-dispatch/index.d.ts +2 -2
- package/build-types/components/use-dispatch/index.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts +11 -9
- package/build-types/components/use-dispatch/use-dispatch-with-map.d.ts.map +1 -1
- package/build-types/components/use-dispatch/use-dispatch.d.ts +10 -19
- package/build-types/components/use-dispatch/use-dispatch.d.ts.map +1 -1
- package/build-types/components/use-select/index.d.ts +24 -28
- package/build-types/components/use-select/index.d.ts.map +1 -1
- package/build-types/components/with-dispatch/index.d.ts +10 -11
- package/build-types/components/with-dispatch/index.d.ts.map +1 -1
- package/build-types/components/with-registry/index.d.ts +2 -6
- package/build-types/components/with-registry/index.d.ts.map +1 -1
- package/build-types/components/with-select/index.d.ts +7 -8
- package/build-types/components/with-select/index.d.ts.map +1 -1
- package/build-types/controls.d.ts +57 -44
- package/build-types/controls.d.ts.map +1 -1
- package/build-types/default-registry.d.ts +2 -2
- package/build-types/default-registry.d.ts.map +1 -1
- package/build-types/dispatch.d.ts +4 -0
- package/build-types/dispatch.d.ts.map +1 -1
- package/build-types/factory.d.ts +2 -1
- package/build-types/factory.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/plugins/index.d.ts +1 -1
- package/build-types/plugins/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/index.d.ts +38 -27
- package/build-types/plugins/persistence/index.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/default.d.ts +7 -1
- package/build-types/plugins/persistence/storage/default.d.ts.map +1 -1
- package/build-types/plugins/persistence/storage/object.d.ts +4 -5
- package/build-types/plugins/persistence/storage/object.d.ts.map +1 -1
- package/build-types/promise-middleware.d.ts +6 -4
- package/build-types/promise-middleware.d.ts.map +1 -1
- package/build-types/redux-store/index.d.ts +12 -15
- package/build-types/redux-store/index.d.ts.map +1 -1
- package/build-types/redux-store/metadata/selectors.d.ts +45 -50
- package/build-types/redux-store/metadata/selectors.d.ts.map +1 -1
- package/build-types/redux-store/metadata/types.d.ts +48 -0
- package/build-types/redux-store/metadata/types.d.ts.map +1 -0
- package/build-types/registry.d.ts +5 -49
- package/build-types/registry.d.ts.map +1 -1
- package/build-types/resolvers-cache-middleware.d.ts +13 -7
- package/build-types/resolvers-cache-middleware.d.ts.map +1 -1
- package/build-types/select.d.ts +3 -0
- package/build-types/select.d.ts.map +1 -1
- package/build-types/store/index.d.ts +5 -12
- package/build-types/store/index.d.ts.map +1 -1
- package/build-types/types.d.ts +201 -10
- package/build-types/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/components/async-mode-provider/{context.js → context.ts} +0 -1
- package/src/components/async-mode-provider/{use-async-mode.js → use-async-mode.ts} +1 -1
- package/src/components/registry-provider/{use-registry.js → use-registry.ts} +3 -2
- package/src/components/use-dispatch/{use-dispatch-with-map.js → use-dispatch-with-map.ts} +18 -9
- package/src/components/use-dispatch/{use-dispatch.js → use-dispatch.ts} +25 -20
- package/src/components/use-select/{index.js → index.ts} +84 -70
- package/src/components/with-dispatch/{index.js → index.tsx} +20 -13
- package/src/components/with-registry/{index.js → index.tsx} +1 -5
- package/src/components/with-select/{index.js → index.tsx} +17 -10
- package/src/{controls.js → controls.ts} +53 -26
- package/src/{default-registry.js → default-registry.ts} +3 -1
- package/src/dispatch.ts +7 -1
- package/src/factory.ts +4 -3
- package/src/index.ts +4 -8
- package/src/plugins/persistence/{index.js → index.ts} +93 -54
- package/src/plugins/persistence/storage/{default.js → default.ts} +3 -2
- package/src/plugins/persistence/storage/object.ts +25 -0
- package/src/{promise-middleware.js → promise-middleware.ts} +3 -3
- package/src/redux-store/{index.js → index.ts} +218 -131
- package/src/redux-store/metadata/{selectors.js → selectors.ts} +83 -54
- package/src/redux-store/metadata/types.ts +100 -0
- package/src/{registry.js → registry.ts} +98 -88
- package/src/{resolvers-cache-middleware.js → resolvers-cache-middleware.ts} +22 -7
- package/src/select.ts +6 -1
- package/src/store/{index.js → index.ts} +13 -8
- package/src/types.ts +263 -24
- package/src/plugins/persistence/storage/object.js +0 -23
- /package/src/components/async-mode-provider/{index.js → index.ts} +0 -0
- /package/src/components/registry-provider/{context.js → context.ts} +0 -0
- /package/src/components/registry-provider/{index.js → index.ts} +0 -0
- /package/src/components/use-dispatch/{index.js → index.ts} +0 -0
- /package/src/plugins/{index.js → index.ts} +0 -0
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
// packages/data/src/dispatch.ts
|
|
2
2
|
import defaultRegistry from "./default-registry.mjs";
|
|
3
3
|
function dispatch(storeNameOrDescriptor) {
|
|
4
|
-
return defaultRegistry.dispatch(
|
|
4
|
+
return defaultRegistry.dispatch(
|
|
5
|
+
storeNameOrDescriptor
|
|
6
|
+
);
|
|
5
7
|
}
|
|
6
8
|
export {
|
|
7
9
|
dispatch
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/dispatch.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, StoreDescriptor, DispatchReturn } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, 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 storeNameOrDescriptor The store descriptor. The legacy calling convention of passing\n * the store name is also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return Object containing the action creators.\n */\nexport function dispatch<\n\tStoreNameOrDescriptor extends StoreDescriptor< AnyConfig > | string,\n>(\n\tstoreNameOrDescriptor: StoreNameOrDescriptor\n): DispatchReturn< StoreNameOrDescriptor > {\n\treturn defaultRegistry.dispatch(
|
|
5
|
-
"mappings": ";AAIA,OAAO,qBAAqB;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { AnyConfig, StoreDescriptor, DispatchReturn } from './types';\nimport defaultRegistry from './default-registry';\n\n/**\n * Given a store descriptor, 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 * Warning: This global `dispatch` function only works with the default registry.\n * It will not work with custom `RegistryProvider` or `BlockEditorProvider` contexts.\n * In React components, prefer the `useDispatch` hook instead, which is registry-aware.\n *\n * @param storeNameOrDescriptor The store descriptor. The legacy calling convention of passing\n * the store name is also supported.\n *\n * @example\n * ```js\n * import { dispatch } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );\n * ```\n * @return Object containing the action creators.\n */\nexport function dispatch<\n\tStoreNameOrDescriptor extends StoreDescriptor< AnyConfig > | string,\n>(\n\tstoreNameOrDescriptor: StoreNameOrDescriptor\n): DispatchReturn< StoreNameOrDescriptor > {\n\treturn defaultRegistry.dispatch(\n\t\tstoreNameOrDescriptor\n\t) as DispatchReturn< StoreNameOrDescriptor >;\n}\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO,qBAAqB;AAyBrB,SAAS,SAGf,uBAC0C;AAC1C,SAAO,gBAAgB;AAAA,IACtB;AAAA,EACD;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/factory.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { select as globalSelect } from './select';\n\ntype RegistrySelector< Selector extends ( ...args: any[] ) => any > = {\n\t( ...args: Parameters< Selector > ): ReturnType< Selector >;\n\tisRegistrySelector?: boolean;\n\tregistry?: any;\n};\n\n/**\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 * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).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( coreStore ).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 registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector<\n\tSelector extends ( ...args: any[] ) => any,\n>(\n\tregistrySelector: ( select: typeof globalSelect ) => Selector\n): RegistrySelector< Selector > {\n\tconst selectorsByRegistry = new WeakMap();\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 wrappedSelector: RegistrySelector< Selector > = ( ...args ) => {\n\t\tlet selector = selectorsByRegistry.get( wrappedSelector.registry );\n\t\t// We want to make sure the cache persists even when new registry\n\t\t// instances are created. For example patterns create their own editors\n\t\t// with their own core/block-editor stores, so we should keep track of\n\t\t// the cache for each registry instance.\n\t\tif ( ! selector ) {\n\t\t\tselector = registrySelector( wrappedSelector.registry.select );\n\t\t\tselectorsByRegistry.set( wrappedSelector.registry, selector );\n\t\t}\n\t\treturn selector( ...args );\n\t};\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 `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t */\n\twrappedSelector.isRegistrySelector = true;\n\n\treturn wrappedSelector;\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 registryControl Function receiving a registry object and returning a control.\n *\n * @return Registry control that can be registered with a store.\n */\nexport function createRegistryControl
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { select as globalSelect } from './select';\nimport type { DataRegistry } from './types';\n\ntype RegistrySelector< Selector extends ( ...args: any[] ) => any > = {\n\t( ...args: Parameters< Selector > ): ReturnType< Selector >;\n\tisRegistrySelector?: boolean;\n\tregistry?: any;\n};\n\n/**\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 * import { store as coreStore } from '@wordpress/core-data';\n * import { store as editorStore } from '@wordpress/editor';\n *\n * const getCurrentPostId = createRegistrySelector( ( select ) => ( state ) => {\n * return select( editorStore ).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( coreStore ).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 registrySelector Function receiving a registry `select`\n * function and returning a state selector.\n *\n * @return Registry selector that can be registered with a store.\n */\nexport function createRegistrySelector<\n\tSelector extends ( ...args: any[] ) => any,\n>(\n\tregistrySelector: ( select: typeof globalSelect ) => Selector\n): RegistrySelector< Selector > {\n\tconst selectorsByRegistry = new WeakMap();\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 wrappedSelector: RegistrySelector< Selector > = ( ...args ) => {\n\t\tlet selector = selectorsByRegistry.get( wrappedSelector.registry );\n\t\t// We want to make sure the cache persists even when new registry\n\t\t// instances are created. For example patterns create their own editors\n\t\t// with their own core/block-editor stores, so we should keep track of\n\t\t// the cache for each registry instance.\n\t\tif ( ! selector ) {\n\t\t\tselector = registrySelector( wrappedSelector.registry.select );\n\t\t\tselectorsByRegistry.set( wrappedSelector.registry, selector );\n\t\t}\n\t\treturn selector( ...args );\n\t};\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 `selector.registry` to make it work correctly.\n\t * be mapped as a registry selector.\n\t */\n\twrappedSelector.isRegistrySelector = true;\n\n\treturn wrappedSelector;\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 registryControl Function receiving a registry object and returning a control.\n *\n * @return Registry control that can be registered with a store.\n */\nexport function createRegistryControl<\n\tT extends ( registry: DataRegistry ) => ( ...args: any ) => any,\n>( registryControl: T & { isRegistryControl?: boolean } ) {\n\tregistryControl.isRegistryControl = true;\n\n\treturn registryControl;\n}\n"],
|
|
5
|
+
"mappings": ";AAoDO,SAAS,uBAGf,kBAC+B;AAC/B,QAAM,sBAAsB,oBAAI,QAAQ;AAIxC,QAAM,kBAAgD,IAAK,SAAU;AACpE,QAAI,WAAW,oBAAoB,IAAK,gBAAgB,QAAS;AAKjE,QAAK,CAAE,UAAW;AACjB,iBAAW,iBAAkB,gBAAgB,SAAS,MAAO;AAC7D,0BAAoB,IAAK,gBAAgB,UAAU,QAAS;AAAA,IAC7D;AACA,WAAO,SAAU,GAAG,IAAK;AAAA,EAC1B;AAOA,kBAAgB,qBAAqB;AAErC,SAAO;AACR;AAsBO,SAAS,sBAEb,iBAAuD;AACzD,kBAAgB,oBAAoB;AAEpC,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// packages/data/src/index.ts
|
|
2
|
-
import
|
|
2
|
+
import defaultRegistry from "./default-registry.mjs";
|
|
3
3
|
import * as plugins from "./plugins/index.mjs";
|
|
4
4
|
import { combineReducers as combineReducersModule } from "./redux-store/index.mjs";
|
|
5
5
|
import { default as default2 } from "./components/with-select/index.mjs";
|
|
@@ -23,10 +23,11 @@ import { controls } from "./controls.mjs";
|
|
|
23
23
|
import { default as default6 } from "./redux-store/index.mjs";
|
|
24
24
|
import { dispatch } from "./dispatch.mjs";
|
|
25
25
|
import { select } from "./select.mjs";
|
|
26
|
-
var defaultRegistry = defaultRegistryUntyped;
|
|
27
26
|
var combineReducers = combineReducersModule;
|
|
28
27
|
function resolveSelect(storeNameOrDescriptor) {
|
|
29
|
-
return defaultRegistry.resolveSelect(
|
|
28
|
+
return defaultRegistry.resolveSelect(
|
|
29
|
+
storeNameOrDescriptor
|
|
30
|
+
);
|
|
30
31
|
}
|
|
31
32
|
var suspendSelect = (storeNameOrDescriptor) => defaultRegistry.suspendSelect(storeNameOrDescriptor);
|
|
32
33
|
var subscribe = (listener, storeNameOrDescriptor) => defaultRegistry.subscribe(listener, storeNameOrDescriptor);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport
|
|
5
|
-
"mappings": ";AAGA,OAAO,
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport defaultRegistry from './default-registry';\nimport * as plugins from './plugins';\nimport { combineReducers as combineReducersModule } from './redux-store';\n\nimport type {\n\tStoreDescriptor,\n\tReduxStoreConfig,\n\tcombineReducers as CombineReducers,\n\tAnyConfig,\n\tCurriedSelectorsResolveOf,\n} from './types';\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 {\n\tdefault as useSelect,\n\tuseSuspenseSelect,\n} 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 { createSelector } from './create-selector';\nexport { controls } from './controls';\nexport { default as createReduxStore } from './redux-store';\nexport { dispatch } from './dispatch';\nexport { select } from './select';\n\nexport type * from './types';\n\n/**\n * Object of available plugins to use with a registry.\n *\n * @see [use](#use)\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 * @type {import('./types').combineReducers}\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 const combineReducers =\n\tcombineReducersModule as unknown as CombineReducers;\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors\n * pre-bound to state so that you only need to supply additional arguments, and\n * modified so that they return promises that resolve to their eventual values,\n * after any resolvers have ran.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @example\n * ```js\n * import { resolveSelect } from '@wordpress/data';\n * import { store as myCustomStore } from 'my-custom-store';\n *\n * resolveSelect( myCustomStore ).getPrice( 'hammer' ).then(console.log)\n * ```\n *\n * @return Object containing the store's promise-wrapped selectors.\n */\nexport function resolveSelect< T extends StoreDescriptor< AnyConfig > >(\n\tstoreNameOrDescriptor: T | string\n): CurriedSelectorsResolveOf< T > {\n\treturn defaultRegistry.resolveSelect(\n\t\tstoreNameOrDescriptor\n\t) as CurriedSelectorsResolveOf< T >;\n}\n\n/**\n * Given a store descriptor, returns an object containing the store's selectors pre-bound to state\n * so that you only need to supply additional arguments, and modified so that they throw promises\n * in case the selector is not resolved yet.\n *\n * @param {StoreDescriptor|string} storeNameOrDescriptor The store descriptor. The legacy calling\n * convention of passing the store name is\n * also supported.\n *\n * @return {Object} Object containing the store's suspense-wrapped selectors.\n */\nexport const suspendSelect = (\n\tstoreNameOrDescriptor:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): any => defaultRegistry.suspendSelect( storeNameOrDescriptor );\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. If you specify the optional\n * `storeNameOrDescriptor` parameter, the listener function will be called only\n * on updates on that one specific registered store.\n *\n * This function returns an `unsubscribe` function used to stop the subscription.\n *\n * @param {Function} listener Callback function.\n * @param {string|StoreDescriptor?} storeNameOrDescriptor Optional store name.\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 = (\n\tlistener: () => void,\n\tstoreNameOrDescriptor?:\n\t\t| string\n\t\t| StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): ( () => void ) =>\n\tdefaultRegistry.subscribe( listener, storeNameOrDescriptor );\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: Function =\n\tdefaultRegistry.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: Function = 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: any = 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 = (\n\tstore: StoreDescriptor< ReduxStoreConfig< any, any, any > >\n): void => defaultRegistry.register( store );\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,qBAAqB;AAC5B,YAAY,aAAa;AACzB,SAAS,mBAAmB,6BAA6B;AAUzD,SAAoB,WAAXA,gBAA6B;AACtC,SAAoB,WAAXA,gBAA+B;AACxC,SAAoB,WAAXA,gBAA+B;AACxC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACY,WAAXA;AAAA,EACA;AAAA,OACM;AACP,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB,6BAA6B;AAC9D,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,SAAoB,WAAXA,gBAAmC;AAC5C,SAAS,gBAAgB;AACzB,SAAS,cAAc;AAkDhB,IAAM,kBACZ;AAsBM,SAAS,cACf,uBACiC;AACjC,SAAO,gBAAgB;AAAA,IACtB;AAAA,EACD;AACD;AAaO,IAAM,gBAAgB,CAC5B,0BAGS,gBAAgB,cAAe,qBAAsB;AA0BxD,IAAM,YAAY,CACxB,UACA,0BAIA,gBAAgB,UAAW,UAAU,qBAAsB;AAUrD,IAAM,uBACZ,gBAAgB;AAYV,IAAM,gBAA0B,gBAAgB;AAShD,IAAM,MAAW,gBAAgB;AAoBjC,IAAM,WAAW,CACvB,UACU,gBAAgB,SAAU,KAAM;",
|
|
6
6
|
"names": ["default"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/data/src/plugins/persistence/index.
|
|
1
|
+
// packages/data/src/plugins/persistence/index.ts
|
|
2
2
|
import { isPlainObject } from "is-plain-object";
|
|
3
3
|
import deepmerge from "deepmerge";
|
|
4
4
|
import defaultStorage from "./storage/default.mjs";
|
|
@@ -53,7 +53,7 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
53
53
|
combineReducers(reducers)
|
|
54
54
|
);
|
|
55
55
|
} else {
|
|
56
|
-
getPersistedState = (
|
|
56
|
+
getPersistedState = (_state, action) => action.nextState;
|
|
57
57
|
}
|
|
58
58
|
let lastState = getPersistedState(void 0, {
|
|
59
59
|
nextState: getState()
|
|
@@ -79,9 +79,13 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
79
79
|
type: "@@WP/PERSISTENCE_RESTORE"
|
|
80
80
|
});
|
|
81
81
|
if (isPlainObject(initialState) && isPlainObject(persistedState)) {
|
|
82
|
-
initialState = deepmerge(
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
initialState = deepmerge(
|
|
83
|
+
initialState,
|
|
84
|
+
persistedState,
|
|
85
|
+
{
|
|
86
|
+
isMergeableObject: isPlainObject
|
|
87
|
+
}
|
|
88
|
+
);
|
|
85
89
|
} else {
|
|
86
90
|
initialState = persistedState;
|
|
87
91
|
}
|
|
@@ -102,9 +106,10 @@ function persistencePlugin(registry, pluginOptions) {
|
|
|
102
106
|
}
|
|
103
107
|
};
|
|
104
108
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
var persistence_default = Object.assign(persistencePlugin, {
|
|
110
|
+
__unstableMigrate: () => {
|
|
111
|
+
}
|
|
112
|
+
});
|
|
108
113
|
export {
|
|
109
114
|
createPersistenceInterface,
|
|
110
115
|
persistence_default as default,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/plugins/persistence/index.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../../../src/plugins/persistence/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\n// @ts-expect-error -- is-plain-object types don't resolve with package.json \"exports\".\nimport { isPlainObject } from 'is-plain-object';\nimport deepmerge from 'deepmerge';\n\n/**\n * Internal dependencies\n */\nimport defaultStorage from './storage/default';\nimport { combineReducers } from '../../';\nimport type {\n\tDataRegistry,\n\tReduxStoreConfig,\n\tStorageInterface,\n} from '../../types';\n\ninterface PersistencePluginOptions {\n\t/**\n\t * Persistent storage implementation. This must\n\t * at least implement `getItem` and `setItem` of\n\t * the Web Storage API.\n\t */\n\tstorage?: StorageInterface;\n\t/**\n\t * Key on which to set in persistent storage.\n\t */\n\tstorageKey?: string;\n}\n\ninterface PersistenceInterface {\n\tget: () => Record< string, unknown >;\n\tset: ( key: string, value: unknown ) => void;\n}\n\n/**\n * Default plugin storage.\n */\nconst DEFAULT_STORAGE = defaultStorage;\n\n/**\n * Default plugin storage key.\n */\nconst DEFAULT_STORAGE_KEY = 'WP_DATA';\n\n/**\n * Higher-order reducer which invokes the original reducer only if state is\n * inequal from that of the action's `nextState` property, otherwise returning\n * the original state reference.\n *\n * @param reducer Original reducer.\n *\n * @return Enhanced reducer.\n */\nexport const withLazySameState =\n\t( reducer: ( state: any, action: any ) => any ) =>\n\t( state: unknown, action: { nextState: unknown } ) => {\n\t\tif ( action.nextState === state ) {\n\t\t\treturn state;\n\t\t}\n\n\t\treturn reducer( state, action );\n\t};\n\n/**\n * Creates a persistence interface, exposing getter and setter methods (`get`\n * and `set` respectively).\n *\n * @param options Plugin options.\n *\n * @return Persistence interface.\n */\nexport function createPersistenceInterface(\n\toptions: PersistencePluginOptions\n): PersistenceInterface {\n\tconst { storage = DEFAULT_STORAGE, storageKey = DEFAULT_STORAGE_KEY } =\n\t\toptions;\n\n\tlet data: Record< string, unknown > | undefined;\n\n\t/**\n\t * Returns the persisted data as an object, defaulting to an empty object.\n\t *\n\t * @return Persisted data.\n\t */\n\tfunction getData(): Record< string, unknown > {\n\t\tif ( data === undefined ) {\n\t\t\t// If unset, getItem is expected to return null. Fall back to\n\t\t\t// empty object.\n\t\t\tconst persisted = storage.getItem( storageKey );\n\t\t\tif ( persisted === null ) {\n\t\t\t\tdata = {};\n\t\t\t} else {\n\t\t\t\ttry {\n\t\t\t\t\tdata = JSON.parse( persisted );\n\t\t\t\t} catch ( error ) {\n\t\t\t\t\t// Similarly, should any error be thrown during parse of\n\t\t\t\t\t// the string (malformed JSON), fall back to empty object.\n\t\t\t\t\tdata = {};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn data!;\n\t}\n\n\t/**\n\t * Merges an updated reducer state into the persisted data.\n\t *\n\t * @param key Key to update.\n\t * @param value Updated value.\n\t */\n\tfunction setData( key: string, value: unknown ): void {\n\t\tdata = { ...data, [ key ]: value };\n\t\tstorage.setItem( storageKey, JSON.stringify( data ) );\n\t}\n\n\treturn {\n\t\tget: getData,\n\t\tset: setData,\n\t};\n}\n\n/**\n * Data plugin to persist store state into a single storage key.\n *\n * @param registry Data registry.\n * @param pluginOptions Plugin options.\n *\n * @return Data plugin.\n */\nfunction persistencePlugin(\n\tregistry: DataRegistry,\n\tpluginOptions: PersistencePluginOptions\n): Partial< DataRegistry > {\n\tconst persistence = createPersistenceInterface( pluginOptions );\n\n\t/**\n\t * Creates an enhanced store dispatch function, triggering the state of the\n\t * given store name to be persisted when changed.\n\t *\n\t * @param getState Function which returns current state.\n\t * @param storeName Store name.\n\t * @param keys Optional subset of keys to save.\n\t *\n\t * @return Enhanced dispatch function.\n\t */\n\tfunction createPersistOnChange(\n\t\tgetState: () => unknown,\n\t\tstoreName: string,\n\t\tkeys: boolean | string[]\n\t): () => void {\n\t\tlet getPersistedState: ( state: any, action: any ) => any;\n\t\tif ( Array.isArray( keys ) ) {\n\t\t\t// Given keys, the persisted state should by produced as an object\n\t\t\t// of the subset of keys. This implementation uses combineReducers\n\t\t\t// to leverage its behavior of returning the same object when none\n\t\t\t// of the property values changes. This allows a strict reference\n\t\t\t// equality to bypass a persistence set on an unchanging state.\n\t\t\tconst reducers = keys.reduce(\n\t\t\t\t(\n\t\t\t\t\taccumulator: Record<\n\t\t\t\t\t\tstring,\n\t\t\t\t\t\t( state: any, action: any ) => any\n\t\t\t\t\t>,\n\t\t\t\t\tkey: string\n\t\t\t\t) =>\n\t\t\t\t\tObject.assign( accumulator, {\n\t\t\t\t\t\t[ key ]: (\n\t\t\t\t\t\t\tstate: unknown,\n\t\t\t\t\t\t\taction: { nextState: Record< string, unknown > }\n\t\t\t\t\t\t) => action.nextState[ key ],\n\t\t\t\t\t} ),\n\t\t\t\t{}\n\t\t\t);\n\n\t\t\tgetPersistedState = withLazySameState(\n\t\t\t\tcombineReducers( reducers )\n\t\t\t);\n\t\t} else {\n\t\t\tgetPersistedState = (\n\t\t\t\t_state: unknown,\n\t\t\t\taction: { nextState: unknown }\n\t\t\t) => action.nextState;\n\t\t}\n\n\t\tlet lastState = getPersistedState( undefined, {\n\t\t\tnextState: getState(),\n\t\t} );\n\n\t\treturn () => {\n\t\t\tconst state = getPersistedState( lastState, {\n\t\t\t\tnextState: getState(),\n\t\t\t} );\n\t\t\tif ( state !== lastState ) {\n\t\t\t\tpersistence.set( storeName, state );\n\t\t\t\tlastState = state;\n\t\t\t}\n\t\t};\n\t}\n\n\treturn {\n\t\tregisterStore(\n\t\t\tstoreName: string,\n\t\t\toptions: ReduxStoreConfig< any, any, any > & {\n\t\t\t\tpersist?: boolean | string[];\n\t\t\t}\n\t\t) {\n\t\t\tif ( ! options.persist ) {\n\t\t\t\treturn registry.registerStore( storeName, options );\n\t\t\t}\n\n\t\t\t// Load from persistence to use as initial state.\n\t\t\tconst persistedState = persistence.get()[ storeName ];\n\t\t\tif ( persistedState !== undefined ) {\n\t\t\t\tlet initialState = options.reducer( options.initialState, {\n\t\t\t\t\ttype: '@@WP/PERSISTENCE_RESTORE',\n\t\t\t\t} );\n\n\t\t\t\tif (\n\t\t\t\t\tisPlainObject( initialState ) &&\n\t\t\t\t\tisPlainObject( persistedState )\n\t\t\t\t) {\n\t\t\t\t\t// If state is an object, ensure that:\n\t\t\t\t\t// - Other keys are left intact when persisting only a\n\t\t\t\t\t// subset of keys.\n\t\t\t\t\t// - New keys in what would otherwise be used as initial\n\t\t\t\t\t// state are deeply merged as base for persisted value.\n\t\t\t\t\tinitialState = deepmerge(\n\t\t\t\t\t\tinitialState as Record< string, unknown >,\n\t\t\t\t\t\tpersistedState as Record< string, unknown >,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tisMergeableObject: isPlainObject,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\t// If there is a mismatch in object-likeness of default\n\t\t\t\t\t// initial or persisted state, defer to persisted value.\n\t\t\t\t\tinitialState = persistedState;\n\t\t\t\t}\n\n\t\t\t\toptions = {\n\t\t\t\t\t...options,\n\t\t\t\t\tinitialState,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst store = registry.registerStore( storeName, options );\n\n\t\t\tstore.subscribe(\n\t\t\t\tcreatePersistOnChange(\n\t\t\t\t\tstore.getState,\n\t\t\t\t\tstoreName,\n\t\t\t\t\toptions.persist!\n\t\t\t\t)\n\t\t\t);\n\n\t\t\treturn store;\n\t\t},\n\t};\n}\n\nexport default Object.assign( persistencePlugin, {\n\t__unstableMigrate: () => {},\n} );\n"],
|
|
5
|
+
"mappings": ";AAIA,SAAS,qBAAqB;AAC9B,OAAO,eAAe;AAKtB,OAAO,oBAAoB;AAC3B,SAAS,uBAAuB;AA4BhC,IAAM,kBAAkB;AAKxB,IAAM,sBAAsB;AAWrB,IAAM,oBACZ,CAAE,YACF,CAAE,OAAgB,WAAoC;AACrD,MAAK,OAAO,cAAc,OAAQ;AACjC,WAAO;AAAA,EACR;AAEA,SAAO,QAAS,OAAO,MAAO;AAC/B;AAUM,SAAS,2BACf,SACuB;AACvB,QAAM,EAAE,UAAU,iBAAiB,aAAa,oBAAoB,IACnE;AAED,MAAI;AAOJ,WAAS,UAAqC;AAC7C,QAAK,SAAS,QAAY;AAGzB,YAAM,YAAY,QAAQ,QAAS,UAAW;AAC9C,UAAK,cAAc,MAAO;AACzB,eAAO,CAAC;AAAA,MACT,OAAO;AACN,YAAI;AACH,iBAAO,KAAK,MAAO,SAAU;AAAA,QAC9B,SAAU,OAAQ;AAGjB,iBAAO,CAAC;AAAA,QACT;AAAA,MACD;AAAA,IACD;AAEA,WAAO;AAAA,EACR;AAQA,WAAS,QAAS,KAAa,OAAuB;AACrD,WAAO,EAAE,GAAG,MAAM,CAAE,GAAI,GAAG,MAAM;AACjC,YAAQ,QAAS,YAAY,KAAK,UAAW,IAAK,CAAE;AAAA,EACrD;AAEA,SAAO;AAAA,IACN,KAAK;AAAA,IACL,KAAK;AAAA,EACN;AACD;AAUA,SAAS,kBACR,UACA,eAC0B;AAC1B,QAAM,cAAc,2BAA4B,aAAc;AAY9D,WAAS,sBACR,UACA,WACA,MACa;AACb,QAAI;AACJ,QAAK,MAAM,QAAS,IAAK,GAAI;AAM5B,YAAM,WAAW,KAAK;AAAA,QACrB,CACC,aAIA,QAEA,OAAO,OAAQ,aAAa;AAAA,UAC3B,CAAE,GAAI,GAAG,CACR,OACA,WACI,OAAO,UAAW,GAAI;AAAA,QAC5B,CAAE;AAAA,QACH,CAAC;AAAA,MACF;AAEA,0BAAoB;AAAA,QACnB,gBAAiB,QAAS;AAAA,MAC3B;AAAA,IACD,OAAO;AACN,0BAAoB,CACnB,QACA,WACI,OAAO;AAAA,IACb;AAEA,QAAI,YAAY,kBAAmB,QAAW;AAAA,MAC7C,WAAW,SAAS;AAAA,IACrB,CAAE;AAEF,WAAO,MAAM;AACZ,YAAM,QAAQ,kBAAmB,WAAW;AAAA,QAC3C,WAAW,SAAS;AAAA,MACrB,CAAE;AACF,UAAK,UAAU,WAAY;AAC1B,oBAAY,IAAK,WAAW,KAAM;AAClC,oBAAY;AAAA,MACb;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AAAA,IACN,cACC,WACA,SAGC;AACD,UAAK,CAAE,QAAQ,SAAU;AACxB,eAAO,SAAS,cAAe,WAAW,OAAQ;AAAA,MACnD;AAGA,YAAM,iBAAiB,YAAY,IAAI,EAAG,SAAU;AACpD,UAAK,mBAAmB,QAAY;AACnC,YAAI,eAAe,QAAQ,QAAS,QAAQ,cAAc;AAAA,UACzD,MAAM;AAAA,QACP,CAAE;AAEF,YACC,cAAe,YAAa,KAC5B,cAAe,cAAe,GAC7B;AAMD,yBAAe;AAAA,YACd;AAAA,YACA;AAAA,YACA;AAAA,cACC,mBAAmB;AAAA,YACpB;AAAA,UACD;AAAA,QACD,OAAO;AAGN,yBAAe;AAAA,QAChB;AAEA,kBAAU;AAAA,UACT,GAAG;AAAA,UACH;AAAA,QACD;AAAA,MACD;AAEA,YAAM,QAAQ,SAAS,cAAe,WAAW,OAAQ;AAEzD,YAAM;AAAA,QACL;AAAA,UACC,MAAM;AAAA,UACN;AAAA,UACA,QAAQ;AAAA,QACT;AAAA,MACD;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AACD;AAEA,IAAO,sBAAQ,OAAO,OAAQ,mBAAmB;AAAA,EAChD,mBAAmB,MAAM;AAAA,EAAC;AAC3B,CAAE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/plugins/persistence/storage/default.
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport objectStorage from './object';\n\nlet storage;\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem( '__wpDataTestLocalStorage' );\n} catch ( error ) {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../../../../src/plugins/persistence/storage/default.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { StorageInterface } from '../../../types';\nimport objectStorage from './object';\n\nlet storage: StorageInterface & { removeItem?: ( key: string ) => void };\n\ntry {\n\t// Private Browsing in Safari 10 and earlier will throw an error when\n\t// attempting to set into localStorage. The test here is intentional in\n\t// causing a thrown error as condition for using fallback object storage.\n\tstorage = window.localStorage;\n\tstorage.setItem( '__wpDataTestLocalStorage', '' );\n\tstorage.removeItem!( '__wpDataTestLocalStorage' );\n} catch ( error ) {\n\tstorage = objectStorage;\n}\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO,mBAAmB;AAE1B,IAAI;AAEJ,IAAI;AAIH,YAAU,OAAO;AACjB,UAAQ,QAAS,4BAA4B,EAAG;AAChD,UAAQ,WAAa,0BAA2B;AACjD,SAAU,OAAQ;AACjB,YAAU;AACX;AAEA,IAAO,kBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/plugins/persistence/storage/object.
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../../../../src/plugins/persistence/storage/object.ts"],
|
|
4
|
+
"sourcesContent": ["import type { StorageInterface } from '../../../types';\n\nlet objectStorage: Record< string, string > | undefined;\n\nconst storage: StorageInterface & { clear: VoidFunction } = {\n\tgetItem( key: string ): string | null {\n\t\tif ( ! objectStorage || ! objectStorage[ key ] ) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn objectStorage[ key ];\n\t},\n\tsetItem( key: string, value: string ) {\n\t\tif ( ! objectStorage ) {\n\t\t\tstorage.clear();\n\t\t}\n\n\t\tobjectStorage![ key ] = String( value );\n\t},\n\tclear() {\n\t\tobjectStorage = Object.create( null );\n\t},\n};\n\nexport default storage;\n"],
|
|
5
|
+
"mappings": ";AAEA,IAAI;AAEJ,IAAM,UAAsD;AAAA,EAC3D,QAAS,KAA6B;AACrC,QAAK,CAAE,iBAAiB,CAAE,cAAe,GAAI,GAAI;AAChD,aAAO;AAAA,IACR;AAEA,WAAO,cAAe,GAAI;AAAA,EAC3B;AAAA,EACA,QAAS,KAAa,OAAgB;AACrC,QAAK,CAAE,eAAgB;AACtB,cAAQ,MAAM;AAAA,IACf;AAEA,kBAAgB,GAAI,IAAI,OAAQ,KAAM;AAAA,EACvC;AAAA,EACA,QAAQ;AACP,oBAAgB,uBAAO,OAAQ,IAAK;AAAA,EACrC;AACD;AAEA,IAAO,iBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/data/src/promise-middleware.
|
|
1
|
+
// packages/data/src/promise-middleware.ts
|
|
2
2
|
import isPromise from "is-promise";
|
|
3
3
|
var promiseMiddleware = () => (next) => (action) => {
|
|
4
4
|
if (isPromise(action)) {
|
|
@@ -6,6 +6,7 @@ var promiseMiddleware = () => (next) => (action) => {
|
|
|
6
6
|
if (resolvedAction) {
|
|
7
7
|
return next(resolvedAction);
|
|
8
8
|
}
|
|
9
|
+
return void 0;
|
|
9
10
|
});
|
|
10
11
|
}
|
|
11
12
|
return next(action);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/promise-middleware.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport isPromise from 'is-promise';\n\n/**\n * Simplest possible promise redux middleware.\n
|
|
5
|
-
"mappings": ";
|
|
3
|
+
"sources": ["../src/promise-middleware.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { Middleware } from 'redux';\nimport isPromise from 'is-promise';\n\n/**\n * Simplest possible promise redux middleware.\n */\nconst promiseMiddleware: Middleware = () => ( next ) => ( action ) => {\n\tif ( isPromise( action ) ) {\n\t\treturn action.then( ( resolvedAction ) => {\n\t\t\tif ( resolvedAction ) {\n\t\t\t\treturn next( resolvedAction );\n\t\t\t}\n\t\t\treturn undefined;\n\t\t} );\n\t}\n\n\treturn next( action );\n};\n\nexport default promiseMiddleware;\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAO,eAAe;AAKtB,IAAM,oBAAgC,MAAM,CAAE,SAAU,CAAE,WAAY;AACrE,MAAK,UAAW,MAAO,GAAI;AAC1B,WAAO,OAAO,KAAM,CAAE,mBAAoB;AACzC,UAAK,gBAAiB;AACrB,eAAO,KAAM,cAAe;AAAA,MAC7B;AACA,aAAO;AAAA,IACR,CAAE;AAAA,EACH;AAEA,SAAO,KAAM,MAAO;AACrB;AAEA,IAAO,6BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/data/src/redux-store/index.
|
|
1
|
+
// packages/data/src/redux-store/index.ts
|
|
2
2
|
import { createStore, applyMiddleware } from "redux";
|
|
3
3
|
import EquivalentKeyMap from "equivalent-key-map";
|
|
4
4
|
import createReduxRoutineMiddleware from "@wordpress/redux-routine";
|
|
@@ -27,11 +27,11 @@ var mapValues = (obj, callback) => Object.fromEntries(
|
|
|
27
27
|
callback(value, key)
|
|
28
28
|
])
|
|
29
29
|
);
|
|
30
|
-
var devToolsReplacer = (
|
|
30
|
+
var devToolsReplacer = (_key, state) => {
|
|
31
31
|
if (state instanceof Map) {
|
|
32
32
|
return Object.fromEntries(state);
|
|
33
33
|
}
|
|
34
|
-
if (state instanceof window.HTMLElement) {
|
|
34
|
+
if (typeof window !== "undefined" && state instanceof window.HTMLElement) {
|
|
35
35
|
return null;
|
|
36
36
|
}
|
|
37
37
|
return state;
|
|
@@ -40,7 +40,7 @@ function createResolversCache() {
|
|
|
40
40
|
const cache = {};
|
|
41
41
|
return {
|
|
42
42
|
isRunning(selectorName, args) {
|
|
43
|
-
return cache[selectorName] && cache[selectorName].get(trimUndefinedValues(args));
|
|
43
|
+
return !!(cache[selectorName] && cache[selectorName].get(trimUndefinedValues(args)));
|
|
44
44
|
},
|
|
45
45
|
clear(selectorName, args) {
|
|
46
46
|
if (cache[selectorName]) {
|
|
@@ -119,8 +119,14 @@ function createReduxStore(key, options) {
|
|
|
119
119
|
return (...args) => Promise.resolve(store.dispatch(action(...args)));
|
|
120
120
|
}
|
|
121
121
|
const actions = {
|
|
122
|
-
...mapValues(
|
|
123
|
-
|
|
122
|
+
...mapValues(
|
|
123
|
+
metadataActions,
|
|
124
|
+
bindAction
|
|
125
|
+
),
|
|
126
|
+
...mapValues(
|
|
127
|
+
options.actions,
|
|
128
|
+
bindAction
|
|
129
|
+
)
|
|
124
130
|
};
|
|
125
131
|
const allActions = createPrivateProxy(
|
|
126
132
|
actions,
|
|
@@ -131,10 +137,15 @@ function createReduxStore(key, options) {
|
|
|
131
137
|
);
|
|
132
138
|
const thunkDispatch = new Proxy(
|
|
133
139
|
(action) => store.dispatch(action),
|
|
134
|
-
{
|
|
140
|
+
{
|
|
141
|
+
get: (_target, name) => allActions[name]
|
|
142
|
+
}
|
|
135
143
|
);
|
|
136
144
|
lock(actions, allActions);
|
|
137
|
-
const resolvers = options.resolvers ? mapValues(
|
|
145
|
+
const resolvers = options.resolvers ? mapValues(
|
|
146
|
+
options.resolvers,
|
|
147
|
+
mapResolver
|
|
148
|
+
) : {};
|
|
138
149
|
function bindSelector(selector, selectorName) {
|
|
139
150
|
if (selector.isRegistrySelector) {
|
|
140
151
|
selector.registry = registry;
|
|
@@ -188,7 +199,10 @@ function createReduxStore(key, options) {
|
|
|
188
199
|
metadataSelectors,
|
|
189
200
|
bindMetadataSelector
|
|
190
201
|
);
|
|
191
|
-
const boundSelectors = mapValues(
|
|
202
|
+
const boundSelectors = mapValues(
|
|
203
|
+
options.selectors,
|
|
204
|
+
bindSelector
|
|
205
|
+
);
|
|
192
206
|
const selectors = {
|
|
193
207
|
...boundMetadataSelectors,
|
|
194
208
|
...boundSelectors
|
|
@@ -206,7 +220,9 @@ function createReduxStore(key, options) {
|
|
|
206
220
|
}
|
|
207
221
|
const thunkSelect = new Proxy(
|
|
208
222
|
(selector) => selector(store.__unstableOriginalGetState()),
|
|
209
|
-
{
|
|
223
|
+
{
|
|
224
|
+
get: (_target, name) => allSelectors[name]
|
|
225
|
+
}
|
|
210
226
|
);
|
|
211
227
|
lock(selectors, allSelectors);
|
|
212
228
|
const bindResolveSelector = mapResolveSelector(
|
|
@@ -248,10 +264,10 @@ function createReduxStore(key, options) {
|
|
|
248
264
|
const getSuspendSelectors = () => suspendSelectors;
|
|
249
265
|
store.__unstableOriginalGetState = store.getState;
|
|
250
266
|
store.getState = () => store.__unstableOriginalGetState().root;
|
|
251
|
-
const subscribe =
|
|
267
|
+
const subscribe = (listener) => {
|
|
252
268
|
listeners.add(listener);
|
|
253
269
|
return () => listeners.delete(listener);
|
|
254
|
-
}
|
|
270
|
+
};
|
|
255
271
|
let lastState = store.__unstableOriginalGetState();
|
|
256
272
|
store.subscribe(() => {
|
|
257
273
|
const state = store.__unstableOriginalGetState();
|
|
@@ -315,13 +331,13 @@ function instantiateReduxStore(key, options, registry, thunkArgs) {
|
|
|
315
331
|
return createStore(
|
|
316
332
|
enhancedReducer,
|
|
317
333
|
{ root: initialState },
|
|
318
|
-
compose(enhancers)
|
|
334
|
+
compose(...enhancers)
|
|
319
335
|
);
|
|
320
336
|
}
|
|
321
337
|
function mapResolveSelector(store, boundMetadataSelectors) {
|
|
322
338
|
return (selector, selectorName) => {
|
|
323
339
|
if (!selector.hasResolver) {
|
|
324
|
-
return async (...args) => selector
|
|
340
|
+
return async (...args) => selector(...args);
|
|
325
341
|
}
|
|
326
342
|
return (...args) => new Promise((resolve, reject) => {
|
|
327
343
|
const hasFinished = () => {
|
|
@@ -345,7 +361,7 @@ function mapResolveSelector(store, boundMetadataSelectors) {
|
|
|
345
361
|
resolve(result2);
|
|
346
362
|
}
|
|
347
363
|
};
|
|
348
|
-
const getResult = () => selector
|
|
364
|
+
const getResult = () => selector(...args);
|
|
349
365
|
const result = getResult();
|
|
350
366
|
if (hasFinished()) {
|
|
351
367
|
return finalize(result);
|
|
@@ -365,7 +381,7 @@ function mapSuspendSelector(store, boundMetadataSelectors) {
|
|
|
365
381
|
return selector;
|
|
366
382
|
}
|
|
367
383
|
return (...args) => {
|
|
368
|
-
const result = selector
|
|
384
|
+
const result = selector(...args);
|
|
369
385
|
if (boundMetadataSelectors.hasFinishedResolution(
|
|
370
386
|
selectorName,
|
|
371
387
|
args
|