@wordpress/core-data 7.32.0 → 7.32.1-next.ff1cebbba.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/build/actions.js +375 -632
- package/build/actions.js.map +7 -1
- package/build/batch/create-batch.js +49 -62
- package/build/batch/create-batch.js.map +7 -1
- package/build/batch/default-processor.js +43 -39
- package/build/batch/default-processor.js.map +7 -1
- package/build/batch/index.js +38 -17
- package/build/batch/index.js.map +7 -1
- package/build/dynamic-entities.js +30 -32
- package/build/dynamic-entities.js.map +7 -1
- package/build/entities.js +298 -410
- package/build/entities.js.map +7 -1
- package/build/entity-context.js +29 -12
- package/build/entity-context.js.map +7 -1
- package/build/entity-provider.js +38 -46
- package/build/entity-provider.js.map +7 -1
- package/build/entity-types/attachment.js +16 -5
- package/build/entity-types/attachment.js.map +7 -1
- package/build/entity-types/base-entity-records.js +16 -42
- package/build/entity-types/base-entity-records.js.map +7 -1
- package/build/entity-types/base.js +16 -5
- package/build/entity-types/base.js.map +7 -1
- package/build/entity-types/comment.js +16 -5
- package/build/entity-types/comment.js.map +7 -1
- package/build/entity-types/global-styles-revision.js +16 -5
- package/build/entity-types/global-styles-revision.js.map +7 -1
- package/build/entity-types/helpers.js +16 -5
- package/build/entity-types/helpers.js.map +7 -1
- package/build/entity-types/index.js +16 -5
- package/build/entity-types/index.js.map +7 -1
- package/build/entity-types/menu-location.js +16 -5
- package/build/entity-types/menu-location.js.map +7 -1
- package/build/entity-types/nav-menu-item.js +16 -5
- package/build/entity-types/nav-menu-item.js.map +7 -1
- package/build/entity-types/nav-menu.js +16 -5
- package/build/entity-types/nav-menu.js.map +7 -1
- package/build/entity-types/page.js +16 -5
- package/build/entity-types/page.js.map +7 -1
- package/build/entity-types/plugin.js +16 -5
- package/build/entity-types/plugin.js.map +7 -1
- package/build/entity-types/post-revision.js +16 -5
- package/build/entity-types/post-revision.js.map +7 -1
- package/build/entity-types/post-status.js +16 -5
- package/build/entity-types/post-status.js.map +7 -1
- package/build/entity-types/post.js +16 -5
- package/build/entity-types/post.js.map +7 -1
- package/build/entity-types/settings.js +16 -5
- package/build/entity-types/settings.js.map +7 -1
- package/build/entity-types/sidebar.js +16 -5
- package/build/entity-types/sidebar.js.map +7 -1
- package/build/entity-types/taxonomy.js +16 -5
- package/build/entity-types/taxonomy.js.map +7 -1
- package/build/entity-types/term.js +16 -5
- package/build/entity-types/term.js.map +7 -1
- package/build/entity-types/theme.js +16 -5
- package/build/entity-types/theme.js.map +7 -1
- package/build/entity-types/type.js +16 -5
- package/build/entity-types/type.js.map +7 -1
- package/build/entity-types/user.js +16 -5
- package/build/entity-types/user.js.map +7 -1
- package/build/entity-types/widget-type.js +16 -5
- package/build/entity-types/widget-type.js.map +7 -1
- package/build/entity-types/widget.js +16 -5
- package/build/entity-types/widget.js.map +7 -1
- package/build/entity-types/wp-template-part.js +16 -5
- package/build/entity-types/wp-template-part.js.map +7 -1
- package/build/entity-types/wp-template.js +16 -5
- package/build/entity-types/wp-template.js.map +7 -1
- package/build/fetch/__experimental-fetch-link-suggestions.js +141 -154
- package/build/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
- package/build/fetch/__experimental-fetch-url-data.js +47 -59
- package/build/fetch/__experimental-fetch-url-data.js.map +7 -1
- package/build/fetch/index.js +53 -32
- package/build/fetch/index.js.map +7 -1
- package/build/footnotes/get-footnotes-order.js +38 -25
- package/build/footnotes/get-footnotes-order.js.map +7 -1
- package/build/footnotes/get-rich-text-values-cached.js +26 -27
- package/build/footnotes/get-rich-text-values-cached.js.map +7 -1
- package/build/footnotes/index.js +68 -55
- package/build/footnotes/index.js.map +7 -1
- package/build/hooks/constants.js +33 -12
- package/build/hooks/constants.js.map +7 -1
- package/build/hooks/index.js +59 -68
- package/build/hooks/index.js.map +7 -1
- package/build/hooks/memoize.js +34 -12
- package/build/hooks/memoize.js.map +7 -1
- package/build/hooks/use-entity-block-editor.js +111 -119
- package/build/hooks/use-entity-block-editor.js.map +7 -1
- package/build/hooks/use-entity-id.js +25 -23
- package/build/hooks/use-entity-id.js.map +7 -1
- package/build/hooks/use-entity-prop.js +59 -60
- package/build/hooks/use-entity-prop.js.map +7 -1
- package/build/hooks/use-entity-record.js +95 -155
- package/build/hooks/use-entity-record.js.map +7 -1
- package/build/hooks/use-entity-records.js +131 -139
- package/build/hooks/use-entity-records.js.map +7 -1
- package/build/hooks/use-query-select.js +65 -84
- package/build/hooks/use-query-select.js.map +7 -1
- package/build/hooks/use-resource-permissions.js +92 -145
- package/build/hooks/use-resource-permissions.js.map +7 -1
- package/build/index.js +96 -153
- package/build/index.js.map +7 -1
- package/build/lock-unlock.js +31 -14
- package/build/lock-unlock.js.map +7 -1
- package/build/locks/actions.js +36 -19
- package/build/locks/actions.js.map +7 -1
- package/build/locks/engine.js +48 -47
- package/build/locks/engine.js.map +7 -1
- package/build/locks/reducer.js +54 -63
- package/build/locks/reducer.js.map +7 -1
- package/build/locks/selectors.js +35 -30
- package/build/locks/selectors.js.map +7 -1
- package/build/locks/utils.js +37 -16
- package/build/locks/utils.js.map +7 -1
- package/build/name.js +27 -12
- package/build/name.js.map +7 -1
- package/build/private-actions.js +67 -75
- package/build/private-actions.js.map +7 -1
- package/build/private-apis.js +33 -16
- package/build/private-apis.js.map +7 -1
- package/build/private-selectors.js +204 -184
- package/build/private-selectors.js.map +7 -1
- package/build/queried-data/actions.js +32 -41
- package/build/queried-data/actions.js.map +7 -1
- package/build/queried-data/get-query-parts.js +41 -79
- package/build/queried-data/get-query-parts.js.map +7 -1
- package/build/queried-data/index.js +39 -36
- package/build/queried-data/index.js.map +7 -1
- package/build/queried-data/reducer.js +162 -193
- package/build/queried-data/reducer.js.map +7 -1
- package/build/queried-data/selectors.js +57 -85
- package/build/queried-data/selectors.js.map +7 -1
- package/build/reducer.js +279 -404
- package/build/reducer.js.map +7 -1
- package/build/resolvers.js +553 -600
- package/build/resolvers.js.map +7 -1
- package/build/selectors.js +456 -981
- package/build/selectors.js.map +7 -1
- package/build/sync.js +34 -22
- package/build/sync.js.map +7 -1
- package/build/types.js +16 -5
- package/build/types.js.map +7 -1
- package/build/utils/conservative-map-item.js +34 -27
- package/build/utils/conservative-map-item.js.map +7 -1
- package/build/utils/crdt-blocks.js +289 -0
- package/build/utils/crdt-blocks.js.map +7 -0
- package/build/utils/crdt.js +202 -0
- package/build/utils/crdt.js.map +7 -0
- package/build/utils/forward-resolver.js +24 -16
- package/build/utils/forward-resolver.js.map +7 -1
- package/build/utils/get-nested-value.js +26 -21
- package/build/utils/get-nested-value.js.map +7 -1
- package/build/utils/get-normalized-comma-separable.js +25 -17
- package/build/utils/get-normalized-comma-separable.js.map +7 -1
- package/build/utils/if-matching-action.js +25 -19
- package/build/utils/if-matching-action.js.map +7 -1
- package/build/utils/index.js +77 -108
- package/build/utils/index.js.map +7 -1
- package/build/utils/is-numeric-id.js +22 -12
- package/build/utils/is-numeric-id.js.map +7 -1
- package/build/utils/is-raw-attribute.js +22 -13
- package/build/utils/is-raw-attribute.js.map +7 -1
- package/build/utils/log-entity-deprecation.js +37 -38
- package/build/utils/log-entity-deprecation.js.map +7 -1
- package/build/utils/on-sub-key.js +30 -24
- package/build/utils/on-sub-key.js.map +7 -1
- package/build/utils/receive-intermediate-results.js +29 -6
- package/build/utils/receive-intermediate-results.js.map +7 -1
- package/build/utils/replace-action.js +24 -17
- package/build/utils/replace-action.js.map +7 -1
- package/build/utils/set-nested-value.js +25 -30
- package/build/utils/set-nested-value.js.map +7 -1
- package/build/utils/user-permissions.js +41 -13
- package/build/utils/user-permissions.js.map +7 -1
- package/build/utils/with-weak-map-cache.js +26 -22
- package/build/utils/with-weak-map-cache.js.map +7 -1
- package/build-module/actions.js +322 -601
- package/build-module/actions.js.map +7 -1
- package/build-module/batch/create-batch.js +21 -57
- package/build-module/batch/create-batch.js.map +7 -1
- package/build-module/batch/default-processor.js +14 -33
- package/build-module/batch/default-processor.js.map +7 -1
- package/build-module/batch/index.js +7 -3
- package/build-module/batch/index.js.map +7 -1
- package/build-module/dynamic-entities.js +7 -28
- package/build-module/dynamic-entities.js.map +7 -1
- package/build-module/entities.js +263 -399
- package/build-module/entities.js.map +7 -1
- package/build-module/entity-context.js +7 -7
- package/build-module/entity-context.js.map +7 -1
- package/build-module/entity-provider.js +19 -42
- package/build-module/entity-provider.js.map +7 -1
- package/build-module/entity-types/attachment.js +1 -2
- package/build-module/entity-types/attachment.js.map +7 -1
- package/build-module/entity-types/base-entity-records.js +1 -37
- package/build-module/entity-types/base-entity-records.js.map +7 -1
- package/build-module/entity-types/base.js +1 -2
- package/build-module/entity-types/base.js.map +7 -1
- package/build-module/entity-types/comment.js +1 -2
- package/build-module/entity-types/comment.js.map +7 -1
- package/build-module/entity-types/global-styles-revision.js +1 -2
- package/build-module/entity-types/global-styles-revision.js.map +7 -1
- package/build-module/entity-types/helpers.js +1 -2
- package/build-module/entity-types/helpers.js.map +7 -1
- package/build-module/entity-types/index.js +1 -2
- package/build-module/entity-types/index.js.map +7 -1
- package/build-module/entity-types/menu-location.js +1 -2
- package/build-module/entity-types/menu-location.js.map +7 -1
- package/build-module/entity-types/nav-menu-item.js +1 -2
- package/build-module/entity-types/nav-menu-item.js.map +7 -1
- package/build-module/entity-types/nav-menu.js +1 -2
- package/build-module/entity-types/nav-menu.js.map +7 -1
- package/build-module/entity-types/page.js +1 -2
- package/build-module/entity-types/page.js.map +7 -1
- package/build-module/entity-types/plugin.js +1 -2
- package/build-module/entity-types/plugin.js.map +7 -1
- package/build-module/entity-types/post-revision.js +1 -2
- package/build-module/entity-types/post-revision.js.map +7 -1
- package/build-module/entity-types/post-status.js +1 -2
- package/build-module/entity-types/post-status.js.map +7 -1
- package/build-module/entity-types/post.js +1 -2
- package/build-module/entity-types/post.js.map +7 -1
- package/build-module/entity-types/settings.js +1 -2
- package/build-module/entity-types/settings.js.map +7 -1
- package/build-module/entity-types/sidebar.js +1 -2
- package/build-module/entity-types/sidebar.js.map +7 -1
- package/build-module/entity-types/taxonomy.js +1 -2
- package/build-module/entity-types/taxonomy.js.map +7 -1
- package/build-module/entity-types/term.js +1 -2
- package/build-module/entity-types/term.js.map +7 -1
- package/build-module/entity-types/theme.js +1 -2
- package/build-module/entity-types/theme.js.map +7 -1
- package/build-module/entity-types/type.js +1 -2
- package/build-module/entity-types/type.js.map +7 -1
- package/build-module/entity-types/user.js +1 -2
- package/build-module/entity-types/user.js.map +7 -1
- package/build-module/entity-types/widget-type.js +1 -2
- package/build-module/entity-types/widget-type.js.map +7 -1
- package/build-module/entity-types/widget.js +1 -2
- package/build-module/entity-types/widget.js.map +7 -1
- package/build-module/entity-types/wp-template-part.js +1 -2
- package/build-module/entity-types/wp-template-part.js.map +7 -1
- package/build-module/entity-types/wp-template.js +1 -2
- package/build-module/entity-types/wp-template.js.map +7 -1
- package/build-module/fetch/__experimental-fetch-link-suggestions.js +111 -149
- package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +7 -1
- package/build-module/fetch/__experimental-fetch-url-data.js +20 -49
- package/build-module/fetch/__experimental-fetch-url-data.js.map +7 -1
- package/build-module/fetch/index.js +20 -15
- package/build-module/fetch/index.js.map +7 -1
- package/build-module/footnotes/get-footnotes-order.js +10 -19
- package/build-module/footnotes/get-footnotes-order.js.map +7 -1
- package/build-module/footnotes/get-rich-text-values-cached.js +8 -23
- package/build-module/footnotes/get-rich-text-values-cached.js.map +7 -1
- package/build-module/footnotes/index.js +34 -47
- package/build-module/footnotes/index.js.map +7 -1
- package/build-module/hooks/constants.js +11 -8
- package/build-module/hooks/constants.js.map +7 -1
- package/build-module/hooks/index.js +27 -15
- package/build-module/hooks/index.js.map +7 -1
- package/build-module/hooks/memoize.js +6 -8
- package/build-module/hooks/memoize.js.map +7 -1
- package/build-module/hooks/use-entity-block-editor.js +80 -110
- package/build-module/hooks/use-entity-block-editor.js.map +7 -1
- package/build-module/hooks/use-entity-id.js +7 -19
- package/build-module/hooks/use-entity-id.js.map +7 -1
- package/build-module/hooks/use-entity-prop.js +31 -55
- package/build-module/hooks/use-entity-prop.js.map +7 -1
- package/build-module/hooks/use-entity-record.js +63 -148
- package/build-module/hooks/use-entity-record.js.map +7 -1
- package/build-module/hooks/use-entity-records.js +98 -131
- package/build-module/hooks/use-entity-records.js.map +7 -1
- package/build-module/hooks/use-query-select.js +27 -71
- package/build-module/hooks/use-query-select.js.map +7 -1
- package/build-module/hooks/use-resource-permissions.js +57 -136
- package/build-module/hooks/use-resource-permissions.js.map +7 -1
- package/build-module/index.js +49 -71
- package/build-module/index.js.map +7 -1
- package/build-module/lock-unlock.js +8 -7
- package/build-module/lock-unlock.js.map +7 -1
- package/build-module/locks/actions.js +8 -13
- package/build-module/locks/actions.js.map +7 -1
- package/build-module/locks/engine.js +17 -38
- package/build-module/locks/engine.js.map +7 -1
- package/build-module/locks/reducer.js +37 -59
- package/build-module/locks/reducer.js.map +7 -1
- package/build-module/locks/selectors.js +16 -23
- package/build-module/locks/selectors.js.map +7 -1
- package/build-module/locks/utils.js +15 -12
- package/build-module/locks/utils.js.map +7 -1
- package/build-module/name.js +5 -8
- package/build-module/name.js.map +7 -1
- package/build-module/private-actions.js +35 -69
- package/build-module/private-actions.js.map +7 -1
- package/build-module/private-apis.js +8 -8
- package/build-module/private-apis.js.map +7 -1
- package/build-module/private-selectors.js +167 -174
- package/build-module/private-selectors.js.map +7 -1
- package/build-module/queried-data/actions.js +11 -38
- package/build-module/queried-data/actions.js.map +7 -1
- package/build-module/queried-data/get-query-parts.js +20 -75
- package/build-module/queried-data/get-query-parts.js.map +7 -1
- package/build-module/queried-data/index.js +7 -4
- package/build-module/queried-data/index.js.map +7 -1
- package/build-module/queried-data/reducer.js +134 -185
- package/build-module/queried-data/reducer.js.map +7 -1
- package/build-module/queried-data/selectors.js +23 -78
- package/build-module/queried-data/selectors.js.map +7 -1
- package/build-module/reducer.js +243 -393
- package/build-module/reducer.js.map +7 -1
- package/build-module/resolvers.js +478 -549
- package/build-module/resolvers.js.map +7 -1
- package/build-module/selectors.js +410 -953
- package/build-module/selectors.js.map +7 -1
- package/build-module/sync.js +14 -17
- package/build-module/sync.js.map +7 -1
- package/build-module/types.js +1 -2
- package/build-module/types.js.map +7 -1
- package/build-module/utils/conservative-map-item.js +6 -22
- package/build-module/utils/conservative-map-item.js.map +7 -1
- package/build-module/utils/crdt-blocks.js +255 -0
- package/build-module/utils/crdt-blocks.js.map +7 -0
- package/build-module/utils/crdt.js +167 -0
- package/build-module/utils/crdt.js.map +7 -0
- package/build-module/utils/forward-resolver.js +6 -12
- package/build-module/utils/forward-resolver.js.map +7 -1
- package/build-module/utils/get-nested-value.js +9 -18
- package/build-module/utils/get-nested-value.js.map +7 -1
- package/build-module/utils/get-normalized-comma-separable.js +7 -13
- package/build-module/utils/get-normalized-comma-separable.js.map +7 -1
- package/build-module/utils/if-matching-action.js +7 -15
- package/build-module/utils/if-matching-action.js.map +7 -1
- package/build-module/utils/index.js +35 -14
- package/build-module/utils/index.js.map +7 -1
- package/build-module/utils/is-numeric-id.js +5 -9
- package/build-module/utils/is-numeric-id.js.map +7 -1
- package/build-module/utils/is-raw-attribute.js +5 -10
- package/build-module/utils/is-raw-attribute.js.map +7 -1
- package/build-module/utils/log-entity-deprecation.js +8 -31
- package/build-module/utils/log-entity-deprecation.js.map +7 -1
- package/build-module/utils/on-sub-key.js +8 -19
- package/build-module/utils/on-sub-key.js.map +7 -1
- package/build-module/utils/receive-intermediate-results.js +7 -2
- package/build-module/utils/receive-intermediate-results.js.map +7 -1
- package/build-module/utils/replace-action.js +6 -13
- package/build-module/utils/replace-action.js.map +7 -1
- package/build-module/utils/set-nested-value.js +8 -27
- package/build-module/utils/set-nested-value.js.map +7 -1
- package/build-module/utils/user-permissions.js +19 -9
- package/build-module/utils/user-permissions.js.map +7 -1
- package/build-module/utils/with-weak-map-cache.js +8 -18
- package/build-module/utils/with-weak-map-cache.js.map +7 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +0 -56
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/index.d.ts.map +1 -1
- package/build-types/private-selectors.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +3 -0
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts.map +1 -1
- package/build-types/sync.d.ts +6 -1
- package/build-types/sync.d.ts.map +1 -1
- package/build-types/types.d.ts +9 -0
- package/build-types/types.d.ts.map +1 -1
- package/build-types/utils/crdt-blocks.d.ts +30 -0
- package/build-types/utils/crdt-blocks.d.ts.map +1 -0
- package/build-types/utils/crdt.d.ts +49 -0
- package/build-types/utils/crdt.d.ts.map +1 -0
- package/package.json +26 -19
- package/src/actions.js +56 -74
- package/src/entities.js +59 -113
- package/src/private-selectors.ts +32 -7
- package/src/resolvers.js +173 -120
- package/src/selectors.ts +0 -13
- package/src/sync.ts +12 -0
- package/src/test/resolvers.js +183 -0
- package/src/types.ts +12 -0
- package/src/utils/crdt-blocks.ts +503 -0
- package/src/utils/crdt.ts +310 -0
- package/src/utils/test/crdt-blocks.ts +375 -0
- package/src/utils/test/crdt.ts +254 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/sync.js +0 -27
|
@@ -1,113 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Internal dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { store as coreStore } from '../';
|
|
11
|
-
import { Status } from './constants';
|
|
12
|
-
import useQuerySelect from './use-query-select';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Is the data resolved by now?
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Resolves resource permissions.
|
|
20
|
-
*
|
|
21
|
-
* @since 6.1.0 Introduced in WordPress core.
|
|
22
|
-
*
|
|
23
|
-
* @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`
|
|
24
|
-
* or REST base as a string - `media`.
|
|
25
|
-
* @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged
|
|
26
|
-
* when using an entity object as a resource to check permissions and will be ignored.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```js
|
|
30
|
-
* import { useResourcePermissions } from '@wordpress/core-data';
|
|
31
|
-
*
|
|
32
|
-
* function PagesList() {
|
|
33
|
-
* const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );
|
|
34
|
-
*
|
|
35
|
-
* if ( isResolving ) {
|
|
36
|
-
* return 'Loading ...';
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
|
-
* return (
|
|
40
|
-
* <div>
|
|
41
|
-
* {canCreate ? (<button>+ Create a new page</button>) : false}
|
|
42
|
-
* // ...
|
|
43
|
-
* </div>
|
|
44
|
-
* );
|
|
45
|
-
* }
|
|
46
|
-
*
|
|
47
|
-
* // Rendered in the application:
|
|
48
|
-
* // <PagesList />
|
|
49
|
-
* ```
|
|
50
|
-
*
|
|
51
|
-
* @example
|
|
52
|
-
* ```js
|
|
53
|
-
* import { useResourcePermissions } from '@wordpress/core-data';
|
|
54
|
-
*
|
|
55
|
-
* function Page({ pageId }) {
|
|
56
|
-
* const {
|
|
57
|
-
* canCreate,
|
|
58
|
-
* canUpdate,
|
|
59
|
-
* canDelete,
|
|
60
|
-
* isResolving
|
|
61
|
-
* } = useResourcePermissions( { kind: 'postType', name: 'page', id: pageId } );
|
|
62
|
-
*
|
|
63
|
-
* if ( isResolving ) {
|
|
64
|
-
* return 'Loading ...';
|
|
65
|
-
* }
|
|
66
|
-
*
|
|
67
|
-
* return (
|
|
68
|
-
* <div>
|
|
69
|
-
* {canCreate ? (<button>+ Create a new page</button>) : false}
|
|
70
|
-
* {canUpdate ? (<button>Edit page</button>) : false}
|
|
71
|
-
* {canDelete ? (<button>Delete page</button>) : false}
|
|
72
|
-
* // ...
|
|
73
|
-
* </div>
|
|
74
|
-
* );
|
|
75
|
-
* }
|
|
76
|
-
*
|
|
77
|
-
* // Rendered in the application:
|
|
78
|
-
* // <Page pageId={ 15 } />
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* In the above example, when `PagesList` is rendered into an
|
|
82
|
-
* application, the appropriate permissions and the resolution details will be retrieved from
|
|
83
|
-
* the store state using `canUser()`, or resolved if missing.
|
|
84
|
-
*
|
|
85
|
-
* @return Entity records data.
|
|
86
|
-
* @template IdType
|
|
87
|
-
*/
|
|
1
|
+
import deprecated from "@wordpress/deprecated";
|
|
2
|
+
import warning from "@wordpress/warning";
|
|
3
|
+
import { store as coreStore } from "../";
|
|
4
|
+
import { Status } from "./constants";
|
|
5
|
+
import useQuerySelect from "./use-query-select";
|
|
88
6
|
function useResourcePermissions(resource, id) {
|
|
89
|
-
|
|
90
|
-
// We can't just pass `resource` as one of the deps, because if it is passed
|
|
91
|
-
// as an object literal, then it will be a different object on each call even
|
|
92
|
-
// if the values remain the same.
|
|
93
|
-
const isEntity = typeof resource === 'object';
|
|
7
|
+
const isEntity = typeof resource === "object";
|
|
94
8
|
const resourceAsString = isEntity ? JSON.stringify(resource) : resource;
|
|
95
|
-
if (isEntity && typeof id !==
|
|
96
|
-
|
|
9
|
+
if (isEntity && typeof id !== "undefined") {
|
|
10
|
+
warning(
|
|
11
|
+
`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`
|
|
12
|
+
);
|
|
97
13
|
}
|
|
98
|
-
return useQuerySelect(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
canUser
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
14
|
+
return useQuerySelect(
|
|
15
|
+
(resolve) => {
|
|
16
|
+
const hasId = isEntity ? !!resource.id : !!id;
|
|
17
|
+
const { canUser } = resolve(coreStore);
|
|
18
|
+
const create = canUser(
|
|
19
|
+
"create",
|
|
20
|
+
isEntity ? { kind: resource.kind, name: resource.name } : resource
|
|
21
|
+
);
|
|
22
|
+
if (!hasId) {
|
|
23
|
+
const read2 = canUser("read", resource);
|
|
24
|
+
const isResolving2 = create.isResolving || read2.isResolving;
|
|
25
|
+
const hasResolved2 = create.hasResolved && read2.hasResolved;
|
|
26
|
+
let status2 = Status.Idle;
|
|
27
|
+
if (isResolving2) {
|
|
28
|
+
status2 = Status.Resolving;
|
|
29
|
+
} else if (hasResolved2) {
|
|
30
|
+
status2 = Status.Success;
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
status: status2,
|
|
34
|
+
isResolving: isResolving2,
|
|
35
|
+
hasResolved: hasResolved2,
|
|
36
|
+
canCreate: create.hasResolved && create.data,
|
|
37
|
+
canRead: read2.hasResolved && read2.data
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const read = canUser("read", resource, id);
|
|
41
|
+
const update = canUser("update", resource, id);
|
|
42
|
+
const _delete = canUser("delete", resource, id);
|
|
43
|
+
const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
|
|
44
|
+
const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
|
|
111
45
|
let status = Status.Idle;
|
|
112
46
|
if (isResolving) {
|
|
113
47
|
status = Status.Resolving;
|
|
@@ -118,38 +52,25 @@ function useResourcePermissions(resource, id) {
|
|
|
118
52
|
status,
|
|
119
53
|
isResolving,
|
|
120
54
|
hasResolved,
|
|
121
|
-
|
|
122
|
-
|
|
55
|
+
canRead: hasResolved && read.data,
|
|
56
|
+
canCreate: hasResolved && create.data,
|
|
57
|
+
canUpdate: hasResolved && update.data,
|
|
58
|
+
canDelete: hasResolved && _delete.data
|
|
123
59
|
};
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const _delete = canUser('delete', resource, id);
|
|
128
|
-
const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
|
|
129
|
-
const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
|
|
130
|
-
let status = Status.Idle;
|
|
131
|
-
if (isResolving) {
|
|
132
|
-
status = Status.Resolving;
|
|
133
|
-
} else if (hasResolved) {
|
|
134
|
-
status = Status.Success;
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
status,
|
|
138
|
-
isResolving,
|
|
139
|
-
hasResolved,
|
|
140
|
-
canRead: hasResolved && read.data,
|
|
141
|
-
canCreate: hasResolved && create.data,
|
|
142
|
-
canUpdate: hasResolved && update.data,
|
|
143
|
-
canDelete: hasResolved && _delete.data
|
|
144
|
-
};
|
|
145
|
-
}, [resourceAsString, id]);
|
|
60
|
+
},
|
|
61
|
+
[resourceAsString, id]
|
|
62
|
+
);
|
|
146
63
|
}
|
|
147
|
-
|
|
148
|
-
|
|
64
|
+
var use_resource_permissions_default = useResourcePermissions;
|
|
65
|
+
function __experimentalUseResourcePermissions(resource, id) {
|
|
149
66
|
deprecated(`wp.data.__experimentalUseResourcePermissions`, {
|
|
150
|
-
alternative:
|
|
151
|
-
since:
|
|
67
|
+
alternative: "wp.data.useResourcePermissions",
|
|
68
|
+
since: "6.1"
|
|
152
69
|
});
|
|
153
70
|
return useResourcePermissions(resource, id);
|
|
154
71
|
}
|
|
155
|
-
|
|
72
|
+
export {
|
|
73
|
+
__experimentalUseResourcePermissions,
|
|
74
|
+
use_resource_permissions_default as default
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=use-resource-permissions.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/use-resource-permissions.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\nimport warning from '@wordpress/warning';\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\ntype EntityResource = { kind: string; name: string; id?: string | number };\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType >;\n\nfunction useResourcePermissions< IdType = void >(\n\tresource: EntityResource,\n\tid?: never\n): ResourcePermissionsResolution< IdType >;\n\n/**\n * Resolves resource permissions.\n *\n * @since 6.1.0 Introduced in WordPress core.\n *\n * @param resource Entity resource to check. Accepts entity object `{ kind: 'postType', name: 'attachment', id: 1 }`\n * or REST base as a string - `media`.\n * @param id Optional ID of the resource to check, e.g. 10. Note: This argument is discouraged\n * when using an entity object as a resource to check permissions and will be ignored.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( { kind: 'postType', name: 'page' } );\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( { kind: 'postType', name: 'page', id: 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 */\nfunction useResourcePermissions< IdType = void >(\n\tresource: string | EntityResource,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\t// Serialize `resource` to a string that can be safely used as a React dep.\n\t// We can't just pass `resource` 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 isEntity = typeof resource === 'object';\n\tconst resourceAsString = isEntity ? JSON.stringify( resource ) : resource;\n\n\tif ( isEntity && typeof id !== 'undefined' ) {\n\t\twarning(\n\t\t\t`When 'resource' is an entity object, passing 'id' as a separate argument isn't supported.`\n\t\t);\n\t}\n\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst hasId = isEntity ? !! resource.id : !! id;\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser(\n\t\t\t\t'create',\n\t\t\t\tisEntity\n\t\t\t\t\t? { kind: resource.kind, name: resource.name }\n\t\t\t\t\t: resource\n\t\t\t);\n\n\t\t\tif ( ! hasId ) {\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[ resourceAsString, id ]\n\t);\n}\n\nexport default useResourcePermissions;\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"],
|
|
5
|
+
"mappings": "AAGA,OAAO,gBAAgB;AACvB,OAAO,aAAa;AAKpB,SAAS,SAAS,iBAAiB;AACnC,SAAS,cAAc;AACvB,OAAO,oBAAoB;AAmH3B,SAAS,uBACR,UACA,IAC0C;AAK1C,QAAM,WAAW,OAAO,aAAa;AACrC,QAAM,mBAAmB,WAAW,KAAK,UAAW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AAAA,QACjC,WAAW,eAAe,OAAO;AAAA,QACjC,WAAW,eAAe,QAAQ;AAAA,MACnC;AAAA,IACD;AAAA,IACA,CAAE,kBAAkB,EAAG;AAAA,EACxB;AACD;AAEA,IAAO,mCAAQ;AAER,SAAS,qCACf,UACA,IACC;AACD,aAAY,gDAAgD;AAAA,IAC3D,aAAa;AAAA,IACb,OAAO;AAAA,EACR,CAAE;AACF,SAAO,uBAAwB,UAAU,EAAG;AAC7C;",
|
|
6
|
+
"names": ["read", "isResolving", "hasResolved", "status"]
|
|
7
|
+
}
|
package/build-module/index.js
CHANGED
|
@@ -1,49 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
import
|
|
16
|
-
import {
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
// The entity selectors/resolvers and actions are shortcuts to their generic equivalents
|
|
23
|
-
// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)
|
|
24
|
-
// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...
|
|
25
|
-
// The "kind" and the "name" of the entity are combined to generate these shortcuts.
|
|
26
|
-
const entitiesConfig = [...rootEntitiesConfig, ...additionalEntityConfigLoaders.filter(config => !!config.name)];
|
|
1
|
+
import { createReduxStore, register } from "@wordpress/data";
|
|
2
|
+
import reducer from "./reducer";
|
|
3
|
+
import * as selectors from "./selectors";
|
|
4
|
+
import * as privateSelectors from "./private-selectors";
|
|
5
|
+
import * as actions from "./actions";
|
|
6
|
+
import * as privateActions from "./private-actions";
|
|
7
|
+
import * as resolvers from "./resolvers";
|
|
8
|
+
import createLocksActions from "./locks/actions";
|
|
9
|
+
import {
|
|
10
|
+
rootEntitiesConfig,
|
|
11
|
+
additionalEntityConfigLoaders,
|
|
12
|
+
getMethodName
|
|
13
|
+
} from "./entities";
|
|
14
|
+
import { STORE_NAME } from "./name";
|
|
15
|
+
import { unlock } from "./lock-unlock";
|
|
16
|
+
import { dynamicActions, dynamicSelectors } from "./dynamic-entities";
|
|
17
|
+
import logEntityDeprecation from "./utils/log-entity-deprecation";
|
|
18
|
+
const entitiesConfig = [
|
|
19
|
+
...rootEntitiesConfig,
|
|
20
|
+
...additionalEntityConfigLoaders.filter((config) => !!config.name)
|
|
21
|
+
];
|
|
27
22
|
const entitySelectors = entitiesConfig.reduce((result, entity) => {
|
|
28
|
-
const {
|
|
29
|
-
kind,
|
|
30
|
-
name,
|
|
31
|
-
plural
|
|
32
|
-
} = entity;
|
|
23
|
+
const { kind, name, plural } = entity;
|
|
33
24
|
const getEntityRecordMethodName = getMethodName(kind, name);
|
|
34
25
|
result[getEntityRecordMethodName] = (state, key, query) => {
|
|
35
26
|
logEntityDeprecation(kind, name, getEntityRecordMethodName, {
|
|
36
27
|
isShorthandSelector: true,
|
|
37
|
-
alternativeFunctionName:
|
|
28
|
+
alternativeFunctionName: "getEntityRecord"
|
|
38
29
|
});
|
|
39
30
|
return selectors.getEntityRecord(state, kind, name, key, query);
|
|
40
31
|
};
|
|
41
32
|
if (plural) {
|
|
42
|
-
const getEntityRecordsMethodName = getMethodName(kind, plural,
|
|
33
|
+
const getEntityRecordsMethodName = getMethodName(kind, plural, "get");
|
|
43
34
|
result[getEntityRecordsMethodName] = (state, query) => {
|
|
44
35
|
logEntityDeprecation(kind, name, getEntityRecordsMethodName, {
|
|
45
36
|
isShorthandSelector: true,
|
|
46
|
-
alternativeFunctionName:
|
|
37
|
+
alternativeFunctionName: "getEntityRecords"
|
|
47
38
|
});
|
|
48
39
|
return selectors.getEntityRecords(state, kind, name, query);
|
|
49
40
|
};
|
|
@@ -51,50 +42,43 @@ const entitySelectors = entitiesConfig.reduce((result, entity) => {
|
|
|
51
42
|
return result;
|
|
52
43
|
}, {});
|
|
53
44
|
const entityResolvers = entitiesConfig.reduce((result, entity) => {
|
|
54
|
-
const {
|
|
55
|
-
kind,
|
|
56
|
-
name,
|
|
57
|
-
plural
|
|
58
|
-
} = entity;
|
|
45
|
+
const { kind, name, plural } = entity;
|
|
59
46
|
const getEntityRecordMethodName = getMethodName(kind, name);
|
|
60
47
|
result[getEntityRecordMethodName] = (key, query) => {
|
|
61
48
|
logEntityDeprecation(kind, name, getEntityRecordMethodName, {
|
|
62
49
|
isShorthandSelector: true,
|
|
63
|
-
alternativeFunctionName:
|
|
50
|
+
alternativeFunctionName: "getEntityRecord"
|
|
64
51
|
});
|
|
65
52
|
return resolvers.getEntityRecord(kind, name, key, query);
|
|
66
53
|
};
|
|
67
54
|
if (plural) {
|
|
68
|
-
const getEntityRecordsMethodName = getMethodName(kind, plural,
|
|
55
|
+
const getEntityRecordsMethodName = getMethodName(kind, plural, "get");
|
|
69
56
|
result[getEntityRecordsMethodName] = (...args) => {
|
|
70
57
|
logEntityDeprecation(kind, plural, getEntityRecordsMethodName, {
|
|
71
58
|
isShorthandSelector: true,
|
|
72
|
-
alternativeFunctionName:
|
|
59
|
+
alternativeFunctionName: "getEntityRecords"
|
|
73
60
|
});
|
|
74
61
|
return resolvers.getEntityRecords(kind, name, ...args);
|
|
75
62
|
};
|
|
76
|
-
result[getEntityRecordsMethodName].shouldInvalidate = action => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
|
|
63
|
+
result[getEntityRecordsMethodName].shouldInvalidate = (action) => resolvers.getEntityRecords.shouldInvalidate(action, kind, name);
|
|
77
64
|
}
|
|
78
65
|
return result;
|
|
79
66
|
}, {});
|
|
80
67
|
const entityActions = entitiesConfig.reduce((result, entity) => {
|
|
81
|
-
const {
|
|
82
|
-
|
|
83
|
-
name
|
|
84
|
-
} = entity;
|
|
85
|
-
const saveEntityRecordMethodName = getMethodName(kind, name, 'save');
|
|
68
|
+
const { kind, name } = entity;
|
|
69
|
+
const saveEntityRecordMethodName = getMethodName(kind, name, "save");
|
|
86
70
|
result[saveEntityRecordMethodName] = (record, options) => {
|
|
87
71
|
logEntityDeprecation(kind, name, saveEntityRecordMethodName, {
|
|
88
72
|
isShorthandSelector: true,
|
|
89
|
-
alternativeFunctionName:
|
|
73
|
+
alternativeFunctionName: "saveEntityRecord"
|
|
90
74
|
});
|
|
91
75
|
return actions.saveEntityRecord(kind, name, record, options);
|
|
92
76
|
};
|
|
93
|
-
const deleteEntityRecordMethodName = getMethodName(kind, name,
|
|
77
|
+
const deleteEntityRecordMethodName = getMethodName(kind, name, "delete");
|
|
94
78
|
result[deleteEntityRecordMethodName] = (key, query, options) => {
|
|
95
79
|
logEntityDeprecation(kind, name, deleteEntityRecordMethodName, {
|
|
96
80
|
isShorthandSelector: true,
|
|
97
|
-
alternativeFunctionName:
|
|
81
|
+
alternativeFunctionName: "deleteEntityRecord"
|
|
98
82
|
});
|
|
99
83
|
return actions.deleteEntityRecord(kind, name, key, query, options);
|
|
100
84
|
};
|
|
@@ -113,26 +97,20 @@ const storeConfig = () => ({
|
|
|
113
97
|
...selectors,
|
|
114
98
|
...entitySelectors
|
|
115
99
|
},
|
|
116
|
-
resolvers: {
|
|
117
|
-
...resolvers,
|
|
118
|
-
...entityResolvers
|
|
119
|
-
}
|
|
100
|
+
resolvers: { ...resolvers, ...entityResolvers }
|
|
120
101
|
});
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Store definition for the code data namespace.
|
|
124
|
-
*
|
|
125
|
-
* @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
|
|
126
|
-
*/
|
|
127
|
-
export const store = createReduxStore(STORE_NAME, storeConfig());
|
|
102
|
+
const store = createReduxStore(STORE_NAME, storeConfig());
|
|
128
103
|
unlock(store).registerPrivateSelectors(privateSelectors);
|
|
129
104
|
unlock(store).registerPrivateActions(privateActions);
|
|
130
|
-
register(store);
|
|
131
|
-
|
|
132
|
-
export
|
|
133
|
-
export * from
|
|
134
|
-
export * from
|
|
135
|
-
export * from
|
|
136
|
-
export * from
|
|
137
|
-
export
|
|
138
|
-
|
|
105
|
+
register(store);
|
|
106
|
+
import { default as default2 } from "./entity-provider";
|
|
107
|
+
export * from "./entity-provider";
|
|
108
|
+
export * from "./entity-types";
|
|
109
|
+
export * from "./fetch";
|
|
110
|
+
export * from "./hooks";
|
|
111
|
+
export * from "./private-apis";
|
|
112
|
+
export {
|
|
113
|
+
default2 as EntityProvider,
|
|
114
|
+
store
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["createReduxStore","register","reducer","selectors","privateSelectors","actions","privateActions","resolvers","createLocksActions","rootEntitiesConfig","additionalEntityConfigLoaders","getMethodName","STORE_NAME","unlock","dynamicActions","dynamicSelectors","logEntityDeprecation","entitiesConfig","filter","config","name","entitySelectors","reduce","result","entity","kind","plural","getEntityRecordMethodName","state","key","query","isShorthandSelector","alternativeFunctionName","getEntityRecord","getEntityRecordsMethodName","getEntityRecords","entityResolvers","args","shouldInvalidate","action","entityActions","saveEntityRecordMethodName","record","options","saveEntityRecord","deleteEntityRecordMethodName","deleteEntityRecord","storeConfig","store","registerPrivateSelectors","registerPrivateActions","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 privateActions from './private-actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport {\n\trootEntitiesConfig,\n\tadditionalEntityConfigLoaders,\n\tgetMethodName,\n} from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { dynamicActions, dynamicSelectors } from './dynamic-entities';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\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.\nconst entitiesConfig = [\n\t...rootEntitiesConfig,\n\t...additionalEntityConfigLoaders.filter( ( config ) => !! config.name ),\n];\n\nconst entitySelectors = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( state, key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn selectors.getEntityRecord( state, kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( state, query ) => {\n\t\t\tlogEntityDeprecation( kind, name, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn selectors.getEntityRecords( state, kind, name, query );\n\t\t};\n\t}\n\treturn result;\n}, {} );\n\nconst entityResolvers = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn resolvers.getEntityRecord( kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( ...args ) => {\n\t\t\tlogEntityDeprecation( kind, plural, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn resolvers.getEntityRecords( kind, name, ...args );\n\t\t};\n\t\tresult[ getEntityRecordsMethodName ].shouldInvalidate = ( action ) =>\n\t\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\t}\n\treturn result;\n}, {} );\n\nconst entityActions = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\n\tconst saveEntityRecordMethodName = getMethodName( kind, name, 'save' );\n\tresult[ saveEntityRecordMethodName ] = ( record, options ) => {\n\t\tlogEntityDeprecation( kind, name, saveEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'saveEntityRecord',\n\t\t} );\n\t\treturn actions.saveEntityRecord( kind, name, record, options );\n\t};\n\n\tconst deleteEntityRecordMethodName = getMethodName( kind, name, 'delete' );\n\tresult[ deleteEntityRecordMethodName ] = ( key, query, options ) => {\n\t\tlogEntityDeprecation( kind, name, deleteEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'deleteEntityRecord',\n\t\t} );\n\t\treturn actions.deleteEntityRecord( kind, name, key, query, options );\n\t};\n\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: {\n\t\t...dynamicActions,\n\t\t...actions,\n\t\t...entityActions,\n\t\t...createLocksActions(),\n\t},\n\tselectors: {\n\t\t...dynamicSelectors,\n\t\t...selectors,\n\t\t...entitySelectors,\n\t},\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 );\nunlock( store ).registerPrivateActions( privateActions );\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';\nexport * from './private-apis';\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,cAAc,MAAM,mBAAmB;AACnD,OAAO,KAAKC,SAAS,MAAM,aAAa;AACxC,OAAOC,kBAAkB,MAAM,iBAAiB;AAChD,SACCC,kBAAkB,EAClBC,6BAA6B,EAC7BC,aAAa,QACP,YAAY;AACnB,SAASC,UAAU,QAAQ,QAAQ;AACnC,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,oBAAoB;AACrE,OAAOC,oBAAoB,MAAM,gCAAgC;;AAEjE;AACA;AACA;AACA;AACA,MAAMC,cAAc,GAAG,CACtB,GAAGR,kBAAkB,EACrB,GAAGC,6BAA6B,CAACQ,MAAM,CAAIC,MAAM,IAAM,CAAC,CAAEA,MAAM,CAACC,IAAK,CAAC,CACvE;AAED,MAAMC,eAAe,GAAGJ,cAAc,CAACK,MAAM,CAAE,CAAEC,MAAM,EAAEC,MAAM,KAAM;EACpE,MAAM;IAAEC,IAAI;IAAEL,IAAI;IAAEM;EAAO,CAAC,GAAGF,MAAM;EAErC,MAAMG,yBAAyB,GAAGhB,aAAa,CAAEc,IAAI,EAAEL,IAAK,CAAC;EAC7DG,MAAM,CAAEI,yBAAyB,CAAE,GAAG,CAAEC,KAAK,EAAEC,GAAG,EAAEC,KAAK,KAAM;IAC9Dd,oBAAoB,CAAES,IAAI,EAAEL,IAAI,EAAEO,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
3
|
+
"sources": ["../src/index.js"],
|
|
4
|
+
"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 privateActions from './private-actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport {\n\trootEntitiesConfig,\n\tadditionalEntityConfigLoaders,\n\tgetMethodName,\n} from './entities';\nimport { STORE_NAME } from './name';\nimport { unlock } from './lock-unlock';\nimport { dynamicActions, dynamicSelectors } from './dynamic-entities';\nimport logEntityDeprecation from './utils/log-entity-deprecation';\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.\nconst entitiesConfig = [\n\t...rootEntitiesConfig,\n\t...additionalEntityConfigLoaders.filter( ( config ) => !! config.name ),\n];\n\nconst entitySelectors = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( state, key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn selectors.getEntityRecord( state, kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( state, query ) => {\n\t\t\tlogEntityDeprecation( kind, name, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn selectors.getEntityRecords( state, kind, name, query );\n\t\t};\n\t}\n\treturn result;\n}, {} );\n\nconst entityResolvers = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name, plural } = entity;\n\tconst getEntityRecordMethodName = getMethodName( kind, name );\n\tresult[ getEntityRecordMethodName ] = ( key, query ) => {\n\t\tlogEntityDeprecation( kind, name, getEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'getEntityRecord',\n\t\t} );\n\t\treturn resolvers.getEntityRecord( kind, name, key, query );\n\t};\n\n\tif ( plural ) {\n\t\tconst getEntityRecordsMethodName = getMethodName( kind, plural, 'get' );\n\t\tresult[ getEntityRecordsMethodName ] = ( ...args ) => {\n\t\t\tlogEntityDeprecation( kind, plural, getEntityRecordsMethodName, {\n\t\t\t\tisShorthandSelector: true,\n\t\t\t\talternativeFunctionName: 'getEntityRecords',\n\t\t\t} );\n\t\t\treturn resolvers.getEntityRecords( kind, name, ...args );\n\t\t};\n\t\tresult[ getEntityRecordsMethodName ].shouldInvalidate = ( action ) =>\n\t\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\t}\n\treturn result;\n}, {} );\n\nconst entityActions = entitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\n\tconst saveEntityRecordMethodName = getMethodName( kind, name, 'save' );\n\tresult[ saveEntityRecordMethodName ] = ( record, options ) => {\n\t\tlogEntityDeprecation( kind, name, saveEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'saveEntityRecord',\n\t\t} );\n\t\treturn actions.saveEntityRecord( kind, name, record, options );\n\t};\n\n\tconst deleteEntityRecordMethodName = getMethodName( kind, name, 'delete' );\n\tresult[ deleteEntityRecordMethodName ] = ( key, query, options ) => {\n\t\tlogEntityDeprecation( kind, name, deleteEntityRecordMethodName, {\n\t\t\tisShorthandSelector: true,\n\t\t\talternativeFunctionName: 'deleteEntityRecord',\n\t\t} );\n\t\treturn actions.deleteEntityRecord( kind, name, key, query, options );\n\t};\n\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: {\n\t\t...dynamicActions,\n\t\t...actions,\n\t\t...entityActions,\n\t\t...createLocksActions(),\n\t},\n\tselectors: {\n\t\t...dynamicSelectors,\n\t\t...selectors,\n\t\t...entitySelectors,\n\t},\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 );\nunlock( store ).registerPrivateActions( privateActions );\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';\nexport * from './private-apis';\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,kBAAkB,gBAAgB;AAK3C,OAAO,aAAa;AACpB,YAAY,eAAe;AAC3B,YAAY,sBAAsB;AAClC,YAAY,aAAa;AACzB,YAAY,oBAAoB;AAChC,YAAY,eAAe;AAC3B,OAAO,wBAAwB;AAC/B;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,gBAAgB,wBAAwB;AACjD,OAAO,0BAA0B;AAMjC,MAAM,iBAAiB;AAAA,EACtB,GAAG;AAAA,EACH,GAAG,8BAA8B,OAAQ,CAAE,WAAY,CAAC,CAAE,OAAO,IAAK;AACvE;AAEA,MAAM,kBAAkB,eAAe,OAAQ,CAAE,QAAQ,WAAY;AACpE,QAAM,EAAE,MAAM,MAAM,OAAO,IAAI;AAE/B,QAAM,4BAA4B,cAAe,MAAM,IAAK;AAC5D,SAAQ,yBAA0B,IAAI,CAAE,OAAO,KAAK,UAAW;AAC9D,yBAAsB,MAAM,M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
5
|
-
|
|
1
|
+
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
|
|
2
|
+
const { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
|
|
3
|
+
"I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
|
|
4
|
+
"@wordpress/core-data"
|
|
5
|
+
);
|
|
6
|
+
export {
|
|
6
7
|
lock,
|
|
7
8
|
unlock
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=lock-unlock.js.map
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=lock-unlock.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/lock-unlock.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/core-data'\n\t);\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,wDAAwD;AAE1D,MAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import createLocks from './engine';
|
|
5
|
-
export default function createLocksActions() {
|
|
1
|
+
import createLocks from "./engine";
|
|
2
|
+
function createLocksActions() {
|
|
6
3
|
const locks = createLocks();
|
|
7
|
-
function __unstableAcquireStoreLock(store, path, {
|
|
8
|
-
exclusive
|
|
9
|
-
}) {
|
|
4
|
+
function __unstableAcquireStoreLock(store, path, { exclusive }) {
|
|
10
5
|
return () => locks.acquire(store, path, exclusive);
|
|
11
6
|
}
|
|
12
7
|
function __unstableReleaseStoreLock(lock) {
|
|
13
8
|
return () => locks.release(lock);
|
|
14
9
|
}
|
|
15
|
-
return {
|
|
16
|
-
__unstableAcquireStoreLock,
|
|
17
|
-
__unstableReleaseStoreLock
|
|
18
|
-
};
|
|
10
|
+
return { __unstableAcquireStoreLock, __unstableReleaseStoreLock };
|
|
19
11
|
}
|
|
20
|
-
|
|
12
|
+
export {
|
|
13
|
+
createLocksActions as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=actions.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/locks/actions.js"],
|
|
4
|
+
"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"],
|
|
5
|
+
"mappings": "AAGA,OAAO,iBAAiB;AAET,SAAR,qBAAsC;AAC5C,QAAM,QAAQ,YAAY;AAE1B,WAAS,2BAA4B,OAAO,MAAM,EAAE,UAAU,GAAI;AACjE,WAAO,MAAM,MAAM,QAAS,OAAO,MAAM,SAAU;AAAA,EACpD;AAEA,WAAS,2BAA4B,MAAO;AAC3C,WAAO,MAAM,MAAM,QAAS,IAAK;AAAA,EAClC;AAEA,SAAO,EAAE,4BAA4B,2BAA2B;AACjE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,30 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import { isLockAvailable, getPendingLockRequests } from './selectors';
|
|
6
|
-
export default function createLocks() {
|
|
7
|
-
let state = reducer(undefined, {
|
|
8
|
-
type: '@@INIT'
|
|
9
|
-
});
|
|
1
|
+
import reducer from "./reducer";
|
|
2
|
+
import { isLockAvailable, getPendingLockRequests } from "./selectors";
|
|
3
|
+
function createLocks() {
|
|
4
|
+
let state = reducer(void 0, { type: "@@INIT" });
|
|
10
5
|
function processPendingLockRequests() {
|
|
11
6
|
for (const request of getPendingLockRequests(state)) {
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
path,
|
|
15
|
-
exclusive,
|
|
16
|
-
notifyAcquired
|
|
17
|
-
} = request;
|
|
18
|
-
if (isLockAvailable(state, store, path, {
|
|
19
|
-
exclusive
|
|
20
|
-
})) {
|
|
21
|
-
const lock = {
|
|
22
|
-
store,
|
|
23
|
-
path,
|
|
24
|
-
exclusive
|
|
25
|
-
};
|
|
7
|
+
const { store, path, exclusive, notifyAcquired } = request;
|
|
8
|
+
if (isLockAvailable(state, store, path, { exclusive })) {
|
|
9
|
+
const lock = { store, path, exclusive };
|
|
26
10
|
state = reducer(state, {
|
|
27
|
-
type:
|
|
11
|
+
type: "GRANT_LOCK_REQUEST",
|
|
28
12
|
lock,
|
|
29
13
|
request
|
|
30
14
|
});
|
|
@@ -33,29 +17,24 @@ export default function createLocks() {
|
|
|
33
17
|
}
|
|
34
18
|
}
|
|
35
19
|
function acquire(store, path, exclusive) {
|
|
36
|
-
return new Promise(resolve => {
|
|
20
|
+
return new Promise((resolve) => {
|
|
37
21
|
state = reducer(state, {
|
|
38
|
-
type:
|
|
39
|
-
request: {
|
|
40
|
-
store,
|
|
41
|
-
path,
|
|
42
|
-
exclusive,
|
|
43
|
-
notifyAcquired: resolve
|
|
44
|
-
}
|
|
22
|
+
type: "ENQUEUE_LOCK_REQUEST",
|
|
23
|
+
request: { store, path, exclusive, notifyAcquired: resolve }
|
|
45
24
|
});
|
|
46
25
|
processPendingLockRequests();
|
|
47
26
|
});
|
|
48
27
|
}
|
|
49
28
|
function release(lock) {
|
|
50
29
|
state = reducer(state, {
|
|
51
|
-
type:
|
|
30
|
+
type: "RELEASE_LOCK",
|
|
52
31
|
lock
|
|
53
32
|
});
|
|
54
33
|
processPendingLockRequests();
|
|
55
34
|
}
|
|
56
|
-
return {
|
|
57
|
-
acquire,
|
|
58
|
-
release
|
|
59
|
-
};
|
|
35
|
+
return { acquire, release };
|
|
60
36
|
}
|
|
61
|
-
|
|
37
|
+
export {
|
|
38
|
+
createLocks as default
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=engine.js.map
|