-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 and API: clarify naming around block registration #842
Conversation
a76d104
to
f057ac5
Compare
blocks/api/factory.js
Outdated
const blockSettings = getBlockSettings( blockType ); | ||
|
||
// Do we need this? What purpose does it have? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create a separate issue for this. I think our current use-cases don't really need it as much as it seems they would.
I like More characters, but in my opinion best phrasing to indicate working with the "blueprint" of a block. We'd probably want to be consistent with variable assignment too. |
This is exactly how I've been thinking about the instance vs blueprint/prototype of a block. I prefer the explicit naming of a type vs. instance though, so would go for I really don't like |
Yeah, "type" vocabulary is growing on me. I think I didn't like the distinction between registerBlockType( 'core/text', {} );
const blockTypes = getBlockTypes();
const blockType = getBlockType( 'core/text' ); |
Yes. `registerBlockType` came up in another conversation. I'm all for that
:)
…On Wed, 24 May 2017, 13:54 Andrew Duthie, ***@***.***> wrote:
Yeah, "type" vocabulary is growing on me. I think I didn't like the
distinction between registerBlock and getBlockTypes, but maybe if we were
to name it registerBlockType ?
registerBlockType( 'core/text', {} );const blockTypes = getBlockTypes();const blockType = getBlockType( 'core/text' );
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#842 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AANIIrFsyA2B0V88NJ8QQbFqKhjEhJQ6ks5r9ChngaJpZM4NggZR>
.
|
9d3a410
to
f60793a
Compare
blockSettings = getBlockSettings( blockType ); | ||
export function createBlockWithFallback( name, rawContent, attributes ) { | ||
// Use type from block content, otherwise find unknown handler. | ||
name = name || getUnknownTypeHandler(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to standardize on name
vs. slug
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it to be clearer (slug usually not including slashes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a few instances where we're already using slug
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm fine with cleaning up later.
blocks/README.md
Outdated
@@ -146,7 +146,7 @@ Registers a new block-level control. Controls appear in a block's toolbar when i | |||
|
|||
Inline controls for [`Editable`](#editable) elements are identical for every block and cannot be modified. | |||
|
|||
### `wp.blocks.getBlockSettings( slug: string )` | |||
### `wp.blocks.getBlockType( slug: string )` | |||
|
|||
Returns settings associated with a registered block. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings? :)
I'm conflicted on this. What do we name the second argument to registerBlockType
? Currently it's still settings
. The "type" terminology doesn't apply as well. Maybe something more akin to "type definition", or configuration.
blocks/api/factory.js
Outdated
* @param {Object} attributes Block attributes | ||
* @return {Object} Block object | ||
*/ | ||
export function createBlock( blockType, attributes = {} ) { | ||
const blockSettings = getBlockSettings( blockType ); | ||
export function createBlock( blockName, attributes = {} ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think blockName
should remain blockType
. Where you can interpret the value to be the ID of the blockType. (ignore this comment as I didn't read further down to realize that would be a catastrophe 😱 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually maybe typeOfBlock
then you can keep the new changes. That is what the string value is.
blocks/api/factory.js
Outdated
const blockSettings = getBlockSettings( blockType ); | ||
export function createBlock( blockName, attributes = {} ) { | ||
// Get the type definition associated with a registered block. | ||
const blockType = getBlockType( blockName ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of the PR is precisely to use blockType
as the bespoke "prototype" or type description of the block, not the name, not the block instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, you can disregard most of my comments as this is fine. It was somewhat confusing to me at first.
073ca2b
to
11ac2a2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried testing everything. LGTM 👍
Thanks! |
Nice one 👍 |
There is some confusion around block instances as consumed in the editor and the registration API. We have two functions for
getBlocks
that return different things.At the same time, we are keeping the block definition behind a getter like
getBlockSettings
where it is not immediately clear what the return value would be. (i.e. we return thesave
andedit
render methods there.)These are mainly relevant internally, but still important to be as clear as possible.
I propose we do one of the following:
/registration.js
:getRegisteredBlock( name )
replacesgetBlockSettings( slug )
./registration.js
: renamegetBlocks
togetRegisteredBlocks
.Or...
/registration.js
:getBlockType( name )
replacesgetBlockSettings( slug )
./registration.js
: renamegetBlocks
togetBlockTypes
.When retrieving settings and using them: