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

Update getContext() usage examples with namespace argument #63411

Conversation

dhananjaykuber
Copy link
Contributor

@dhananjaykuber dhananjaykuber commented Jul 11, 2024

Fixes #63366

What?

This PR updates the documentation for the getContext() function to separate usage examples with and without namespace arguments. It provides clear, distinct examples and explanations for each case.

Why?

This PR addresses the need for clearer documentation on how to use the getContext() function both with and without the optional namespace argument. It helps developers understand the different use cases and how to retrieve specific parts of the context, improving the overall usability and clarity of the documentation.

How?

Adding a section for using getContext(namespace) with a namespace argument.

Copy link

github-actions bot commented Jul 11, 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: dhananjaykuber <dhananjaykuber@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: juanmaguitar <juanmaguitar@git.wordpress.org>

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

Copy link
Member

@fabiankaegy fabiankaegy left a comment

Choose a reason for hiding this comment

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

Thanks for adding these docs! :)

What you have written at the moment is not how the API is working however.

The namespace you pass to the getContext function needs to be the namespace of an interactive region (data-wp-interactive).

So in this case you would want to use getContext("myPlugin")

And the getContext function always gets the entire context object. There is no helper function to only get part of a context.

@fabiankaegy fabiankaegy added [Type] Developer Documentation Documentation for developers [Feature] Interactivity API API to add frontend interactivity to blocks. labels Jul 11, 2024
@dhananjaykuber
Copy link
Contributor Author

Hi @fabiankaegy,

Thank you for your feedback. I have updated the documentation to reflect the correct usage of the getContext function with the namespace of an interactive region (data-wp-interactive). Can you please review it once more to ensure everything is accurate?

Copy link
Member

@fabiankaegy fabiankaegy left a comment

Choose a reason for hiding this comment

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

Left one minor suggestion :) Otherwise this looks great 👍

Thanks for updating it :)

docs/reference-guides/interactivity-api/api-reference.md Outdated Show resolved Hide resolved
Co-authored-by: Fabian Kägy <mail@fabian-kaegy.de>
@fabiankaegy fabiankaegy enabled auto-merge (squash) July 11, 2024 12:04
@fabiankaegy fabiankaegy merged commit 0b54ea4 into WordPress:trunk Jul 11, 2024
58 checks passed
@github-actions github-actions bot added this to the Gutenberg 18.9 milestone Jul 11, 2024
carstingaxion pushed a commit to carstingaxion/gutenberg that referenced this pull request Jul 18, 2024
…tivity API Documentation (WordPress#63411)

Co-authored-by: dhananjaykuber <dhananjaykuber@git.wordpress.org>
Co-authored-by: fabiankaegy <fabiankaegy@git.wordpress.org>
Co-authored-by: juanmaguitar <juanmaguitar@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
2 participants