-
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
Block Bindings: Create utils for block bindings #62063
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +623 B (+0.04%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
|
||
const { setAttributes } = props; | ||
const boundAttributes = useSelect( () => { | ||
return getBoundAttributesValues( clientId, context, registry ); |
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.
Why is this a reusable function if it's only used once? I also don't really like this, it becomes unclear what store this is selecting from.
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.
It was meant to be used in other places like allow editing of post meta, but we changed the approach there so it is not reused anymore. See related comment.
export function getBoundAttributesValues( clientId, blockContext, registry ) { | ||
const attributes = registry | ||
.select( blockEditorStore ) | ||
.getBlockAttributes( clientId ); |
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.
You sneaked in a block editor store subscription here for every block, which will impact performance. Why not use the attributes prop?
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 tried to avoid passing attributes
as a parameter, but I think it makes sense then.
The PR title/description makes its sound like this is just moving code, but it's not? |
It was the intention, but I wasn't fully aware of the implications 😄 Anyway, this pull request was meant to create a reusable function to transform the attributes not only in the Edit hook but in other places if wanted. I thought it was needed for the pull request to allow editing of post meta in bindings, but it isn't with the new approach there. I am marking it as draft again because I believe it could still be valuable something like that but there are some uncertainties we would need to explore deeper. Happy to close and reopen if you prefer. |
Is it still actionable? It looks like an alternative approach are being explored, example: |
I will close this and reopen it if consider necessary. |
What?
I'm creating a new
bindings
util file to store all the reusable functions instead of having it in the editor hook. As part of that, I'm abstracting the logic to change the block attributes with the bindings values into a function.Why?
It looks cleaner this way and we can reuse the same logic to replace the block attributes in the future.
How?
Just creating a new file and creating a new
transformBlockAttributesWithBindingsValues
function to replace the block attributes with bindings.Testing Instructions
Tests should pass. We are not adding new functionalities.