-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
iAPI Docs: The first three Core Concepts guides #63759
iAPI Docs: The first three Core Concepts guides #63759
Conversation
@luisherranz "we" is not explicitly forbidden, but its use is discouraged. In the case we want to use it, we should specify who "we" means ("the group of contributors that worked on this feature" for example) At Style Guide / Language and grammar / Grammatical person, it states
Also at Core Handbook / Best Practices / Post & Comment Guidelines > Style and Substance it states
|
Sure! I'll have a look at it this week. |
@luisherranz I have committed some changes to this PR to properly add a new subsection in the docs. Basically, we need to add the new structure to |
Flaky tests detected in 9f59f16. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10367917253
|
|
||
### Can you spot the bug? | ||
|
||
In the imperative example, we intentionally introduced a bug. Can you find it? It's not easy! |
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 think it's fine as it is, but to avoid the use of "we" in the docs, maybe we can say here:
In the imperative example, a bug has been intentionally introduced for didactical purposes. Can you find it? It's not easy!
<details> | ||
<summary>Show me the answer!</summary> | ||
|
||
In the case that the Show button is pressed first, then the Activate button, and finally the Hide button, we forgot to add the `inactive` class using `statusParagraph.classList.add('inactive');`. Therefore, the next time the user presses Show, the paragraph will not appear in red. |
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.
Again, nothing critical, but to avoid the use of "we" in the docs, maybe we can say here:
In the case that the Show button is pressed first, then the Activate button, and finally the Hide button, there's a missing step in the previous code for adding the
inactive
class usingstatusParagraph.classList.add('inactive');
. Therefore, the next time the user presses Show, the paragraph will not appear in red.
|
||
5. **Automatic Updates**: When the state or context changes (through actions), the Interactivity API automatically updates all parts of the DOM that depend on that state (or derived state). | ||
|
||
Let's break down these concepts with an example from the code we've seen: |
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.
Another suggestion to avoid the use of "we"
Let's break down these concepts with an example (adapted from the declarative code example above):
|
||
## Understanding Reactivity | ||
|
||
The Interactivity API is a declarative framework thanks to its leverage of reactivity. In a reactive system, changes to the data automatically trigger updates in the user interface, ensuring that the view always reflects the current state of the application. |
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.
Maybe we can link this concept to the Block Editor, which uses central Stores to manage state: The Block Editor dynamically responds to state changes, updating the DOM through React components that represent individual blocks.
Great job @luisherranz! I enjoyed reading this guide 🙌 |
…derived-state' into iapi-docs-the-reactive-and-declarative-mindset
…ctive-and-declarative-mindset
7daf260
to
5e7d70c
Compare
I have merged the guide for "Understanding Global State, Local Context, and Derived State" into this pull request, and I have also added the guide for "Server-Side Rendering". This way we can review all three to ensure they are consistent with each other and merge them together once they are ready. |
@luisherranz I have added the |
…rative-mindset' into iapi-docs-the-reactive-and-declarative-mindset
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. |
The three guides are ready for review. |
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 help a lot of folks, including myself. Well written. Honestly, I'm not sure I'll ever feel confident explaining the differences between imperative and declarative, but it makes sense when I read about it (mostly).
I left one small suggestion. Thanks!
docs/reference-guides/interactivity-api/core-concepts/README.md
Outdated
Show resolved
Hide resolved
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 overlooked expanding some diffs to read in my first review, and took another pass with a few more suggestions.
This is so helpful, well written, and will help many developers understand these core concepts. Thank you!
docs/reference-guides/interactivity-api/core-concepts/server-side-rendering.md
Outdated
Show resolved
Hide resolved
} ); | ||
``` | ||
|
||
To fix this issue, you can use the `wp_interactivity_state` function to serialize the translated mango string and then access that value in your action. |
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.
Love this! Amazing! 👏
...interactivity-api/core-concepts/undestanding-global-state-local-context-and-derived-state.md
Outdated
Show resolved
Hide resolved
...interactivity-api/core-concepts/undestanding-global-state-local-context-and-derived-state.md
Outdated
Show resolved
Hide resolved
|
||
This lack of distinction is intentional, allowing developers to consume both derived and global state uniformly, and making them interchangeable in practice. | ||
|
||
You can also access the derived state from another derived state and, thus, create multiple levels of computed values. |
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 made my head explode 🤯 Not your fault though and just because you're blowing my mind. 😆
Co-authored-by: Damon Cook <[email protected]>
Thank you @colorful-tones for the review and corrections! And thanks @juanmaguitar for the review and approval! Let's merge this now so that we can publish the guides and if we need to improve them, we can do so in subsequent PRs 🙂 |
* Initial version * Convert all tabs to spaces (except in non-PHP code snippets) * Initial SSR guide version * Initial version * Changes to properly add a subsection in the docs * Reorganize headers a bit * Add titles (are they necessary?) * Reorganize SSR sections * Use async handlers and update state/context guide * Finish review of the Declarative/reactive guide * Remove last "we's" * added manifest and toc data and intro to guides * Final revision * Fix typos Co-authored-by: Damon Cook <[email protected]> --------- Co-authored-by: luisherranz <[email protected]> Co-authored-by: juanmaguitar <[email protected]> Co-authored-by: colorful-tones <[email protected]>
EDIT: Initially, in this pull request, I only included the guide "the reactive and declarative mindset". But now, I have included the three guides to merge and review them simultaneously to ensure they are consistent with each other.
What?
These are the first guides of the Core Concepts section of the Interactivity API, which aims to explain the concepts of:
Why?
The Interactivity API would benefit from some guides that explain the concepts and mental models, not just from the API references.
How?
I added a file to a new folder called
core-concepts
, but I'm not really sure how to structure this.@juanmaguitar, can you give me a hand? 🙂
On the other hand, I would still like to add a section to the guide with examples of what people should not do (such as mutating the DOM within an action) and the exceptions (such as removing or adding a class to the
body
element).I think I've also used
we
in some places, and I shouldn't have. @juanmaguitar, can you confirm this for me as well?