How Gutenberg allows others to Register GutenBlocks

Last Updated on June 5, 2019 by Neil Murray

From Sastra Manurung

1. Registering Blocks

I read Gutenberg coding last night and found interesting idea on how they allow addons.

I realize it is similar to our Visual, which also allow addons.

By default, I believe WordPress generates window.wp variable for each post type edit page.

We can see it in the console as screenshot below:

Gutenberg adds additional function/object into window.wp such as blocks, components, etc.

We can see it is added by every file build/index.js found in Gutenberg directory.

They use webpack.config.js to output it.

For example, addon can register their block by using window.wp.blocks.registerBlockType(). 

Further Reading