-
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
Validate usable render behavior on registered block #362
Comments
Having blocks with no settings seems to be a viable case in the tests are we changing that assumption? |
After having spoken with @mtias , it seems there's a desire that:
It's quite possible other tests may need to be updated to reflect this behavior. * Per #401, we may want to change these method names to be more descriptive. Do you have any opinions on this? |
In the branch I have going, both are being forced.
Yeah... lots of impact on other modules currently. If everyone is open to some changes, I would like to change the API slightly to be a bit more flexible, moving into the future.
forEditing(), and forSaving() sound better to me and I think improve readability. Maybe .editView() and .view()? The output of |
Improvements are always welcome 😄 |
Fixes #362. Validates that a block has a `save()` and `edit()`. This is probably a temporary solution. The API should probably be cleaned up a bit so everything is not quite as coupled and tests can be done differently.
Is this definitely a good first task? Would like to see where I can help on this one. First thoughts would be to add basic type checking of the two properties in |
That sounds like a good path to head down. In this case it's not already been done because it's not actively harming anything aside from being more flexible than we care for it to be. There's some precedent of validation: gutenberg/blocks/api/registration.js Lines 35 to 52 in 740b93d
See also: #508 @BE-Webdesign , given you'd assigned this to yourself but haven't had a chance to circle back around, would you mind if @njpanderson were to take it on? |
Nope. I can unassign myself as well. I was planning on doing this at some point, but if someone wants to do it right now all the better. |
Right, thanks guys. Will give it a go :) |
Ok, I've got two branches on the go currently, so I'll explain what's what: update/stricter-block-validationThis is a basic update to try/prop-based-block-validationThis is a little more involved and at a very rough and ready stage right now. It's an adapted version of a "PropType" style validator I wrote for another library. I've not taken it too far just in case you all decide it's not worth pursuing. The idea is slightly different in this one: You define an ideal set of variables and their required attributes, as well as the actual variable values. This specification is sent to a It's pretty generic and in theory could be used anywhere in the project that there is a list of required variables and their types. Let me know what you think and whether or not I should continue working on that second branch. |
@njpanderson I checked the branches out. Great work! For now I think stricter-block-validation would be good. prop-based-block-validation is also great, I am not sure whether we are going to introduce block schemas quite yet. We will probably eventually need schemas and want to have some synergy between the server-side and client-side schemas, which will probably lead to the adoption of JSON Schema validation. |
Fair enough. I'll keep my try/ branch on my own repo just for now and have PR'ed the update/ branch. Thanks! |
Maybe this has been discussed before, and it's also being discussed on the PHP side in #1321 (PR #1322): should there not be a |
That would be quite a major refactoring of existing code from my perspective but definitely something I would be willing to take on. One potential downside to extending an existing class might be that the Should a new issue be started for it either way? |
@westonruter Why would the class be better? ES5 support has been the deterring factor for me. Supporting both forms is similarly a negative in my view, as more options muddies communication. Related previous conversation with @nb: #1135 (comment) |
Please no ES6 classes. |
It took us several years to figure out that inheritance was a bad practice, let's stick with composition and functions, please. |
closing as fixed by #1345 |
When registering a block, we should ensure that it has at minimum a
save
implementation (front-end UI representation) and optionallyedit
.Once validated, we can collapse logic here to return early only on
settings
being falsey and assume if settings exist that aedit
orsave
function/component can be used for displaying the block:https://github.com/WordPress/gutenberg/blob/15db036/editor/editor/mode/visual.js#L25-L32
The text was updated successfully, but these errors were encountered: