Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Move ESNext as default code example #23117

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions docs/designers-developers/developers/block-api/block-attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,16 @@ attributes: {
From here, meta attributes can be read and written by a block using the same interface as any attribute:

{% codetabs %}
{% ESNext %}
```js
edit( { attributes, setAttributes } ) {
function onChange( event ) {
setAttributes( { author: event.target.value } );
}

return <input value={ attributes.author } onChange={ onChange } type="text" />;
},
```
{% ES5 %}
```js
edit: function( props ) {
Expand All @@ -198,16 +208,6 @@ edit: function( props ) {
} );
},
```
{% ESNext %}
```js
edit( { attributes, setAttributes } ) {
function onChange( event ) {
setAttributes( { author: event.target.value } );
}

return <input value={ attributes.author } onChange={ onChange } type="text" />;
},
```
{% end %}

### Considerations
Expand Down
132 changes: 66 additions & 66 deletions docs/designers-developers/developers/block-api/block-deprecation.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,64 @@ It's important to note that `attributes`, `supports`, and `save` are not automat
### Example:

{% codetabs %}
{% ES5 %}
{% ESNext %}
```js
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
attributes = {
text: {
type: 'string',
default: 'some random value',
}
};
const { registerBlockType } = wp.blocks;
const attributes = {
text: {
type: 'string',
default: 'some random value',
}
};

registerBlockType( 'gutenberg/block-with-deprecated-version', {

// ... other block properties go here

attributes: attributes,
attributes,

save: function( props ) {
return el( 'div', {}, props.attributes.text );
save( props ) {
return <div>{ props.attributes.text }</div>;
},

deprecated: [
{
attributes: attributes,
attributes,

save: function( props ) {
return el( 'p', {}, props.attributes.text );
save( props ) {
return <p>{ props.attributes.text }</p>;
},
}
]
} );
```
{% ESNext %}
{% ES5 %}
```js
const { registerBlockType } = wp.blocks;
const attributes = {
text: {
type: 'string',
default: 'some random value',
}
};
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
attributes = {
text: {
type: 'string',
default: 'some random value',
}
};

registerBlockType( 'gutenberg/block-with-deprecated-version', {

// ... other block properties go here

attributes,
attributes: attributes,

save( props ) {
return <div>{ props.attributes.text }</div>;
save: function( props ) {
return el( 'div', {}, props.attributes.text );
},

deprecated: [
{
attributes,
attributes: attributes,

save( props ) {
return <p>{ props.attributes.text }</p>;
save: function( props ) {
return el( 'p', {}, props.attributes.text );
},
}
]
Expand All @@ -95,10 +95,9 @@ Sometimes, you need to update the attributes set to rename or modify old attribu
### Example:

{% codetabs %}
{% ES5 %}
{% ESNext %}
```js
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType;
const { registerBlockType } = wp.blocks;

registerBlockType( 'gutenberg/block-with-deprecated-version', {

Expand All @@ -111,8 +110,8 @@ registerBlockType( 'gutenberg/block-with-deprecated-version', {
}
},

save: function( props ) {
return el( 'div', {}, props.attributes.content );
save( props ) {
return <div>{ props.attributes.content }</div>;
},

deprecated: [
Expand All @@ -124,22 +123,23 @@ registerBlockType( 'gutenberg/block-with-deprecated-version', {
}
},

migrate: function( attributes ) {
migrate( { text } ) {
return {
content: attributes.text
content: text
};
},

save: function( props ) {
return el( 'p', {}, props.attributes.text );
save( props ) {
return <p>{ props.attributes.text }</p>;
},
}
]
} );
```
{% ESNext %}
{% ES5 %}
```js
const { registerBlockType } = wp.blocks;
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType;

registerBlockType( 'gutenberg/block-with-deprecated-version', {

Expand All @@ -152,8 +152,8 @@ registerBlockType( 'gutenberg/block-with-deprecated-version', {
}
},

save( props ) {
return <div>{ props.attributes.content }</div>;
save: function( props ) {
return el( 'div', {}, props.attributes.content );
},

deprecated: [
Expand All @@ -165,14 +165,14 @@ registerBlockType( 'gutenberg/block-with-deprecated-version', {
}
},

migrate( { text } ) {
migrate: function( attributes ) {
return {
content: text
content: attributes.text
};
},

save( props ) {
return <p>{ props.attributes.text }</p>;
save: function( props ) {
return el( 'p', {}, props.attributes.text );
},
}
]
Expand All @@ -191,16 +191,19 @@ E.g: a block wants to migrate a title attribute to a paragraph innerBlock.
### Example:

{% codetabs %}
{% ES5 %}
{% ESNext %}
```js
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
omit = lodash.omit;
const { registerBlockType } = wp.blocks;
const { omit } = lodash;

registerBlockType( 'gutenberg/block-with-deprecated-version', {

// ... block properties go here

save( props ) {
return <p>{ props.attributes.title }</p>;
},

deprecated: [
{
attributes: {
Expand All @@ -211,38 +214,36 @@ registerBlockType( 'gutenberg/block-with-deprecated-version', {
},
},

migrate: function( attributes, innerBlocks ) {
migrate( attributes, innerBlocks ) {
return [
omit( attributes, 'title' ),
[
createBlock( 'core/paragraph', {
content: attributes.title,
fontSize: 'large',
} ),
].concat( innerBlocks ),
...innerBlocks,
],
];
},

save: function( props ) {
return el( 'p', {}, props.attributes.title );
save( props ) {
return <p>{ props.attributes.title }</p>;
},
}
]
} );
```
{% ESNext %}
{% ES5 %}
```js
const { registerBlockType } = wp.blocks;
const { omit } = lodash;
var el = wp.element.createElement,
registerBlockType = wp.blocks.registerBlockType,
omit = lodash.omit;

registerBlockType( 'gutenberg/block-with-deprecated-version', {

// ... block properties go here

save( props ) {
return <p>{ props.attributes.title }</p>;
},

deprecated: [
{
attributes: {
Expand All @@ -253,21 +254,20 @@ registerBlockType( 'gutenberg/block-with-deprecated-version', {
},
},

migrate( attributes, innerBlocks ) {
migrate: function( attributes, innerBlocks ) {
return [
omit( attributes, 'title' ),
[
createBlock( 'core/paragraph', {
content: attributes.title,
fontSize: 'large',
} ),
...innerBlocks,
],
].concat( innerBlocks ),
];
},

save( props ) {
return <p>{ props.attributes.title }</p>;
save: function( props ) {
return el( 'p', {}, props.attributes.title );
},
}
]
Expand Down
Loading