Skip to content

Commit

Permalink
Removing 'rich-text' references to the store name (#27820)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelgallani authored Dec 19, 2020
1 parent b6d6d4c commit bb9ec5e
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
3 changes: 2 additions & 1 deletion packages/rich-text/src/component/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { removeLineSeparator } from '../remove-line-separator';
import { isCollapsed } from '../is-collapsed';
import { remove } from '../remove';
import styles from './style.scss';
import { store as richTextStore } from '../store';

const unescapeSpaces = ( text ) => {
return text.replace( / | /gi, ' ' );
Expand Down Expand Up @@ -955,7 +956,7 @@ export default compose( [
get( parentBlock, [ 'attributes', 'childrenStyles' ] ) || {};

return {
formatTypes: select( 'core/rich-text' ).getFormatTypes(),
formatTypes: select( richTextStore ).getFormatTypes(),
isMentionsSupported:
getSettings( 'capabilities' ).mentions === true,
...{ parentBlockStyles },
Expand Down
6 changes: 5 additions & 1 deletion packages/rich-text/src/component/use-format-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
* WordPress dependencies
*/
import { useSelect, useDispatch } from '@wordpress/data';
/**
* Internal dependencies
*/
import { store as richTextStore } from '../store';

function formatTypesSelector( select ) {
return select( 'core/rich-text' ).getFormatTypes();
return select( richTextStore ).getFormatTypes();
}

/**
Expand Down
6 changes: 5 additions & 1 deletion packages/rich-text/src/get-format-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* WordPress dependencies
*/
import { select } from '@wordpress/data';
/**
* Internal dependencies
*/
import { store as richTextStore } from './store';

/** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */

Expand All @@ -13,5 +17,5 @@ import { select } from '@wordpress/data';
* @return {RichTextFormatType|undefined} Format type.
*/
export function getFormatType( name ) {
return select( 'core/rich-text' ).getFormatType( name );
return select( richTextStore ).getFormatType( name );
}
6 changes: 5 additions & 1 deletion packages/rich-text/src/get-format-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
* WordPress dependencies
*/
import { select } from '@wordpress/data';
/**
* Internal dependencies
*/
import { store as richTextStore } from './store';

/** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */

Expand All @@ -11,5 +15,5 @@ import { select } from '@wordpress/data';
* @return {Array<RichTextFormatType>} Format settings.
*/
export function getFormatTypes() {
return select( 'core/rich-text' ).getFormatTypes();
return select( richTextStore ).getFormatTypes();
}
13 changes: 8 additions & 5 deletions packages/rich-text/src/register-format-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
* WordPress dependencies
*/
import { select, dispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as richTextStore } from './store';
/**
* @typedef {Object} WPFormat
*
Expand Down Expand Up @@ -44,7 +47,7 @@ export function registerFormatType( name, settings ) {
return;
}

if ( select( 'core/rich-text' ).getFormatType( settings.name ) ) {
if ( select( richTextStore ).getFormatType( settings.name ) ) {
window.console.error(
'Format "' + settings.name + '" is already registered.'
);
Expand Down Expand Up @@ -76,7 +79,7 @@ export function registerFormatType( name, settings ) {

if ( settings.className === null ) {
const formatTypeForBareElement = select(
'core/rich-text'
richTextStore
).getFormatTypeForBareElement( settings.tagName );

if ( formatTypeForBareElement ) {
Expand All @@ -87,7 +90,7 @@ export function registerFormatType( name, settings ) {
}
} else {
const formatTypeForClassName = select(
'core/rich-text'
richTextStore
).getFormatTypeForClassName( settings.className );

if ( formatTypeForClassName ) {
Expand Down Expand Up @@ -119,7 +122,7 @@ export function registerFormatType( name, settings ) {
return;
}

dispatch( 'core/rich-text' ).addFormatTypes( settings );
dispatch( richTextStore ).addFormatTypes( settings );

return settings;
}
3 changes: 2 additions & 1 deletion packages/rich-text/src/test/register-format-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { select } from '@wordpress/data';
import { registerFormatType } from '../register-format-type';
import { unregisterFormatType } from '../unregister-format-type';
import { getFormatType } from '../get-format-type';
import { store as richTextStore } from '../store';

describe( 'registerFormatType', () => {
beforeAll( () => {
Expand All @@ -17,7 +18,7 @@ describe( 'registerFormatType', () => {
} );

afterEach( () => {
select( 'core/rich-text' )
select( richTextStore )
.getFormatTypes()
.forEach( ( { name } ) => {
unregisterFormatType( name );
Expand Down
9 changes: 7 additions & 2 deletions packages/rich-text/src/unregister-format-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
*/
import { select, dispatch } from '@wordpress/data';

/**
* Internal dependencies
*/
import { store as richTextStore } from './store';

/** @typedef {import('./register-format-type').RichTextFormatType} RichTextFormatType */

/**
Expand All @@ -15,14 +20,14 @@ import { select, dispatch } from '@wordpress/data';
* otherwise `undefined`.
*/
export function unregisterFormatType( name ) {
const oldFormat = select( 'core/rich-text' ).getFormatType( name );
const oldFormat = select( richTextStore ).getFormatType( name );

if ( ! oldFormat ) {
window.console.error( `Format ${ name } is not registered.` );
return;
}

dispatch( 'core/rich-text' ).removeFormatTypes( name );
dispatch( richTextStore ).removeFormatTypes( name );

return oldFormat;
}

0 comments on commit bb9ec5e

Please sign in to comment.