-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Add section to setAttributes documentation about immutability of attributes #12811
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
Conversation
| } | ||
| ``` | ||
|
|
||
| When calling `setAttributes`, it's important that attributes are not mutated in the process of updating them. This is considered bad practice, the core of Gutenberg has been written with the same philosophies as Redux and state is treated as immutable data. It can also cause bugs. Objects and arrays are passed as references in JavaScript, so mutating them can affect other bindings to those references, for example an attribute's default value. |
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 makes a lot of sense to document but I think the lingo might be slightly over the head of many WP developers.
It's obviously good to introduce and use higher level terms so folks can learn and expand their skills, but maybe this can be expanded with some extra context, definitions, etc.?
(This could also link into @mkaz's work on a JS tutorial, so we could point someone to some additional background.)
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.
Thanks for the feedback @chrisvanpatten—I've simplified the text a bit, tried using a simpler vocabulary.
918afba to
6625cfa
Compare
chrisvanpatten
left a comment
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.
Small tweak request (typo and a new link to more reading), then good to merge 👍
docs/designers-developers/developers/block-api/block-edit-save.md
Outdated
Show resolved
Hide resolved
Co-Authored-By: talldan <[email protected]>
662f72c to
712a592
Compare
…ibutes (#12811) * Add section to setAttributes documentation about immutability of attributes * Simplify explanation of immutable attributes * Fix typo and add link to redux's immutability docs Co-Authored-By: talldan <[email protected]>
…ibutes (#12811) * Add section to setAttributes documentation about immutability of attributes * Simplify explanation of immutable attributes * Fix typo and add link to redux's immutability docs Co-Authored-By: talldan <[email protected]>
Description
#10890 raised an issue about side effects caused by mutating attributes. Looking through the docs there wasn't anything covering best practices around the handling of attributes, so I've added a bit to the documentation for
setAttributes.Types of changes
Documentation update
Checklist: