@wordpress/core-data 6.16.0 → 6.17.1
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 +2 -0
- package/build/actions.js +69 -134
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +0 -22
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +3 -15
- package/build/batch/default-processor.js.map +1 -1
- package/build/batch/index.js +0 -3
- package/build/batch/index.js.map +1 -1
- package/build/entities.js +109 -36
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +34 -53
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/attachment.js.map +1 -1
- package/build/entity-types/base-entity-records.js +0 -3
- package/build/entity-types/base-entity-records.js.map +1 -1
- package/build/entity-types/comment.js.map +1 -1
- package/build/entity-types/helpers.js.map +1 -1
- package/build/entity-types/index.js.map +1 -1
- package/build/entity-types/menu-location.js.map +1 -1
- package/build/entity-types/nav-menu-item.js.map +1 -1
- package/build/entity-types/nav-menu.js.map +1 -1
- package/build/entity-types/page.js.map +1 -1
- package/build/entity-types/plugin.js.map +1 -1
- package/build/entity-types/post.js.map +1 -1
- package/build/entity-types/settings.js.map +1 -1
- package/build/entity-types/sidebar.js.map +1 -1
- package/build/entity-types/taxonomy.js.map +1 -1
- package/build/entity-types/theme.js.map +1 -1
- package/build/entity-types/type.js.map +1 -1
- package/build/entity-types/user.js.map +1 -1
- package/build/entity-types/widget-type.js.map +1 -1
- package/build/entity-types/widget.js.map +1 -1
- package/build/entity-types/wp-template-part.js.map +1 -1
- package/build/entity-types/wp-template.js.map +1 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +14 -20
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build/fetch/__experimental-fetch-url-data.js +4 -13
- package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build/fetch/index.js +0 -3
- package/build/fetch/index.js.map +1 -1
- package/build/hooks/constants.js +4 -5
- package/build/hooks/constants.js.map +1 -1
- package/build/hooks/index.js +0 -5
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/memoize.js +0 -3
- package/build/hooks/memoize.js.map +1 -1
- package/build/hooks/use-entity-record.js +0 -9
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +2 -9
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +1 -13
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +0 -15
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +9 -41
- package/build/index.js.map +1 -1
- package/build/locks/actions.js +1 -6
- package/build/locks/actions.js.map +1 -1
- package/build/locks/engine.js +1 -9
- package/build/locks/engine.js.map +1 -1
- package/build/locks/reducer.js +8 -9
- package/build/locks/reducer.js.map +1 -1
- package/build/locks/selectors.js +8 -11
- package/build/locks/selectors.js.map +1 -1
- package/build/locks/utils.js +4 -19
- package/build/locks/utils.js.map +1 -1
- package/build/name.js +0 -1
- package/build/name.js.map +1 -1
- package/build/private-apis.js +1 -2
- package/build/private-apis.js.map +1 -1
- package/build/private-selectors.js +2 -5
- package/build/private-selectors.js.map +1 -1
- package/build/queried-data/actions.js +4 -6
- package/build/queried-data/actions.js.map +1 -1
- package/build/queried-data/get-query-parts.js +11 -24
- package/build/queried-data/get-query-parts.js.map +1 -1
- package/build/queried-data/index.js +0 -6
- package/build/queried-data/index.js.map +1 -1
- package/build/queried-data/reducer.js +33 -51
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +4 -25
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +76 -128
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +91 -133
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +51 -145
- package/build/selectors.js.map +1 -1
- package/build/sync.js +19 -0
- package/build/sync.js.map +1 -0
- package/build/types.js.map +1 -1
- package/build/utils/conservative-map-item.js +3 -10
- package/build/utils/conservative-map-item.js.map +1 -1
- package/build/utils/forward-resolver.js +0 -2
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/get-normalized-comma-separable.js +0 -3
- package/build/utils/get-normalized-comma-separable.js.map +1 -1
- package/build/utils/if-matching-action.js +0 -3
- package/build/utils/if-matching-action.js.map +1 -1
- package/build/utils/index.js +0 -10
- package/build/utils/index.js.map +1 -1
- package/build/utils/is-raw-attribute.js +0 -1
- package/build/utils/is-raw-attribute.js.map +1 -1
- package/build/utils/on-sub-key.js +5 -9
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/replace-action.js +0 -2
- package/build/utils/replace-action.js.map +1 -1
- package/build/utils/set-nested-value.js +0 -4
- package/build/utils/set-nested-value.js.map +1 -1
- package/build/utils/with-weak-map-cache.js +3 -6
- package/build/utils/with-weak-map-cache.js.map +1 -1
- package/build-module/actions.js +72 -95
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +1 -20
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +4 -13
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/batch/index.js.map +1 -1
- package/build-module/entities.js +109 -25
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +35 -45
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/attachment.js.map +1 -1
- package/build-module/entity-types/base-entity-records.js +0 -2
- package/build-module/entity-types/base-entity-records.js.map +1 -1
- package/build-module/entity-types/comment.js.map +1 -1
- package/build-module/entity-types/helpers.js.map +1 -1
- package/build-module/entity-types/index.js.map +1 -1
- package/build-module/entity-types/menu-location.js.map +1 -1
- package/build-module/entity-types/nav-menu-item.js.map +1 -1
- package/build-module/entity-types/nav-menu.js.map +1 -1
- package/build-module/entity-types/page.js.map +1 -1
- package/build-module/entity-types/plugin.js.map +1 -1
- package/build-module/entity-types/post.js.map +1 -1
- package/build-module/entity-types/settings.js.map +1 -1
- package/build-module/entity-types/sidebar.js.map +1 -1
- package/build-module/entity-types/taxonomy.js.map +1 -1
- package/build-module/entity-types/theme.js.map +1 -1
- package/build-module/entity-types/type.js.map +1 -1
- package/build-module/entity-types/user.js.map +1 -1
- package/build-module/entity-types/widget-type.js.map +1 -1
- package/build-module/entity-types/widget.js.map +1 -1
- package/build-module/entity-types/wp-template-part.js.map +1 -1
- package/build-module/entity-types/wp-template.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +15 -15
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +5 -10
- package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
- package/build-module/fetch/index.js.map +1 -1
- package/build-module/hooks/constants.js +3 -4
- package/build-module/hooks/constants.js.map +1 -1
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/memoize.js +2 -1
- package/build-module/hooks/memoize.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +1 -3
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +2 -3
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +1 -9
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +1 -10
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +11 -19
- package/build-module/index.js.map +1 -1
- package/build-module/locks/actions.js +0 -3
- package/build-module/locks/actions.js.map +1 -1
- package/build-module/locks/engine.js +0 -5
- package/build-module/locks/engine.js.map +1 -1
- package/build-module/locks/reducer.js +7 -7
- package/build-module/locks/reducer.js.map +1 -1
- package/build-module/locks/selectors.js +7 -8
- package/build-module/locks/selectors.js.map +1 -1
- package/build-module/locks/utils.js +4 -14
- package/build-module/locks/utils.js.map +1 -1
- package/build-module/name.js.map +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/private-selectors.js +2 -2
- package/build-module/private-selectors.js.map +1 -1
- package/build-module/queried-data/actions.js +4 -3
- package/build-module/queried-data/actions.js.map +1 -1
- package/build-module/queried-data/get-query-parts.js +13 -21
- package/build-module/queried-data/get-query-parts.js.map +1 -1
- package/build-module/queried-data/index.js.map +1 -1
- package/build-module/queried-data/reducer.js +33 -42
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +6 -21
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +79 -104
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +94 -96
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +56 -92
- package/build-module/selectors.js.map +1 -1
- package/build-module/sync.js +12 -0
- package/build-module/sync.js.map +1 -0
- package/build-module/types.js.map +1 -1
- package/build-module/utils/conservative-map-item.js +4 -8
- package/build-module/utils/conservative-map-item.js.map +1 -1
- package/build-module/utils/forward-resolver.js +0 -1
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/get-normalized-comma-separable.js +0 -2
- package/build-module/utils/get-normalized-comma-separable.js.map +1 -1
- package/build-module/utils/if-matching-action.js +0 -2
- package/build-module/utils/if-matching-action.js.map +1 -1
- package/build-module/utils/index.js.map +1 -1
- package/build-module/utils/is-raw-attribute.js.map +1 -1
- package/build-module/utils/on-sub-key.js +5 -7
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/replace-action.js +0 -1
- package/build-module/utils/replace-action.js.map +1 -1
- package/build-module/utils/set-nested-value.js +0 -3
- package/build-module/utils/set-nested-value.js.map +1 -1
- package/build-module/utils/with-weak-map-cache.js +3 -5
- package/build-module/utils/with-weak-map-cache.js.map +1 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +53 -0
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-provider.d.ts +1 -1
- package/build-types/entity-provider.d.ts.map +1 -1
- package/build-types/hooks/memoize.d.ts +1 -1
- package/build-types/hooks/memoize.d.ts.map +1 -1
- package/build-types/index.d.ts +3 -3
- package/build-types/index.d.ts.map +1 -1
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/sync.d.ts +2 -0
- package/build-types/sync.d.ts.map +1 -0
- package/package.json +17 -15
- package/src/actions.js +24 -14
- package/src/entities.js +91 -0
- package/src/entity-provider.js +11 -2
- package/src/resolvers.js +89 -41
- package/src/sync.js +18 -0
- package/src/test/entity-provider.js +272 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["default","__experimentalFetchLinkSuggestions","__experimentalFetchUrlData"],"sources":["@wordpress/core-data/src/fetch/index.js"],"sourcesContent":["export { default as __experimentalFetchLinkSuggestions } from './__experimental-fetch-link-suggestions';\nexport { default as __experimentalFetchUrlData } from './__experimental-fetch-url-data';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,kCAAkC,QAAQ,yCAAyC;AACvG,SAASD,OAAO,IAAIE,0BAA0B,QAAQ,iCAAiC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
export let Status
|
|
2
|
-
|
|
3
|
-
(function (Status) {
|
|
1
|
+
export let Status = /*#__PURE__*/function (Status) {
|
|
4
2
|
Status["Idle"] = "IDLE";
|
|
5
3
|
Status["Resolving"] = "RESOLVING";
|
|
6
4
|
Status["Error"] = "ERROR";
|
|
7
5
|
Status["Success"] = "SUCCESS";
|
|
8
|
-
|
|
6
|
+
return Status;
|
|
7
|
+
}({});
|
|
9
8
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/constants.ts"],"
|
|
1
|
+
{"version":3,"names":["Status"],"sources":["@wordpress/core-data/src/hooks/constants.ts"],"sourcesContent":["export const enum Status {\n\tIdle = 'IDLE',\n\tResolving = 'RESOLVING',\n\tError = 'ERROR',\n\tSuccess = 'SUCCESS',\n}\n"],"mappings":"AAAA,WAAkBA,MAAM,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["default","useEntityRecord","__experimentalUseEntityRecord","useEntityRecords","__experimentalUseEntityRecords","useResourcePermissions","__experimentalUseResourcePermissions"],"sources":["@wordpress/core-data/src/hooks/index.ts"],"sourcesContent":["export {\n\tdefault as useEntityRecord,\n\t__experimentalUseEntityRecord,\n} from './use-entity-record';\nexport {\n\tdefault as useEntityRecords,\n\t__experimentalUseEntityRecords,\n} from './use-entity-records';\nexport {\n\tdefault as useResourcePermissions,\n\t__experimentalUseResourcePermissions,\n} from './use-resource-permissions';\n"],"mappings":"AAAA,SACCA,OAAO,IAAIC,eAAe,EAC1BC,6BAA6B,QACvB,qBAAqB;AAC5B,SACCF,OAAO,IAAIG,gBAAgB,EAC3BC,8BAA8B,QACxB,sBAAsB;AAC7B,SACCJ,OAAO,IAAIK,sBAAsB,EACjCC,oCAAoC,QAC9B,4BAA4B"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import memoize from 'memize';
|
|
4
|
+
import memoize from 'memize';
|
|
5
5
|
|
|
6
|
+
// re-export due to restrictive esModuleInterop setting
|
|
6
7
|
export default memoize;
|
|
7
8
|
//# sourceMappingURL=memoize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/memoize.js"],"
|
|
1
|
+
{"version":3,"names":["memoize"],"sources":["@wordpress/core-data/src/hooks/memoize.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport memoize from 'memize';\n\n// re-export due to restrictive esModuleInterop setting\nexport default memoize;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,QAAQ;;AAE5B;AACA,eAAeA,OAAO"}
|
|
@@ -4,13 +4,12 @@
|
|
|
4
4
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
5
5
|
import deprecated from '@wordpress/deprecated';
|
|
6
6
|
import { useMemo } from '@wordpress/element';
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* Internal dependencies
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
11
|
import useQuerySelect from './use-query-select';
|
|
12
12
|
import { store as coreStore } from '../';
|
|
13
|
-
|
|
14
13
|
/**
|
|
15
14
|
* Resolves the specified entity record.
|
|
16
15
|
*
|
|
@@ -129,7 +128,6 @@ export default function useEntityRecord(kind, name, recordId, options = {
|
|
|
129
128
|
data: null
|
|
130
129
|
};
|
|
131
130
|
}
|
|
132
|
-
|
|
133
131
|
return query(coreStore).getEntityRecord(kind, name, recordId);
|
|
134
132
|
}, [kind, name, recordId, options.enabled]);
|
|
135
133
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useDispatch","useSelect","deprecated","useMemo","useQuerySelect","store","coreStore","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,OAAOC,UAAU,MAAM,uBAAuB;AAC9C,SAASC,OAAO,QAAQ,oBAAoB;;AAE5C;AACA;AACA;AACA,OAAOC,cAAc,MAAM,oBAAoB;AAC/C,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AA4CxC;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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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OE,KAAK,CAAEtB,SAAU,CAAC,CAACuB,eAAe,CAAErB,IAAI,EAAEC,IAAI,EAAEC,QAAS,CAAC;EAClE,CAAC,EACD,CAAEF,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,CAACC,OAAO,CACxC,CAAC;EAED,OAAO;IACNK,MAAM;IACNI,YAAY;IACZC,QAAQ;IACR,GAAGK,eAAe;IAClB,GAAGZ;EACJ,CAAC;AACF;AAEA,OAAO,SAASe,6BAA6BA,CAC5CtB,IAAY,EACZC,IAAY,EACZC,QAAa,EACbC,OAAY,EACX;EACDT,UAAU,CAAG,uCAAsC,EAAE;IACpD6B,WAAW,EAAE,yBAAyB;IACtCC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAOzB,eAAe,CAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAQ,CAAC;AACxD"}
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { addQueryArgs } from '@wordpress/url';
|
|
5
5
|
import deprecated from '@wordpress/deprecated';
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Internal dependencies
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
10
|
import useQuerySelect from './use-query-select';
|
|
11
11
|
import { store as coreStore } from '../';
|
|
12
12
|
const EMPTY_ARRAY = [];
|
|
13
|
+
|
|
13
14
|
/**
|
|
14
15
|
* Resolves the specified entity records.
|
|
15
16
|
*
|
|
@@ -50,7 +51,6 @@ const EMPTY_ARRAY = [];
|
|
|
50
51
|
* @return Entity records data.
|
|
51
52
|
* @template RecordType
|
|
52
53
|
*/
|
|
53
|
-
|
|
54
54
|
export default function useEntityRecords(kind, name, queryArgs = {}, options = {
|
|
55
55
|
enabled: true
|
|
56
56
|
}) {
|
|
@@ -69,7 +69,6 @@ export default function useEntityRecords(kind, name, queryArgs = {}, options = {
|
|
|
69
69
|
data: EMPTY_ARRAY
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
|
-
|
|
73
72
|
return query(coreStore).getEntityRecords(kind, name, queryArgs);
|
|
74
73
|
}, [kind, name, queryAsString, options.enabled]);
|
|
75
74
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["addQueryArgs","deprecated","useQuerySelect","store","coreStore","EMPTY_ARRAY","useEntityRecords","kind","name","queryArgs","options","enabled","queryAsString","data","records","rest","query","getEntityRecords","__experimentalUseEntityRecords","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-records.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Options } from './use-entity-record';\nimport type { Status } from './constants';\n\ninterface EntityRecordsResolution< RecordType > {\n\t/** The requested entity record */\n\trecords: RecordType[] | null;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Resolves the specified entity records.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param queryArgs Optional HTTP query description for how to fetch the data, passed to the requested API endpoint.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecords } from '@wordpress/core-data';\n *\n * function PageTitlesList() {\n * const { records, isResolving } = useEntityRecords( 'postType', 'page' );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return (\n * <ul>\n * {records.map(( page ) => (\n * <li>{ page.title }</li>\n * ))}\n * </ul>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PageTitlesList />\n * ```\n *\n * In the above example, when `PageTitlesList` is rendered into an\n * application, the list of records and the resolution details will be retrieved from\n * the store state using `getEntityRecords()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template RecordType\n */\nexport default function useEntityRecords< RecordType >(\n\tkind: string,\n\tname: string,\n\tqueryArgs: Record< string, unknown > = {},\n\toptions: Options = { enabled: true }\n): EntityRecordsResolution< RecordType > {\n\t// Serialize queryArgs to a string that can be safely used as a React dep.\n\t// We can't just pass queryArgs as one of the deps, because if it is passed\n\t// as an object literal, then it will be a different object on each call even\n\t// if the values remain the same.\n\tconst queryAsString = addQueryArgs( '', queryArgs );\n\n\tconst { data: records, ...rest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\t// Avoiding returning a new reference on every execution.\n\t\t\t\t\tdata: EMPTY_ARRAY,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecords( kind, name, queryArgs );\n\t\t},\n\t\t[ kind, name, queryAsString, options.enabled ]\n\t);\n\n\treturn {\n\t\trecords,\n\t\t...rest,\n\t};\n}\n\nexport function __experimentalUseEntityRecords(\n\tkind: string,\n\tname: string,\n\tqueryArgs: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecords`, {\n\t\talternative: 'wp.data.useEntityRecords',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecords( kind, name, queryArgs, options );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,YAAY,QAAQ,gBAAgB;AAC7C,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,OAAOC,cAAc,MAAM,oBAAoB;AAC/C,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AAsBxC,MAAMC,WAAW,GAAG,EAAE;;AAEtB;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,eAAe,SAASC,gBAAgBA,CACvCC,IAAY,EACZC,IAAY,EACZC,SAAoC,GAAG,CAAC,CAAC,EACzCC,OAAgB,GAAG;EAAEC,OAAO,EAAE;AAAK,CAAC,EACI;EACxC;EACA;EACA;EACA;EACA,MAAMC,aAAa,GAAGZ,YAAY,CAAE,EAAE,EAAES,SAAU,CAAC;EAEnD,MAAM;IAAEI,IAAI,EAAEC,OAAO;IAAE,GAAGC;EAAK,CAAC,GAAGb,cAAc,CAC9Cc,KAAK,IAAM;IACZ,IAAK,CAAEN,OAAO,CAACC,OAAO,EAAG;MACxB,OAAO;QACN;QACAE,IAAI,EAAER;MACP,CAAC;IACF;IACA,OAAOW,KAAK,CAAEZ,SAAU,CAAC,CAACa,gBAAgB,CAAEV,IAAI,EAAEC,IAAI,EAAEC,SAAU,CAAC;EACpE,CAAC,EACD,CAAEF,IAAI,EAAEC,IAAI,EAAEI,aAAa,EAAEF,OAAO,CAACC,OAAO,CAC7C,CAAC;EAED,OAAO;IACNG,OAAO;IACP,GAAGC;EACJ,CAAC;AACF;AAEA,OAAO,SAASG,8BAA8BA,CAC7CX,IAAY,EACZC,IAAY,EACZC,SAAc,EACdC,OAAY,EACX;EACDT,UAAU,CAAG,wCAAuC,EAAE;IACrDkB,WAAW,EAAE,0BAA0B;IACvCC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAOd,gBAAgB,CAAEC,IAAI,EAAEC,IAAI,EAAEC,SAAS,EAAEC,OAAQ,CAAC;AAC1D"}
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { useSelect } from '@wordpress/data';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Internal dependencies
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import memoize from './memoize';
|
|
10
10
|
import { Status } from './constants';
|
|
11
11
|
export const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFinishedResolution', 'isResolving', 'getCachedResolvers'];
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
13
|
* Like useSelect, but the selectors return objects containing
|
|
15
14
|
* both the original data AND the resolution info.
|
|
@@ -56,11 +55,9 @@ export const META_SELECTORS = ['getIsResolving', 'hasStartedResolution', 'hasFin
|
|
|
56
55
|
export default function useQuerySelect(mapQuerySelect, deps) {
|
|
57
56
|
return useSelect((select, registry) => {
|
|
58
57
|
const resolve = store => enrichSelectors(select(store));
|
|
59
|
-
|
|
60
58
|
return mapQuerySelect(resolve, registry);
|
|
61
59
|
}, deps);
|
|
62
60
|
}
|
|
63
|
-
|
|
64
61
|
/**
|
|
65
62
|
* Transform simple selectors into ones that return an object with the
|
|
66
63
|
* original return value AND the resolution info.
|
|
@@ -70,12 +67,10 @@ export default function useQuerySelect(mapQuerySelect, deps) {
|
|
|
70
67
|
*/
|
|
71
68
|
const enrichSelectors = memoize(selectors => {
|
|
72
69
|
const resolvers = {};
|
|
73
|
-
|
|
74
70
|
for (const selectorName in selectors) {
|
|
75
71
|
if (META_SELECTORS.includes(selectorName)) {
|
|
76
72
|
continue;
|
|
77
73
|
}
|
|
78
|
-
|
|
79
74
|
Object.defineProperty(resolvers, selectorName, {
|
|
80
75
|
get: () => (...args) => {
|
|
81
76
|
const {
|
|
@@ -86,7 +81,6 @@ const enrichSelectors = memoize(selectors => {
|
|
|
86
81
|
const hasResolved = !isResolving && hasFinishedResolution(selectorName, args);
|
|
87
82
|
const data = selectors[selectorName](...args);
|
|
88
83
|
let status;
|
|
89
|
-
|
|
90
84
|
if (isResolving) {
|
|
91
85
|
status = Status.Resolving;
|
|
92
86
|
} else if (hasResolved) {
|
|
@@ -98,7 +92,6 @@ const enrichSelectors = memoize(selectors => {
|
|
|
98
92
|
} else {
|
|
99
93
|
status = Status.Idle;
|
|
100
94
|
}
|
|
101
|
-
|
|
102
95
|
return {
|
|
103
96
|
data,
|
|
104
97
|
status,
|
|
@@ -108,7 +101,6 @@ const enrichSelectors = memoize(selectors => {
|
|
|
108
101
|
}
|
|
109
102
|
});
|
|
110
103
|
}
|
|
111
|
-
|
|
112
104
|
return resolvers;
|
|
113
105
|
});
|
|
114
106
|
//# sourceMappingURL=use-query-select.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useSelect","memoize","Status","META_SELECTORS","useQuerySelect","mapQuerySelect","deps","select","registry","resolve","store","enrichSelectors","selectors","resolvers","selectorName","includes","Object","defineProperty","get","args","getIsResolving","hasFinishedResolution","isResolving","hasResolved","data","status","Resolving","Success","Error","Idle"],"sources":["@wordpress/core-data/src/hooks/use-query-select.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport memoize from './memoize';\nimport { Status } from './constants';\n\nexport const META_SELECTORS = [\n\t'getIsResolving',\n\t'hasStartedResolution',\n\t'hasFinishedResolution',\n\t'isResolving',\n\t'getCachedResolvers',\n];\n\ninterface QuerySelectResponse< Data > {\n\t/** the requested selector return value */\n\tdata: Data;\n\n\t/** is the record still being resolved? Via the `getIsResolving` meta-selector */\n\tisResolving: boolean;\n\n\t/** was the resolution started? Via the `hasStartedResolution` meta-selector */\n\thasStarted: boolean;\n\n\t/** has the resolution finished? Via the `hasFinishedResolution` meta-selector. */\n\thasResolved: boolean;\n}\n\n/**\n * Like useSelect, but the selectors return objects containing\n * both the original data AND the resolution info.\n *\n * @since 6.1.0 Introduced in WordPress core.\n * @private\n *\n * @param {Function} mapQuerySelect see useSelect\n * @param {Array} deps see useSelect\n *\n * @example\n * ```js\n * import { useQuerySelect } from '@wordpress/data';\n * import { store as coreDataStore } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { data: page, isResolving } = useQuerySelect( ( query ) => {\n * return query( coreDataStore ).getEntityRecord( 'postType', 'page', id )\n * }, [ id ] );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return page.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 10 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using the `mapSelect` callback on `useQuerySelect`.\n *\n * If the id prop changes then any page in the state for that id is\n * retrieved. If the id prop doesn't change and other props are passed in\n * that do change, the title will not change because the dependency is just\n * the id.\n * @see useSelect\n *\n * @return {QuerySelectResponse} Queried data.\n */\nexport default function useQuerySelect( mapQuerySelect, deps ) {\n\treturn useSelect( ( select, registry ) => {\n\t\tconst resolve = ( store ) => enrichSelectors( select( store ) );\n\t\treturn mapQuerySelect( resolve, registry );\n\t}, deps );\n}\n\ninterface EnrichedSelectors {\n\t< Selectors extends Record< string, ( ...args: any[] ) => any > >(\n\t\tselectors: Selectors\n\t): {\n\t\t[ Selector in keyof Selectors ]: (\n\t\t\t...args: Parameters< Selectors[ Selector ] >\n\t\t) => QuerySelectResponse< ReturnType< Selectors[ Selector ] > >;\n\t};\n}\n\n/**\n * Transform simple selectors into ones that return an object with the\n * original return value AND the resolution info.\n *\n * @param {Object} selectors Selectors to enrich\n * @return {EnrichedSelectors} Enriched selectors\n */\nconst enrichSelectors = memoize( ( ( selectors ) => {\n\tconst resolvers = {};\n\tfor ( const selectorName in selectors ) {\n\t\tif ( META_SELECTORS.includes( selectorName ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tObject.defineProperty( resolvers, selectorName, {\n\t\t\tget:\n\t\t\t\t() =>\n\t\t\t\t( ...args: unknown[] ) => {\n\t\t\t\t\tconst { getIsResolving, hasFinishedResolution } = selectors;\n\t\t\t\t\tconst isResolving = !! getIsResolving( selectorName, args );\n\t\t\t\t\tconst hasResolved =\n\t\t\t\t\t\t! isResolving &&\n\t\t\t\t\t\thasFinishedResolution( selectorName, args );\n\t\t\t\t\tconst data = selectors[ selectorName ]( ...args );\n\n\t\t\t\t\tlet status;\n\t\t\t\t\tif ( isResolving ) {\n\t\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\t\tif ( data ) {\n\t\t\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstatus = Status.Error;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\tstatus = Status.Idle;\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\tdata,\n\t\t\t\t\t\tstatus,\n\t\t\t\t\t\tisResolving,\n\t\t\t\t\t\thasResolved,\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t} );\n\t}\n\treturn resolvers;\n} ) as EnrichedSelectors );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,iBAAiB;;AAE3C;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,SAASC,MAAM,QAAQ,aAAa;AAEpC,OAAO,MAAMC,cAAc,GAAG,CAC7B,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,oBAAoB,CACpB;AAgBD;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,eAAe,SAASC,cAAcA,CAAEC,cAAc,EAAEC,IAAI,EAAG;EAC9D,OAAON,SAAS,CAAE,CAAEO,MAAM,EAAEC,QAAQ,KAAM;IACzC,MAAMC,OAAO,GAAKC,KAAK,IAAMC,eAAe,CAAEJ,MAAM,CAAEG,KAAM,CAAE,CAAC;IAC/D,OAAOL,cAAc,CAAEI,OAAO,EAAED,QAAS,CAAC;E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deprecated';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Internal dependencies
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import { store as coreStore } from '../';
|
|
10
10
|
import { Status } from './constants';
|
|
11
11
|
import useQuerySelect from './use-query-select';
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
13
|
* Resolves resource permissions.
|
|
15
14
|
*
|
|
@@ -84,19 +83,16 @@ export default function useResourcePermissions(resource, id) {
|
|
|
84
83
|
canUser
|
|
85
84
|
} = resolve(coreStore);
|
|
86
85
|
const create = canUser('create', resource);
|
|
87
|
-
|
|
88
86
|
if (!id) {
|
|
89
87
|
const read = canUser('read', resource);
|
|
90
88
|
const isResolving = create.isResolving || read.isResolving;
|
|
91
89
|
const hasResolved = create.hasResolved && read.hasResolved;
|
|
92
90
|
let status = Status.Idle;
|
|
93
|
-
|
|
94
91
|
if (isResolving) {
|
|
95
92
|
status = Status.Resolving;
|
|
96
93
|
} else if (hasResolved) {
|
|
97
94
|
status = Status.Success;
|
|
98
95
|
}
|
|
99
|
-
|
|
100
96
|
return {
|
|
101
97
|
status,
|
|
102
98
|
isResolving,
|
|
@@ -105,22 +101,17 @@ export default function useResourcePermissions(resource, id) {
|
|
|
105
101
|
canRead: read.hasResolved && read.data
|
|
106
102
|
};
|
|
107
103
|
}
|
|
108
|
-
|
|
109
104
|
const read = canUser('read', resource, id);
|
|
110
105
|
const update = canUser('update', resource, id);
|
|
111
|
-
|
|
112
106
|
const _delete = canUser('delete', resource, id);
|
|
113
|
-
|
|
114
107
|
const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
|
|
115
108
|
const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
|
|
116
109
|
let status = Status.Idle;
|
|
117
|
-
|
|
118
110
|
if (isResolving) {
|
|
119
111
|
status = Status.Resolving;
|
|
120
112
|
} else if (hasResolved) {
|
|
121
113
|
status = Status.Success;
|
|
122
114
|
}
|
|
123
|
-
|
|
124
115
|
return {
|
|
125
116
|
status,
|
|
126
117
|
isResolving,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["deprecated","store","coreStore","Status","useQuerySelect","useResourcePermissions","resource","id","resolve","canUser","create","read","isResolving","hasResolved","status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","__experimentalUseResourcePermissions","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} )\n];\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource The resource in question, e.g. media.\n * @param id ID of a specific resource entry, if needed, e.g. 10.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( 'pages' );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( 'pages', pageId );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nexport default function useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser( 'create', resource );\n\t\t\tif ( ! id ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,SAASC,KAAK,IAAIC,SAAS,QAAQ,KAAK;AACxC,SAASC,MAAM,QAAQ,aAAa;AACpC,OAAOC,cAAc,MAAM,oBAAoB;AAiC/C;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;A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O,CAACV,WAAW;IACpB,MAAMC,WAAW,GAChBF,IAAI,CAACE,WAAW,IAChBH,MAAM,CAACG,WAAW,IAClBQ,MAAM,CAACR,WAAW,IAClBS,OAAO,CAACT,WAAW;IAEpB,IAAIC,MAAM,GAAGX,MAAM,CAACY,IAAI;IACxB,IAAKH,WAAW,EAAG;MAClBE,MAAM,GAAGX,MAAM,CAACa,SAAS;IAC1B,CAAC,MAAM,IAAKH,WAAW,EAAG;MACzBC,MAAM,GAAGX,MAAM,CAACc,OAAO;IACxB;IACA,OAAO;MACNH,MAAM;MACNF,WAAW;MACXC,WAAW;MACXO,OAAO,EAAEP,WAAW,IAAIF,IAAI,CAACQ,IAAI;MACjCD,SAAS,EAAEL,WAAW,IAAIH,MAAM,CAACS,IAAI;MACrCI,SAAS,EAAEV,WAAW,IAAIQ,MAAM,CAACF,IAAI;MACrCK,SAAS,EAAEX,WAAW,IAAIS,OAAO,CAACH;IACnC,CAAC;EACF,CAAC,EACD,CAAEb,QAAQ,EAAEC,EAAE,CACf,CAAC;AACF;AAEA,OAAO,SAASkB,oCAAoCA,CACnDnB,QAAgB,EAChBC,EAAY,EACX;EACDP,UAAU,CAAG,8CAA6C,EAAE;IAC3D0B,WAAW,EAAE,gCAAgC;IAC7CC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAOtB,sBAAsB,CAAEC,QAAQ,EAAEC,EAAG,CAAC;AAC9C"}
|
package/build-module/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { createReduxStore, register } from '@wordpress/data';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Internal dependencies
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
import reducer from './reducer';
|
|
10
10
|
import * as selectors from './selectors';
|
|
11
11
|
import * as privateSelectors from './private-selectors';
|
|
@@ -14,7 +14,9 @@ import * as resolvers from './resolvers';
|
|
|
14
14
|
import createLocksActions from './locks/actions';
|
|
15
15
|
import { rootEntitiesConfig, getMethodName } from './entities';
|
|
16
16
|
import { STORE_NAME } from './name';
|
|
17
|
-
import { unlock } from './private-apis';
|
|
17
|
+
import { unlock } from './private-apis';
|
|
18
|
+
|
|
19
|
+
// The entity selectors/resolvers and actions are shortcuts to their generic equivalents
|
|
18
20
|
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
|
|
19
21
|
// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
|
|
20
22
|
// The "kind" and the "name" of the entity are combined to generate these shortcuts.
|
|
@@ -24,11 +26,8 @@ const entitySelectors = rootEntitiesConfig.reduce((result, entity) => {
|
|
|
24
26
|
kind,
|
|
25
27
|
name
|
|
26
28
|
} = entity;
|
|
27
|
-
|
|
28
29
|
result[getMethodName(kind, name)] = (state, key, query) => selectors.getEntityRecord(state, kind, name, key, query);
|
|
29
|
-
|
|
30
30
|
result[getMethodName(kind, name, 'get', true)] = (state, query) => selectors.getEntityRecords(state, kind, name, query);
|
|
31
|
-
|
|
32
31
|
return result;
|
|
33
32
|
}, {});
|
|
34
33
|
const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
|
|
@@ -36,15 +35,10 @@ const entityResolvers = rootEntitiesConfig.reduce((result, entity) => {
|
|
|
36
35
|
kind,
|
|
37
36
|
name
|
|
38
37
|
} = entity;
|
|
39
|
-
|
|
40
38
|
result[getMethodName(kind, name)] = (key, query) => resolvers.getEntityRecord(kind, name, key, query);
|
|
41
|
-
|
|
42
39
|
const pluralMethodName = getMethodName(kind, name, 'get', true);
|
|
43
|
-
|
|
44
40
|
result[pluralMethodName] = (...args) => resolvers.getEntityRecords(kind, name, ...args);
|
|
45
|
-
|
|
46
41
|
result[pluralMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
|
|
47
|
-
|
|
48
42
|
return result;
|
|
49
43
|
}, {});
|
|
50
44
|
const entityActions = rootEntitiesConfig.reduce((result, entity) => {
|
|
@@ -52,34 +46,32 @@ const entityActions = rootEntitiesConfig.reduce((result, entity) => {
|
|
|
52
46
|
kind,
|
|
53
47
|
name
|
|
54
48
|
} = entity;
|
|
55
|
-
|
|
56
49
|
result[getMethodName(kind, name, 'save')] = key => actions.saveEntityRecord(kind, name, key);
|
|
57
|
-
|
|
58
50
|
result[getMethodName(kind, name, 'delete')] = (key, query) => actions.deleteEntityRecord(kind, name, key, query);
|
|
59
|
-
|
|
60
51
|
return result;
|
|
61
52
|
}, {});
|
|
62
|
-
|
|
63
53
|
const storeConfig = () => ({
|
|
64
54
|
reducer,
|
|
65
|
-
actions: {
|
|
55
|
+
actions: {
|
|
56
|
+
...actions,
|
|
66
57
|
...entityActions,
|
|
67
58
|
...createLocksActions()
|
|
68
59
|
},
|
|
69
|
-
selectors: {
|
|
60
|
+
selectors: {
|
|
61
|
+
...selectors,
|
|
70
62
|
...entitySelectors
|
|
71
63
|
},
|
|
72
|
-
resolvers: {
|
|
64
|
+
resolvers: {
|
|
65
|
+
...resolvers,
|
|
73
66
|
...entityResolvers
|
|
74
67
|
}
|
|
75
68
|
});
|
|
69
|
+
|
|
76
70
|
/**
|
|
77
71
|
* Store definition for the code data namespace.
|
|
78
72
|
*
|
|
79
73
|
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
80
74
|
*/
|
|
81
|
-
|
|
82
|
-
|
|
83
75
|
export const store = createReduxStore(STORE_NAME, storeConfig());
|
|
84
76
|
unlock(store).registerPrivateSelectors(privateSelectors);
|
|
85
77
|
register(store); // Register store after unlocking private selectors to allow resolvers to use them.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createReduxStore","register","reducer","selectors","privateSelectors","actions","resolvers","createLocksActions","rootEntitiesConfig","getMethodName","STORE_NAME","unlock","entitySelectors","reduce","result","entity","kind","name","state","key","query","getEntityRecord","getEntityRecords","entityResolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","saveEntityRecord","deleteEntityRecord","storeConfig","store","registerPrivateSelectors","default","EntityProvider"],"sources":["@wordpress/core-data/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as privateSelectors from './private-selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './private-apis';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\nunlock( store ).registerPrivateSelectors( privateSelectors );\nregister( store ); // Register store after unlocking private selectors to allow resolvers to use them.\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,gBAAgB,EAAEC,QAAQ,QAAQ,iBAAiB;;AAE5D;AACA;AACA;AACA,OAAOC,OAAO,MAAM,WAAW;AAC/B,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,gBAAgB,MAAM,qBAAqB;AACvD,OAAO,KAAKC,OAAO,MAAM,WAAW;AACpC,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAOC,kBAAkB,MAAM,iBAAiB;AAChD,SAASC,kBAAkB,EAAEC,aAAa,QAAQ,YAAY;AAC9D,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAASC,MAAM,QAAQ,gBAAgB;;AAEvC;AACA;AACA;AACA;;AAEA,MAAMC,eAAe,GAAGJ,kBAAkB,CAACK,MAAM,CAAE,CAAEC,MAAM,EAAEC,MAAM,KAAM;EACxE,MAAM;IAAEC,IAAI;IAAEC;EAAK,CAAC,GAAGF,MAAM;EAC7BD,MAAM,CAAEL,aAAa,CAAEO,IAAI,EAAEC,IAAK,CAAC,CAAE,GAAG,CAAEC,KAAK,EAAEC,GAAG,EAA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const locks = createLocks();
|
|
7
|
-
|
|
8
7
|
function __unstableAcquireStoreLock(store, path, {
|
|
9
8
|
exclusive
|
|
10
9
|
}) {
|
|
11
10
|
return () => locks.acquire(store, path, exclusive);
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
function __unstableReleaseStoreLock(lock) {
|
|
15
13
|
return () => locks.release(lock);
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
return {
|
|
19
16
|
__unstableAcquireStoreLock,
|
|
20
17
|
__unstableReleaseStoreLock
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createLocks","createLocksActions","locks","__unstableAcquireStoreLock","store","path","exclusive","acquire","__unstableReleaseStoreLock","lock","release"],"sources":["@wordpress/core-data/src/locks/actions.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport createLocks from './engine';\n\nexport default function createLocksActions() {\n\tconst locks = createLocks();\n\n\tfunction __unstableAcquireStoreLock( store, path, { exclusive } ) {\n\t\treturn () => locks.acquire( store, path, exclusive );\n\t}\n\n\tfunction __unstableReleaseStoreLock( lock ) {\n\t\treturn () => locks.release( lock );\n\t}\n\n\treturn { __unstableAcquireStoreLock, __unstableReleaseStoreLock };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,UAAU;AAElC,eAAe,SAASC,kBAAkBA,CAAA,EAAG;EAC5C,MAAMC,KAAK,GAAGF,WAAW,CAAC,CAAC;EAE3B,SAASG,0BAA0BA,CAAEC,KAAK,EAAEC,IAAI,EAAE;IAAEC;EAAU,CAAC,EAAG;IACjE,OAAO,MAAMJ,KAAK,CAACK,OAAO,CAAEH,KAAK,EAAEC,IAAI,EAAEC,SAAU,CAAC;EACrD;EAEA,SAASE,0BAA0BA,CAAEC,IAAI,EAAG;IAC3C,OAAO,MAAMP,KAAK,CAACQ,OAAO,CAAED,IAAK,CAAC;EACnC;EAEA,OAAO;IAAEN,0BAA0B;IAAEK;EAA2B,CAAC;AAClE"}
|
|
@@ -7,7 +7,6 @@ export default function createLocks() {
|
|
|
7
7
|
let state = reducer(undefined, {
|
|
8
8
|
type: '@@INIT'
|
|
9
9
|
});
|
|
10
|
-
|
|
11
10
|
function processPendingLockRequests() {
|
|
12
11
|
for (const request of getPendingLockRequests(state)) {
|
|
13
12
|
const {
|
|
@@ -16,7 +15,6 @@ export default function createLocks() {
|
|
|
16
15
|
exclusive,
|
|
17
16
|
notifyAcquired
|
|
18
17
|
} = request;
|
|
19
|
-
|
|
20
18
|
if (isLockAvailable(state, store, path, {
|
|
21
19
|
exclusive
|
|
22
20
|
})) {
|
|
@@ -34,7 +32,6 @@ export default function createLocks() {
|
|
|
34
32
|
}
|
|
35
33
|
}
|
|
36
34
|
}
|
|
37
|
-
|
|
38
35
|
function acquire(store, path, exclusive) {
|
|
39
36
|
return new Promise(resolve => {
|
|
40
37
|
state = reducer(state, {
|
|
@@ -49,7 +46,6 @@ export default function createLocks() {
|
|
|
49
46
|
processPendingLockRequests();
|
|
50
47
|
});
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
function release(lock) {
|
|
54
50
|
state = reducer(state, {
|
|
55
51
|
type: 'RELEASE_LOCK',
|
|
@@ -57,7 +53,6 @@ export default function createLocks() {
|
|
|
57
53
|
});
|
|
58
54
|
processPendingLockRequests();
|
|
59
55
|
}
|
|
60
|
-
|
|
61
56
|
return {
|
|
62
57
|
acquire,
|
|
63
58
|
release
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["reducer","isLockAvailable","getPendingLockRequests","createLocks","state","undefined","type","processPendingLockRequests","request","store","path","exclusive","notifyAcquired","lock","acquire","Promise","resolve","release"],"sources":["@wordpress/core-data/src/locks/engine.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport { isLockAvailable, getPendingLockRequests } from './selectors';\n\nexport default function createLocks() {\n\tlet state = reducer( undefined, { type: '@@INIT' } );\n\n\tfunction processPendingLockRequests() {\n\t\tfor ( const request of getPendingLockRequests( state ) ) {\n\t\t\tconst { store, path, exclusive, notifyAcquired } = request;\n\t\t\tif ( isLockAvailable( state, store, path, { exclusive } ) ) {\n\t\t\t\tconst lock = { store, path, exclusive };\n\t\t\t\tstate = reducer( state, {\n\t\t\t\t\ttype: 'GRANT_LOCK_REQUEST',\n\t\t\t\t\tlock,\n\t\t\t\t\trequest,\n\t\t\t\t} );\n\t\t\t\tnotifyAcquired( lock );\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction acquire( store, path, exclusive ) {\n\t\treturn new Promise( ( resolve ) => {\n\t\t\tstate = reducer( state, {\n\t\t\t\ttype: 'ENQUEUE_LOCK_REQUEST',\n\t\t\t\trequest: { store, path, exclusive, notifyAcquired: resolve },\n\t\t\t} );\n\t\t\tprocessPendingLockRequests();\n\t\t} );\n\t}\n\tfunction release( lock ) {\n\t\tstate = reducer( state, {\n\t\t\ttype: 'RELEASE_LOCK',\n\t\t\tlock,\n\t\t} );\n\t\tprocessPendingLockRequests();\n\t}\n\n\treturn { acquire, release };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,OAAO,MAAM,WAAW;AAC/B,SAASC,eAAe,EAAEC,sBAAsB,QAAQ,aAAa;AAErE,eAAe,SAASC,WAAWA,CAAA,EAAG;EACrC,IAAIC,KAAK,GAAGJ,OAAO,CAAEK,SAAS,EAAE;IAAEC,IAAI,EAAE;EAAS,CAAE,CAAC;EAEpD,SAASC,0BAA0BA,CAAA,EAAG;IACrC,KAAM,MAAMC,OAAO,IAAIN,sBAAsB,CAAEE,KAAM,CAAC,EAAG;MACxD,MAAM;QAAEK,KAAK;QAAEC,IAAI;QAAEC,SAAS;QAAEC;MAAe,CAAC,GAAGJ,OAAO;MAC1D,IAAKP,eAAe,CAAEG,KAAK,EAAEK,KAAK,EAAEC,IAAI,EAAE;QAAEC;MAAU,CAAE,CAAC,EAAG;QAC3D,MAAME,IAAI,GAAG;UAAEJ,KAAK;U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