Skip to content
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

Merged
merged 17 commits into from
Aug 19, 2024

Conversation

luisherranz
Copy link
Member

@luisherranz luisherranz commented Jul 19, 2024

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:

  1. The reactive and declarative mindset.
  2. Understanding global state, local context, and derived state.
  3. Server-side rendering: How directives are processed on the server.

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?

@luisherranz luisherranz added [Type] Developer Documentation Documentation for developers [Feature] Interactivity API API to add frontend interactivity to blocks. labels Jul 19, 2024
@luisherranz luisherranz self-assigned this Jul 19, 2024
@juanmaguitar
Copy link
Contributor

juanmaguitar commented Jul 23, 2024

I think I've also used we in some places, and I shouldn't have. @juanmaguitar, can you confirm this for me as well?

@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

Second person
In general, use second person in your documentation. Second person depicts a friendly tone, with a perfect focus on the reader. In addition to this, directly addressing the reader helps avoid passive voice; thereby preventing unwanted confusion.

First person
Use first person (I, we) only when absolutely needed. First person may be used in quotes, direct references, and personifications. First person plurals such as we and our may intimidate the reader in some cases. Try to avoid first person plurals, but be cautious if you’re using them.

Also at Core Handbook / Best Practices / Post & Comment Guidelines > Style and Substance it states

Similarly, the word “we” should be avoided in posts, unless its made very clear which group is speaking. An example of this is listing attendees of a meeting and, in the summary post, noting that “we, those present at the meeting” made a decision or agreed on a plan of action.

@juanmaguitar
Copy link
Contributor

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? 🙂

Sure! I'll have a look at it this week.

@juanmaguitar
Copy link
Contributor

I think this PR tackles this issue #63524
cc: @WPLake

@juanmaguitar
Copy link
Contributor

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?

@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 docs/toc.json and then run npm run docs:gen to generate an updated version of docs/manifest.json. I also included a README.md to introduce this new Core Concepts section

Copy link

github-actions bot commented Jul 24, 2024

Flaky tests detected in 9f59f16.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10367917253
📝 Reported issues:


### Can you spot the bug?

In the imperative example, we intentionally introduced a bug. Can you find it? It's not easy!
Copy link
Contributor

@juanmaguitar juanmaguitar Jul 24, 2024

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.
Copy link
Contributor

@juanmaguitar juanmaguitar Jul 24, 2024

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 using statusParagraph.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:
Copy link
Contributor

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.
Copy link
Contributor

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.

@juanmaguitar
Copy link
Contributor

juanmaguitar commented Jul 24, 2024

Great job @luisherranz! I enjoyed reading this guide 🙌
I think it addresses Reactivity and Declarative code very well, two essential ideas to really understand the iAPI approach for adding interactivity in the Frontend (and why it's a good approach).
I left some minor comments, but I think it is not far from being ready to be published as this PR will "inaugurate" this new section and will provide value to iAPI users already.

@luisherranz luisherranz force-pushed the iapi-docs-the-reactive-and-declarative-mindset branch from 7daf260 to 5e7d70c Compare August 9, 2024 14:28
@luisherranz luisherranz changed the title iAPI Docs: The Reactive and Declarative Mindset iAPI Docs: The first three Core Concepts guides Aug 9, 2024
@luisherranz
Copy link
Member Author

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.

@juanmaguitar
Copy link
Contributor

@luisherranz I have added the manifest data (required to have this new structure of docs properly reflected on the BEH sidebar). I also added an introduction to these new guides at core-concepts/README

…rative-mindset' into iapi-docs-the-reactive-and-declarative-mindset
@luisherranz luisherranz marked this pull request as ready for review August 13, 2024 10:18
Copy link

github-actions bot commented Aug 13, 2024

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@luisherranz
Copy link
Member Author

The three guides are ready for review.

Copy link
Member

@colorful-tones colorful-tones left a 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!

Copy link
Member

@colorful-tones colorful-tones left a 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!

} );
```

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this! Amazing! 👏


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.
Copy link
Member

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. 😆

@juanmaguitar juanmaguitar self-requested a review August 17, 2024 09:18
Co-authored-by: Damon Cook <colorful-tones@users.noreply.github.com>
@luisherranz
Copy link
Member Author

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 🙂

@luisherranz luisherranz enabled auto-merge (squash) August 19, 2024 10:07
@luisherranz luisherranz merged commit ade27ac into trunk Aug 19, 2024
60 checks passed
@luisherranz luisherranz deleted the iapi-docs-the-reactive-and-declarative-mindset branch August 19, 2024 10:40
@github-actions github-actions bot added this to the Gutenberg 19.1 milestone Aug 19, 2024
bph pushed a commit to bph/gutenberg that referenced this pull request Aug 31, 2024
* 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 <colorful-tones@users.noreply.github.com>

---------

Co-authored-by: luisherranz <luisherranz@git.wordpress.org>
Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org>
Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Interactivity API API to add frontend interactivity to blocks. [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants