rtCamp/gutenberg-fields-middleware

Why not use the hooks provided by core?

gziolo opened this issue · 3 comments

I had a brief chat with @danielbachhuber and he suggested I open an issue.

It's more a feedback than a call for action. Core provides a few hooks which allow to modify the block which is about to be registered. See: https://wordpress.org/gutenberg/handbook/extensibility/#modifying-blocks-experimental. In particular blocks.registerBlockType might be another way to go. It probably would have to be set with the top priority to make sure it is executed first.

This is an interesting idea, the more plugins like that, the more ideas for the core part to incorporate it by default. Once it is ready, we should see if it is something that would bring expected benefits to a wider audience. In fact, we use a similar approach in core in a few cases. Examples: https://github.com/WordPress/gutenberg/blob/master/blocks/hooks/align.js, which adds align support for the block with supports: align property.

One more important thing to keep in mind. We are looking into moving parts of the block's registration to the server. There are several reasons for doing that and it seems to be very expected by the community. See related issue: WordPress/gutenberg#2751.

Thanks @gziolo for opening the issue. We have just started this project so looking for the best ways to do it. I think using the hook is a great idea and is much better than providing a global object and is also easy for someone registering a block. Implemented this in 5e69104 .

Nice refactoring. With hooks, it should be easier to update all existing plugins to use your middleware.