-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block API: add more inline comments #20257
Conversation
fbde271
to
e704ff2
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 definitely appreciate this voice, conducive to broad explanations and the offering of a starting point to understanding the blocks API.
However, it does raise interesting question about how and where to accommodate this kind of documentation. In its current form, the language added to ./index.js
may prove immensely useful to one stumbling upon the file, but there's a serendipitous element to that; other devs may instead look for information in ./README.md
(non-existent) or ../../README.md
(too prosaic), for a very general view, or ./parser/README.md
, ./serializer/README.md
for each topic.
Clearly, there are requirements of discoverability, locality and depth to juggle. Avoiding duplication is also important if documentation is to remain current. Can we find a better balance? I don't know if the bulk of the comments in this PR should make up a new packages/blocks/src/api/README.md
, or if they should be broken up by topic, i.e. spread out in ./parser/README.md
, ./serializer/README.md
, etc.
Either way, one file should point to the other(s). As an illustration:
// Serialization is covered extensively in .././path/
export { … } from './serializer';
packages/blocks/src/api/parser.js
Outdated
if ( ! deprecatedDefinitions || ! deprecatedDefinitions.length ) { | ||
return block; | ||
} | ||
|
||
const { originalContent, innerBlocks } = block; | ||
|
||
// By design, blocks lack any sort of version tracking. Instead, to process | ||
// outdated content it operates a queue out of all the defined attribute |
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.
it operates
Who?
packages/blocks/src/api/index.js
Outdated
@@ -1,3 +1,9 @@ | |||
// The Block Type is the most important concept within the block API. It defines | |||
// all aspects of the block configuration and its interfaces (including "edit" | |||
// and "save"). The transforms specification allows converting one block type to |
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.
For consistency with other occurrences, edit and save should be wrapped with back-ticks instead.
packages/blocks/src/api/index.js
Outdated
// blocks mechanism. A child block is a block node that can only exist within | ||
// the inner block boundaries of a specific parent. This allows block authors to | ||
// compose specific block nodes that are not meant to be used outside of a | ||
// specific context. Thus, child blocks extend the concept of inner blocks to |
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 description in terms of block nodes rather than types, though pertinent, may mislead one into understanding the child relationship to be instance-based (dynamically set on the node) rather than class-based (defined in the type).
packages/blocks/src/api/parser.js
Outdated
@@ -617,7 +634,20 @@ const createParse = ( parseImplementation ) => ( content ) => | |||
}, [] ); | |||
|
|||
/** | |||
* Parses the post content with a PegJS grammar and returns a list of blocks. | |||
Utilizes an optimized token-driven parser based on the Gutenberg grammar spec |
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.
Something went wrong with the automated suggestion thing: needs a leading *
.
packages/blocks/src/api/parser.js
Outdated
@@ -404,8 +412,13 @@ export function getMigratedBlock( block, parsedAttributes ) { | |||
*/ | |||
export function createBlockWithFallback( blockNode ) { | |||
const { blockName: originalName } = blockNode; | |||
// The tripartite structure of the block type includes its attributes, inner |
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.
"Tripartite" is a very obscure word; perhaps this should be simplified to "The structure of a block type includes its attributes, inner blocks, and inner HTML."
packages/blocks/src/api/index.js
Outdated
@@ -1,3 +1,9 @@ | |||
// The Block Type is the most important concept within the block API. It defines |
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.
Should "Block Type" be capitalized or not? It isn't elsewhere in these comments.
Any plans to address feedback? Do you need help with this one? |
I need time |
2fcdddb
to
734b142
Compare
Size Change: 0 B Total Size: 1.28 MB ℹ️ View Unchanged
|
Co-Authored-By: Miguel Fonseca <[email protected]>
b97b226
to
b96c1c6
Compare
I found time! |
When reading the source code for the block API there's a patent lack of overview around some key concepts and their relationships that I feel is worth clarifying next to the code.
It also expands a bit more on the role of the PEG parser.