-
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
Include an example of blocks.getSaveElement
use
#8470
Conversation
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.
This sort of usage (and in fact, the filter itself) may be something to discourage, as if the plugin is ever to later to be deactivated, the user will be presented with the "Modified Externally" warning, since the attribute would be destroyed on subsequent re-saves.
At minimum, we should be very clear about this caution, or avoid documenting getSaveElement
altogether.
Related #6878 (comment)
Updated in f2f1c56 |
if ( ! attributes.myCustomAttribute.length ) { | ||
return element; | ||
} | ||
// Modifying nested JavaScript objects is pretty awful. |
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.
- This should probably be using
cloneElement
to override props - Deep object assignment can be improved by using
_.merge
instead
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.
Can you provide an example?
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.
// Bad:
return _.assign( {}, element, { myprop: 'foo' } );
// Good:
return wp.element.cloneElement( element, { myprop: 'foo' } );
element = lodash.assign( {}, element, { | ||
props: lodash.assign( {}, element.props, { | ||
children: [ | ||
lodash.assign( {}, element.props.children[0], { |
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.
This will not assign data-custom-attribute
when the image is assigned a URL. The deep override should be a signal of its fragility.
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 don't follow this either. Can you explain further?
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.
The markup shape changes depending on whether the image block has a url
attribute assigned.
Aside: It's maybe telling that this is an easy thing to overlook.
I probably won't have time to pick this back up this week, so assigning to myself to clean up early next. |
Are you able to resume work here? |
I haven't been able to come back to this yet. The project work is still on my todo list though, so I'll pick up the documentation when I'm back on the project. |
Happened to need this for my project so thought I'd add example for this... Old PR WordPress#8470
No description provided.