@wordpress/core-data 4.7.0 → 4.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +56 -56
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +1 -1
- package/build/batch/create-batch.js.map +1 -1
- package/build/batch/default-processor.js +13 -7
- package/build/batch/default-processor.js.map +1 -1
- package/build/entities.js +49 -35
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/entities.js +6 -0
- package/build/entity-types/entities.js.map +1 -0
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +94 -0
- package/build/hooks/use-resource-permissions.js.map +1 -0
- package/build/index.js +28 -1
- package/build/index.js.map +1 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/resolvers.js +4 -14
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +45 -8
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/with-weak-map-cache.js +1 -7
- package/build/utils/with-weak-map-cache.js.map +1 -1
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +2 -2
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/batch/default-processor.js +12 -5
- package/build-module/batch/default-processor.js.map +1 -1
- package/build-module/entities.js +49 -35
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/entities.js +2 -0
- package/build-module/entity-types/entities.js.map +1 -0
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +82 -0
- package/build-module/hooks/use-resource-permissions.js.map +1 -0
- package/build-module/index.js +3 -0
- package/build-module/index.js.map +1 -1
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/resolvers.js +5 -15
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +40 -4
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/with-weak-map-cache.js +1 -6
- package/build-module/utils/with-weak-map-cache.js.map +1 -1
- package/package.json +12 -12
- package/src/actions.js +389 -372
- package/src/batch/create-batch.js +2 -2
- package/src/batch/default-processor.js +10 -5
- package/src/entities.ts +357 -135
- package/src/entity-provider.js +4 -6
- package/src/entity-types/attachment.ts +4 -3
- package/src/entity-types/comment.ts +4 -3
- package/src/entity-types/entities.ts +130 -0
- package/src/entity-types/index.ts +115 -20
- package/src/entity-types/menu-location.ts +4 -3
- package/src/entity-types/nav-menu-item.ts +4 -3
- package/src/entity-types/nav-menu.ts +3 -3
- package/src/entity-types/page.ts +3 -3
- package/src/entity-types/plugin.ts +3 -3
- package/src/entity-types/post.ts +3 -3
- package/src/entity-types/settings.ts +3 -3
- package/src/entity-types/sidebar.ts +4 -3
- package/src/entity-types/taxonomy.ts +4 -3
- package/src/entity-types/theme.ts +3 -3
- package/src/entity-types/type.ts +3 -3
- package/src/entity-types/user.ts +3 -3
- package/src/entity-types/widget-type.ts +4 -3
- package/src/entity-types/widget.ts +3 -3
- package/src/entity-types/wp-template-part.ts +4 -3
- package/src/entity-types/wp-template.ts +4 -3
- package/src/fetch/test/__experimental-fetch-link-suggestions.js +2 -4
- package/src/hooks/test/use-query-select.js +4 -2
- package/src/hooks/test/use-resource-permissions.js +115 -0
- package/src/hooks/use-entity-record.ts +0 -1
- package/src/hooks/use-query-select.ts +26 -24
- package/src/hooks/use-resource-permissions.ts +120 -0
- package/src/index.js +3 -0
- package/src/locks/test/selectors.js +2 -1
- package/src/queried-data/selectors.js +2 -8
- package/src/resolvers.js +344 -326
- package/src/selectors.ts +347 -194
- package/src/test/reducer.js +5 -4
- package/src/test/resolvers.js +1 -3
- package/src/test/selectors.js +1 -2
- package/src/utils/forward-resolver.js +6 -5
- package/src/utils/on-sub-key.js +20 -20
- package/src/utils/with-weak-map-cache.js +1 -6
package/src/test/reducer.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import deepFreeze from 'deep-freeze';
|
|
5
|
-
import { filter } from 'lodash';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* Internal dependencies
|
|
@@ -135,9 +134,11 @@ describe( 'entities', () => {
|
|
|
135
134
|
entities: [ { kind: 'postType', name: 'posts' } ],
|
|
136
135
|
} );
|
|
137
136
|
|
|
138
|
-
expect(
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
expect(
|
|
138
|
+
Object.entries( state.config )
|
|
139
|
+
.filter( ( [ , cfg ] ) => cfg.kind === 'postType' )
|
|
140
|
+
.map( ( [ , cfg ] ) => cfg )
|
|
141
|
+
).toEqual( [ { kind: 'postType', name: 'posts' } ] );
|
|
141
142
|
} );
|
|
142
143
|
} );
|
|
143
144
|
|
package/src/test/resolvers.js
CHANGED
|
@@ -208,9 +208,7 @@ describe( 'getEntityRecords', () => {
|
|
|
208
208
|
} );
|
|
209
209
|
|
|
210
210
|
// The record should have been received.
|
|
211
|
-
expect(
|
|
212
|
-
dispatch.__unstableAcquireStoreLock
|
|
213
|
-
).toHaveBeenCalledWith(
|
|
211
|
+
expect( dispatch.__unstableAcquireStoreLock ).toHaveBeenCalledWith(
|
|
214
212
|
'core',
|
|
215
213
|
[ 'entities', 'records', 'root', 'postType' ],
|
|
216
214
|
{ exclusive: false }
|
package/src/test/selectors.js
CHANGED
|
@@ -611,8 +611,7 @@ describe( 'isPreviewEmbedFallback()', () => {
|
|
|
611
611
|
const state = deepFreeze( {
|
|
612
612
|
embedPreviews: {
|
|
613
613
|
'http://example.com/': {
|
|
614
|
-
html:
|
|
615
|
-
'<a href="http://example.com/">http://example.com/</a>',
|
|
614
|
+
html: '<a href="http://example.com/">http://example.com/</a>',
|
|
616
615
|
},
|
|
617
616
|
},
|
|
618
617
|
} );
|
|
@@ -5,10 +5,11 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @return {Function} Enhanced resolver.
|
|
7
7
|
*/
|
|
8
|
-
const forwardResolver =
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
const forwardResolver =
|
|
9
|
+
( resolverName ) =>
|
|
10
|
+
( ...args ) =>
|
|
11
|
+
async ( { resolveSelect } ) => {
|
|
12
|
+
await resolveSelect[ resolverName ]( ...args );
|
|
13
|
+
};
|
|
13
14
|
|
|
14
15
|
export default forwardResolver;
|
package/src/utils/on-sub-key.js
CHANGED
|
@@ -8,28 +8,28 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @return {AnyFunction} Higher-order reducer.
|
|
10
10
|
*/
|
|
11
|
-
export const onSubKey =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
11
|
+
export const onSubKey =
|
|
12
|
+
( actionProperty ) =>
|
|
13
|
+
( reducer ) =>
|
|
14
|
+
( state = {}, action ) => {
|
|
15
|
+
// Retrieve subkey from action. Do not track if undefined; useful for cases
|
|
16
|
+
// where reducer is scoped by action shape.
|
|
17
|
+
const key = action[ actionProperty ];
|
|
18
|
+
if ( key === undefined ) {
|
|
19
|
+
return state;
|
|
20
|
+
}
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
// Avoid updating state if unchanged. Note that this also accounts for a
|
|
23
|
+
// reducer which returns undefined on a key which is not yet tracked.
|
|
24
|
+
const nextKeyState = reducer( state[ key ], action );
|
|
25
|
+
if ( nextKeyState === state[ key ] ) {
|
|
26
|
+
return state;
|
|
27
|
+
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
return {
|
|
30
|
+
...state,
|
|
31
|
+
[ key ]: nextKeyState,
|
|
32
|
+
};
|
|
32
33
|
};
|
|
33
|
-
};
|
|
34
34
|
|
|
35
35
|
export default onSubKey;
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { isObjectLike } from 'lodash';
|
|
5
|
-
|
|
6
1
|
/**
|
|
7
2
|
* Given a function, returns an enhanced function which caches the result and
|
|
8
3
|
* tracks in WeakMap. The result is only cached if the original function is
|
|
@@ -25,7 +20,7 @@ function withWeakMapCache( fn ) {
|
|
|
25
20
|
// Can reach here if key is not valid for WeakMap, since `has`
|
|
26
21
|
// will return false for invalid key. Since `set` will throw,
|
|
27
22
|
// ensure that key is valid before setting into cache.
|
|
28
|
-
if (
|
|
23
|
+
if ( key !== null && typeof key === 'object' ) {
|
|
29
24
|
cache.set( key, value );
|
|
30
25
|
}
|
|
31
26
|
}
|