@wordpress/core-data 4.0.7 → 4.1.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/LICENSE.md +1 -1
- package/README.md +2 -0
- package/build/actions.js +25 -5
- package/build/actions.js.map +1 -1
- package/build/entities.js +13 -4
- package/build/entities.js.map +1 -1
- package/build/reducer.js +36 -0
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +18 -2
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +21 -15
- package/build/selectors.js.map +1 -1
- package/build-module/actions.js +23 -5
- package/build-module/actions.js.map +1 -1
- package/build-module/entities.js +13 -4
- package/build-module/entities.js.map +1 -1
- package/build-module/reducer.js +34 -0
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +14 -1
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +19 -15
- package/build-module/selectors.js.map +1 -1
- package/package.json +11 -11
- package/src/actions.js +27 -5
- package/src/entities.js +12 -4
- package/src/reducer.js +30 -0
- package/src/resolvers.js +15 -1
- package/src/selectors.js +17 -15
- package/src/test/selectors.js +4 -4
package/src/resolvers.js
CHANGED
|
@@ -450,8 +450,22 @@ export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ( {
|
|
|
450
450
|
const themeGlobalStyles = await apiFetch( {
|
|
451
451
|
path: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,
|
|
452
452
|
} );
|
|
453
|
-
|
|
453
|
+
dispatch.__experimentalReceiveThemeBaseGlobalStyles(
|
|
454
454
|
currentTheme.stylesheet,
|
|
455
455
|
themeGlobalStyles
|
|
456
456
|
);
|
|
457
457
|
};
|
|
458
|
+
|
|
459
|
+
export const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ( {
|
|
460
|
+
resolveSelect,
|
|
461
|
+
dispatch,
|
|
462
|
+
} ) => {
|
|
463
|
+
const currentTheme = await resolveSelect.getCurrentTheme();
|
|
464
|
+
const variations = await apiFetch( {
|
|
465
|
+
path: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }/variations`,
|
|
466
|
+
} );
|
|
467
|
+
dispatch.__experimentalReceiveThemeGlobalStyleVariations(
|
|
468
|
+
currentTheme.stylesheet,
|
|
469
|
+
variations
|
|
470
|
+
);
|
|
471
|
+
};
|
package/src/selectors.js
CHANGED
|
@@ -28,17 +28,6 @@ import { getNormalizedCommaSeparable, isRawAttribute } from './utils';
|
|
|
28
28
|
*/
|
|
29
29
|
const EMPTY_OBJECT = {};
|
|
30
30
|
|
|
31
|
-
/**
|
|
32
|
-
* Shared reference to an empty array for cases where it is important to avoid
|
|
33
|
-
* returning a new array reference on every invocation, as in a connected or
|
|
34
|
-
* other pure component which performs `shouldComponentUpdate` check on props.
|
|
35
|
-
* This should be used as a last resort, since the normalized data should be
|
|
36
|
-
* maintained by the reducer result in state.
|
|
37
|
-
*
|
|
38
|
-
* @type {Array}
|
|
39
|
-
*/
|
|
40
|
-
const EMPTY_ARRAY = [];
|
|
41
|
-
|
|
42
31
|
/**
|
|
43
32
|
* Returns true if a request is in progress for embed preview data, or false
|
|
44
33
|
* otherwise.
|
|
@@ -304,16 +293,14 @@ export function hasEntityRecords( state, kind, name, query ) {
|
|
|
304
293
|
*/
|
|
305
294
|
export function getEntityRecords( state, kind, name, query ) {
|
|
306
295
|
// Queried data state is prepopulated for all known entities. If this is not
|
|
307
|
-
// assigned for the given parameters, then it is known to not exist.
|
|
308
|
-
// return value of an empty array is used instead of `null` (where `null` is
|
|
309
|
-
// otherwise used to represent an unknown state).
|
|
296
|
+
// assigned for the given parameters, then it is known to not exist.
|
|
310
297
|
const queriedState = get( state.entities.data, [
|
|
311
298
|
kind,
|
|
312
299
|
name,
|
|
313
300
|
'queriedData',
|
|
314
301
|
] );
|
|
315
302
|
if ( ! queriedState ) {
|
|
316
|
-
return
|
|
303
|
+
return null;
|
|
317
304
|
}
|
|
318
305
|
return getQueriedItems( queriedState, query );
|
|
319
306
|
}
|
|
@@ -921,3 +908,18 @@ export function __experimentalGetCurrentThemeBaseGlobalStyles( state ) {
|
|
|
921
908
|
}
|
|
922
909
|
return state.themeBaseGlobalStyles[ currentTheme.stylesheet ];
|
|
923
910
|
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Return the ID of the current global styles object.
|
|
914
|
+
*
|
|
915
|
+
* @param {Object} state Data state.
|
|
916
|
+
*
|
|
917
|
+
* @return {string} The current global styles ID.
|
|
918
|
+
*/
|
|
919
|
+
export function __experimentalGetCurrentThemeGlobalStylesVariations( state ) {
|
|
920
|
+
const currentTheme = getCurrentTheme( state );
|
|
921
|
+
if ( ! currentTheme ) {
|
|
922
|
+
return null;
|
|
923
|
+
}
|
|
924
|
+
return state.themeGlobalStyleVariations[ currentTheme.stylesheet ];
|
|
925
|
+
}
|
package/src/test/selectors.js
CHANGED
|
@@ -160,14 +160,14 @@ describe( 'hasEntityRecords', () => {
|
|
|
160
160
|
expect( hasEntityRecords( state, 'root', 'postType' ) ).toBe( false );
|
|
161
161
|
} );
|
|
162
162
|
|
|
163
|
-
it( 'returns
|
|
163
|
+
it( 'returns false if the entity configuration is not known', () => {
|
|
164
164
|
const state = deepFreeze( {
|
|
165
165
|
entities: {
|
|
166
166
|
data: {},
|
|
167
167
|
},
|
|
168
168
|
} );
|
|
169
169
|
|
|
170
|
-
expect( hasEntityRecords( state, 'root', 'postType' ) ).toBe(
|
|
170
|
+
expect( hasEntityRecords( state, 'root', 'postType' ) ).toBe( false );
|
|
171
171
|
} );
|
|
172
172
|
|
|
173
173
|
it( 'returns true if entity records have been received', () => {
|
|
@@ -295,14 +295,14 @@ describe( 'getEntityRecords', () => {
|
|
|
295
295
|
expect( getEntityRecords( state, 'root', 'postType' ) ).toBe( null );
|
|
296
296
|
} );
|
|
297
297
|
|
|
298
|
-
it( 'should return
|
|
298
|
+
it( 'should return null for an unknown entity configuration', () => {
|
|
299
299
|
const state = deepFreeze( {
|
|
300
300
|
entities: {
|
|
301
301
|
data: {},
|
|
302
302
|
},
|
|
303
303
|
} );
|
|
304
304
|
|
|
305
|
-
expect( getEntityRecords( state, 'root', 'postType' ) ).
|
|
305
|
+
expect( getEntityRecords( state, 'root', 'postType' ) ).toBe( null );
|
|
306
306
|
} );
|
|
307
307
|
|
|
308
308
|
it( 'should return all the records', () => {
|