Skip to content

Commit

Permalink
Refactor to get baseConfig from context not coreStore
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Dec 14, 2023
1 parent f4b6822 commit 2bbe8a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
20 changes: 7 additions & 13 deletions packages/edit-site/src/components/revisions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {
__unstableIframe as Iframe,
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { useMemo } from '@wordpress/element';
import { store as coreStore } from '@wordpress/core-data';
import { useContext, useMemo } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -22,23 +21,18 @@ import { unlock } from '../../lock-unlock';
import { mergeBaseAndUserConfigs } from '../global-styles/global-styles-provider';
import EditorCanvasContainer from '../editor-canvas-container';

const { ExperimentalBlockEditorProvider, useGlobalStylesOutputWithConfig } =
unlock( blockEditorPrivateApis );
const {
ExperimentalBlockEditorProvider,
GlobalStylesContext,
useGlobalStylesOutputWithConfig,
} = unlock( blockEditorPrivateApis );

function isObjectEmpty( object ) {
return ! object || Object.keys( object ).length === 0;
}

function Revisions( { actions, userConfig, blocks } ) {
const { baseConfig } = useSelect(
( select ) => ( {
baseConfig:
select(
coreStore
).__experimentalGetCurrentThemeBaseGlobalStyles(),
} ),
[]
);
const { base: baseConfig } = useContext( GlobalStylesContext );

const mergedConfig = useMemo( () => {
if ( ! isObjectEmpty( userConfig ) && ! isObjectEmpty( baseConfig ) ) {
Expand Down
15 changes: 3 additions & 12 deletions packages/edit-site/src/components/style-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ import {
} from '@wordpress/block-editor';
import { useSelect } from '@wordpress/data';
import { useResizeObserver } from '@wordpress/compose';
import { useMemo, useState, memo } from '@wordpress/element';
import { useMemo, useState, memo, useContext } from '@wordpress/element';
import { ENTER, SPACE } from '@wordpress/keycodes';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand All @@ -41,6 +40,7 @@ import { mergeBaseAndUserConfigs } from '../global-styles/global-styles-provider
const {
ExperimentalBlockEditorProvider,
useGlobalStyle,
GlobalStylesContext,
useGlobalStylesOutputWithConfig,
} = unlock( blockEditorPrivateApis );

Expand Down Expand Up @@ -205,16 +205,7 @@ function StyleBook( {
} ) ),
[ examples ]
);

const { baseConfig } = useSelect(
( select ) => ( {
baseConfig:
select(
coreStore
).__experimentalGetCurrentThemeBaseGlobalStyles(),
} ),
[]
);
const { base: baseConfig } = useContext( GlobalStylesContext );

const mergedConfig = useMemo( () => {
if ( ! isObjectEmpty( userConfig ) && ! isObjectEmpty( baseConfig ) ) {
Expand Down

0 comments on commit 2bbe8a0

Please sign in to comment.