-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
[Documentation] add examples for core/blocks
actions
#42637
[Documentation] add examples for core/blocks
actions
#42637
Conversation
Size Change: +266 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
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.
Documenting those actions is tricky as they overlap with similar public APIs exposed from@wordpress/blocks
. I'm still unsure what's the best way to move forward :)
import { useDispatch } from '@wordpress/data'; | ||
|
||
const ExampleComponent = () => { | ||
const { addBlockTypes } = useDispatch( blocksStore ); |
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'm not sure if we should continue promoting this action because the process of registering a block type has more steps, and it's only one of them. I would say it's an internal API that gets executed with registerBlockType
from @wordpress/blocks
.
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.
Might be a good candidate for @ignore
, agreed?
return ( | ||
<Button | ||
onClick={ () => | ||
removeBlockTypes( [ 'core/cover', 'core/heading' ] ) |
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.
Similar to addBlockTypes
this might be treated as an internal API. Technically, it's perfectly fine to use it directly, but it might change with time.
@gziolo I'm starting to think that perhaps any actions that have a corresponding member in the |
Yes, it's very likely you are correct. We would have to check existing docs and code in the repository to confirm that. Well, we can always update recommendations to what you proposed if that makes the most sense. For selectors, we probably should do the opposite and promote using |
…@ignore. Add instructions to the Actions section where to find the apporpriate functions.
@gziolo I've done a pass adding |
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 checked all current actions, and you are correct that all of them are used internally by public APIs from @wordpress/blocks`.
I'm still not 100% sure whether we should completely remove <!-- START TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.js) -->
from the document. All actions are ignored at the moment, but maybe in the future we start using some new actions directly from the store 🤷🏻♂️
The good news is that most of the examples can be used with the public API of @wordpress/blocks
with small editions.
One more thing, I'm curious what do you think about replacing:
Ignored from documentation as it's internal to the data store.
with something like:
Ignored from documentation as the recommended usage for this action through
methodName
from@wordpress/blocks
.
- `Object`: Action object. | ||
|
||
<!-- END TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.js) --> | ||
The actions in this package shouldn't be used directly. Instead, use the functions listed in the public API [here](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-blocks/) |
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.
According to contributing guides https://github.com/WordPress/gutenberg/tree/trunk/docs/contributors/documentation#using-links this link should look as follows:
The actions in this package shouldn't be used directly. Instead, use the functions listed in the public API [here](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-blocks/) | |
The actions in this package shouldn't be used directly. Instead, use the functions listed in the public API [here](/packages/blocks/README.md) |
The rest will magically happen behind the scenes.
@@ -717,231 +717,4 @@ _Returns_ | |||
|
|||
## Actions | |||
|
|||
<!-- START TOKEN(Autogenerated actions|../../../packages/blocks/src/store/actions.js) --> | |||
|
|||
### addBlockCollection |
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.
Used by registerBlockCollection
.
|
||
- `Object`: Action object. | ||
|
||
### addBlockStyles |
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.
Used by registerBlockStyle
.
|
||
- `Object`: Action object. | ||
|
||
### addBlockTypes |
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.
Used indirectly by registerBlockType
.
|
||
- `Object`: Action object. | ||
|
||
### addBlockVariations |
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.
Used by registerBlockVariation
.
|
||
- `Object`: Action object. | ||
|
||
### setDefaultBlockName |
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.
Used by setDefaultBlockName
.
|
||
- `Object`: Action object. | ||
|
||
### setFreeformFallbackBlockName |
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.
Used by setFreeformContentHandlerName
.
|
||
- `Object`: Action object. | ||
|
||
### setGroupingBlockName |
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.
Used by setGroupingBlockName
.
|
||
- `Object`: Action object. | ||
|
||
### setUnregisteredFallbackBlockName |
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.
Used by setUnregisteredTypeHandlerName
.
|
||
- `Object`: Action object. | ||
|
||
### updateCategory |
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.
Used by updateCategory
.
@gziolo I really like this suggestion. It will point those that like to source code dive in the corrected direction. I'll make those updates and revert the removal of the tokens today. |
…on. Revert the removal of the tokens and add the correct link per contribution practices.
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.
This is great. I really like how those docs are shaping the most useful packages from the block developers' perspective.
Let's make sure that examples added previously get transferred with slight editions to the public API methods from @wordpress/blocks
😄
Changed to 'Developer Documentation' (from User Documentation)
|
What?
This PR adds examples for the actions in core/blocks. Part of #42125