Skip to content

Commit

Permalink
Change from store name provided as a string to store definition (#27094)
Browse files Browse the repository at this point in the history
* Change from store name provided as a string to store definition

* Lint

* lint - change import src

Co-authored-by: grzegorz_marzencki <[email protected]>
  • Loading branch information
grzim and grzegorz_marzencki authored Nov 24, 2020
1 parent e2ffa92 commit c10f11a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
7 changes: 4 additions & 3 deletions packages/block-library/src/block/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
BlockControls,
useBlockProps,
} from '@wordpress/block-editor';
import { store as reusableBlocksStore } from '@wordpress/reusable-blocks';

/**
* Internal dependencies
Expand Down Expand Up @@ -51,7 +52,7 @@ export default function ReusableBlockEdit( {
isSaving: select( 'core' ).isSavingEntityRecord( ...recordArgs ),
canUserUpdate: select( 'core' ).canUser( 'update', 'blocks', ref ),
isEditing: select(
'core/reusable-blocks'
reusableBlocksStore
).__experimentalIsEditingReusableBlock( clientId ),
settings: select( 'core/block-editor' ).getSettings(),
} ),
Expand All @@ -60,7 +61,7 @@ export default function ReusableBlockEdit( {

const { editEntityRecord, saveEditedEntityRecord } = useDispatch( 'core' );
const { __experimentalSetEditingReusableBlock } = useDispatch(
'core/reusable-blocks'
reusableBlocksStore
);
const setIsEditing = useCallback(
( value ) => {
Expand All @@ -71,7 +72,7 @@ export default function ReusableBlockEdit( {

const {
__experimentalConvertBlockToStatic: convertBlockToStatic,
} = useDispatch( 'core/reusable-blocks' );
} = useDispatch( reusableBlocksStore );

const { createSuccessNotice, createErrorNotice } = useDispatch(
'core/notices'
Expand Down
8 changes: 5 additions & 3 deletions packages/reusable-blocks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ return (
This package also provides convenient utilities for managing reusable blocks through redux actions:

```js
import { store as reusableBlocksStore } from '@wordpress/reusable-blocks';

function MyConvertToStaticButton( { clientId } ) {
const { __experimentalConvertBlockToStatic } = useDispatch( 'core/reusable-blocks' );
const { __experimentalConvertBlockToStatic } = useDispatch( reusableBlocksStore );
return (
<button onClick={() => __experimentalConvertBlockToStatic( clientId )} >
Convert to static
Expand All @@ -82,7 +84,7 @@ function MyConvertToStaticButton( { clientId } ) {
}

function MyConvertToReusableButton( { clientId } ) {
const { __experimentalConvertBlocksToReusable } = useDispatch( 'core/reusable-blocks' );
const { __experimentalConvertBlocksToReusable } = useDispatch( reusableBlocksStore );
return (
<button onClick={() => __experimentalConvertBlocksToReusable( [ clientId ] )} >
Convert to reusable
Expand All @@ -91,7 +93,7 @@ function MyConvertToReusableButton( { clientId } ) {
}

function MyDeleteReusableBlockButton( { id } ) {
const { __experimentalDeleteReusableBlock } = useDispatch( 'core/reusable-blocks' );
const { __experimentalDeleteReusableBlock } = useDispatch( reusableBlocksStore );
return (
<button onClick={() => __experimentalDeleteReusableBlock( id )} >
Delete reusable block
Expand Down
7 changes: 6 additions & 1 deletion packages/reusable-blocks/src/store/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import {
import { createRegistryControl } from '@wordpress/data';
import { __ } from '@wordpress/i18n';

/**
* Internal dependencies
*/
import { store as reusableBlocksStore } from './index.js';

/**
* Convert a reusable block to a static block effect handler
*
Expand Down Expand Up @@ -94,7 +99,7 @@ const controls = {
.dispatch( 'core/block-editor' )
.replaceBlocks( clientIds, newBlock );
registry
.dispatch( 'core/reusable-blocks' )
.dispatch( reusableBlocksStore )
.__experimentalSetEditingReusableBlock(
newBlock.clientId,
true
Expand Down

0 comments on commit c10f11a

Please sign in to comment.