Skip to content

Commit

Permalink
block-directory: migrate the data-controls to builtin controls (#25993)
Browse files Browse the repository at this point in the history
* block-directory: migrate the data-controls to builtin controls

Rather straightforward one, there are only two usages of `select`/`dispatch`.

* Update expected control types in tests: getBlockTypes is a sync select
  • Loading branch information
jsnajdr authored Oct 20, 2020
1 parent 1d6b8dc commit 26d2b0a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions packages/block-directory/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { apiFetch, dispatch, select } from '@wordpress/data-controls';
import { controls } from '@wordpress/data';
import { apiFetch } from '@wordpress/data-controls';

/**
* Internal dependencies
Expand Down Expand Up @@ -83,11 +84,11 @@ export function* installBlockType( block ) {
} );

yield loadAssets( assets );
const registeredBlocks = yield select( 'core/blocks', 'getBlockTypes' );
if (
! registeredBlocks.length ||
! registeredBlocks.filter( ( i ) => i.name === block.name ).length
) {
const registeredBlocks = yield controls.select(
'core/blocks',
'getBlockTypes'
);
if ( ! registeredBlocks.some( ( i ) => i.name === block.name ) ) {
throw new Error(
__( 'Error registering block. Try reloading the page.' )
);
Expand Down Expand Up @@ -141,7 +142,7 @@ export function* uninstallBlockType( block ) {
} );
yield removeInstalledBlockType( block );
} catch ( error ) {
yield dispatch(
yield controls.dispatch(
'core/notices',
'createErrorNotice',
error.message || __( 'An error occurred.' )
Expand Down
4 changes: 2 additions & 2 deletions packages/block-directory/src/store/test/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe( 'actions', () => {
args: [],
selectorName: 'getBlockTypes',
storeKey: 'core/blocks',
type: '@@data/RESOLVE_SELECT',
type: '@@data/SELECT',
} );

expect( generator.next( [ block ] ).value ).toEqual( {
Expand Down Expand Up @@ -143,7 +143,7 @@ describe( 'actions', () => {
args: [],
selectorName: 'getBlockTypes',
storeKey: 'core/blocks',
type: '@@data/RESOLVE_SELECT',
type: '@@data/SELECT',
} );

expect( generator.next( [ inactiveBlock ] ).value ).toEqual( {
Expand Down

0 comments on commit 26d2b0a

Please sign in to comment.