Skip to content

Commit

Permalink
Polish: make create() easier to read
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Sep 26, 2018
1 parent b750ac9 commit 9a754dc
Show file tree
Hide file tree
Showing 21 changed files with 299 additions and 215 deletions.
10 changes: 5 additions & 5 deletions docs/reference/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo
## 4.2.0

- Writing resolvers as async generators has been removed. Use the controls plugin instead.
- The block attribute source type `node` has been removed. Please use the `children` source type instead with a `multiline` property passing the right tag. See the core quote and list blocks for examples.
- `wp.blocks.node.matcher` has been removed. Please use `wp.blocks.children.matcher` with the `multilineTag` argument instead.
- The block attribute sources `children` and `node` have been removed. Please use the `rich-text-value` source instead. See the core blocks for examples.
- `wp.blocks.node.matcher` has been removed. Please use `wp.richTextValue.create` instead.
- `wp.blocks.node.toHTML` has been removed. Please use `wp.richTextValue.toHTMLString` instead.
- `wp.blocks.node.fromDOM` has been removed. Please use `wp.richTextValue.createValue` instead.
- `wp.blocks.node.fromDOM` has been removed. Please use `wp.richTextValue.create` instead.
- `wp.blocks.children.toHTML` has been removed. Please use `wp.richTextValue.toHTMLString` instead.
- `wp.blocks.children.fromDOM` has been removed. Please use `wp.richTextValue.createValue` instead.
- `wp.blocks.children.fromDOM` has been removed. Please use `wp.richTextValue.create` instead.
- `wp.blocks.children.concat` has been removed. Please use `wp.richTextValue.concat` instead.
- `wp.blocks.children.getChildrenArray` has been removed. Please use `wp.richTextValue.createValue` instead.
- `wp.blocks.children.getChildrenArray` has been removed. Please use `wp.richTextValue.create` instead.

## 4.1.0

Expand Down
4 changes: 2 additions & 2 deletions packages/block-library/src/paragraph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RichText,
} from '@wordpress/editor';
import { getPhrasingContentSchema } from '@wordpress/blocks';
import { createValue, concat } from '@wordpress/rich-text-value';
import { create, concat } from '@wordpress/rich-text-value';

/**
* Internal dependencies
Expand Down Expand Up @@ -198,7 +198,7 @@ export const settings = {
migrate( attributes ) {
return {
...attributes,
content: createValue( attributes.content ),
content: create( { html: attributes.content } ),
};
},
},
Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/preformatted/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
* WordPress
*/
import { __ } from '@wordpress/i18n';
import { children, createBlock, getPhrasingContentSchema } from '@wordpress/blocks';
import { createBlock, getPhrasingContentSchema } from '@wordpress/blocks';
import { RichText } from '@wordpress/editor';
import { createValue } from '@wordpress/rich-text-value';
import { create, concat } from '@wordpress/rich-text-value';

export const name = 'core/preformatted';

Expand Down Expand Up @@ -32,7 +32,7 @@ export const settings = {
blocks: [ 'core/code', 'core/paragraph' ],
transform: ( { content } ) =>
createBlock( 'core/preformatted', {
content: createValue( content ),
content: create( { text: content } ),
} ),
},
{
Expand Down Expand Up @@ -88,7 +88,7 @@ export const settings = {

merge( attributes, attributesToMerge ) {
return {
content: children.concat( attributes.content, attributesToMerge.content ),
content: concat( attributes.content, attributesToMerge.content ),
};
},
};
8 changes: 4 additions & 4 deletions packages/block-library/src/table/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { times } from 'lodash';
/**
* WordPress dependencies
*/
import { createValue } from '@wordpress/rich-text-value';
import { create } from '@wordpress/rich-text-value';

/**
* Creates a table state.
Expand All @@ -23,7 +23,7 @@ export function createTable( {
return {
body: times( rowCount, () => ( {
cells: times( columnCount, () => ( {
content: createValue(),
content: create(),
tag: 'td',
} ) ),
} ) ),
Expand Down Expand Up @@ -89,7 +89,7 @@ export function insertRow( state, {
...state[ section ].slice( 0, rowIndex ),
{
cells: times( cellCount, () => ( {
content: createValue(),
content: create(),
tag: 'td',
} ) ),
},
Expand Down Expand Up @@ -134,7 +134,7 @@ export function insertColumn( state, {
cells: [
...row.cells.slice( 0, columnIndex ),
{
content: createValue(),
content: create(),
tag: 'td',
},
...row.cells.slice( columnIndex ),
Expand Down
56 changes: 28 additions & 28 deletions packages/block-library/src/table/test/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import deepFreeze from 'deep-freeze';
/**
* WordPress dependencies
*/
import { createValue } from '@wordpress/rich-text-value';
import { create } from '@wordpress/rich-text-value';

/**
* Internal dependencies
Expand All @@ -25,23 +25,23 @@ const table = deepFreeze( {
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue(),
content: create(),
tag: 'td',
},
],
},
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue(),
content: create(),
tag: 'td',
},
],
Expand All @@ -54,23 +54,23 @@ const tableWithContent = deepFreeze( {
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue(),
content: create(),
tag: 'td',
},
],
},
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue( 'test' ),
content: create( { text: 'test' } ),
tag: 'td',
},
],
Expand All @@ -92,7 +92,7 @@ describe( 'updateCellContent', () => {
section: 'body',
rowIndex: 1,
columnIndex: 1,
content: createValue( 'test' ),
content: create( { text: 'test' } ),
} );

expect( state ).toEqual( tableWithContent );
Expand All @@ -111,35 +111,35 @@ describe( 'insertRow', () => {
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue(),
content: create(),
tag: 'td',
},
],
},
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue( 'test' ),
content: create( { text: 'test' } ),
tag: 'td',
},
],
},
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue(),
content: create(),
tag: 'td',
},
],
Expand All @@ -163,31 +163,31 @@ describe( 'insertColumn', () => {
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue(),
content: create(),
tag: 'td',
},
],
},
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue( 'test' ),
content: create( { text: 'test' } ),
tag: 'td',
},
{
content: createValue(),
content: create(),
tag: 'td',
},
],
Expand All @@ -211,11 +211,11 @@ describe( 'deleteRow', () => {
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
{
content: createValue( 'test' ),
content: create( { text: 'test' } ),
tag: 'td',
},
],
Expand All @@ -239,15 +239,15 @@ describe( 'deleteColumn', () => {
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
],
},
{
cells: [
{
content: createValue( 'test' ),
content: create( { text: 'test' } ),
tag: 'td',
},
],
Expand All @@ -264,15 +264,15 @@ describe( 'deleteColumn', () => {
{
cells: [
{
content: createValue(),
content: create(),
tag: 'td',
},
],
},
{
cells: [
{
content: createValue( 'test' ),
content: create( { text: 'test' } ),
tag: 'td',
},
],
Expand Down
6 changes: 3 additions & 3 deletions packages/block-library/src/text-columns/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
RichText,
} from '@wordpress/editor';
import deprecated from '@wordpress/deprecated';
import { createValue } from '@wordpress/rich-text-value';
import { create } from '@wordpress/rich-text-value';

export const name = 'core/text-columns';

Expand Down Expand Up @@ -48,10 +48,10 @@ export const settings = {
},
default: [
{
children: createValue(),
children: create(),
},
{
children: createValue(),
children: create(),
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions packages/blocks/src/api/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
* WordPress dependencies
*/
import { createHooks, applyFilters } from '@wordpress/hooks';
import { createValue } from '@wordpress/rich-text-value';
import { create } from '@wordpress/rich-text-value';

/**
* Internal dependencies
Expand Down Expand Up @@ -49,7 +49,7 @@ export function createBlock( name, blockAttributes = {}, innerBlocks = [] ) {
} else if ( schema.hasOwnProperty( 'default' ) ) {
result[ key ] = schema.default;
} else if ( schema.source === 'rich-text-value' ) {
result[ key ] = createValue( null, schema.multiline );
result[ key ] = create();
}

return result;
Expand Down
7 changes: 5 additions & 2 deletions packages/blocks/src/api/matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export { attr, prop, html, text, query } from 'hpq';
/**
* WordPress dependencies
*/
import { createValue } from '@wordpress/rich-text-value';
import { create } from '@wordpress/rich-text-value';

/**
* Internal dependencies
Expand All @@ -22,6 +22,9 @@ export function richTextValue( selector, multilineTag ) {
match = domNode.querySelector( selector );
}

return createValue( match, multilineTag );
return create( {
element: match,
multilineTag,
} );
};
}
4 changes: 2 additions & 2 deletions packages/editor/src/components/block-list/test/block-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { shallow } from 'enzyme';
*/
import { createBlock } from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/block-library';
import { createValue } from '@wordpress/rich-text-value';
import { create } from '@wordpress/rich-text-value';

/**
* Internal dependencies
Expand All @@ -35,7 +35,7 @@ describe( 'BlockHTML', () => {

it( 'use block content for a valid block', () => {
const block = createBlock( 'core/paragraph', {
content: createValue( 'test-block' ),
content: create( { text: 'test-block' } ),
isValid: true,
} );

Expand Down
Loading

0 comments on commit 9a754dc

Please sign in to comment.