Skip to content
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

Idea for block registry. #336

Closed
BE-Webdesign opened this issue Mar 27, 2017 · 2 comments
Closed

Idea for block registry. #336

BE-Webdesign opened this issue Mar 27, 2017 · 2 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Question Questions about the design or development of the editor.

Comments

@BE-Webdesign
Copy link
Contributor

Hi, just throwing out some ideas on the block registering API.

  1. Currently block types are created via wp.blocks.registerBlock( slug, settings ) which returns the block and also adds the block as a key, value pair to the somewhat global blocks. This is a coupling that I do not think should be made. I would recommend the creation of a block to be handled in a function blockType( slug, settings ) ( or preferably just settings ). Then the registry of blocks can be another factory function that creates registries of blocks, which can have the method registerBlock( block ) on them.

This will make testing a lot easier/cleaner and will also create a bit more flexibility in the code for unforeseen future needs.

@mtias mtias added [Feature] Block API API that allows to express the block paradigm. [Type] Question Questions about the design or development of the editor. labels Mar 28, 2017
@nylen
Copy link
Member

nylen commented Mar 28, 2017

One drawback of this approach for clients would be that it's no longer possible to register a block in a single function call.

It looks like the proposed blockType function would either be Object.assign (or nothing, if the slug is included in the settings). Maybe with some validation logic, but this validation would also need to be repeated inside registerBlock.

Given that, it's hard for me to see the advantages of pulling this operation out into two functions.

@BE-Webdesign
Copy link
Contributor Author

One drawback of this approach for clients would be that it's no longer possible to register a block in a single function call.

Yup, definitely. I was thinking in the future there may come a point where two instances of the editor may need exist and will need to have different blockTypes registered to them. So for now we can probably close this out. It can be done then, if it is ever needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

3 participants