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 wordpress/data documentation in order to prefer store object instead of store name to access the store #41210

Merged
merged 5 commits into from
Jun 30, 2022

Conversation

renatho
Copy link
Contributor

@renatho renatho commented May 20, 2022

What?

It updates part of the documentation (@wordpress/data) to use store object instead of store names when accessing the stores through the select and dispatch functions.

Why?

It's a new standard. The other way should be considered as a legacy way only for backward compatibility.

Next

There are many other documentation pages still using store names that we should also update.

@renatho renatho requested a review from nerrad as a code owner May 20, 2022 20:09
@@ -481,7 +485,7 @@ _Usage_
```js
import { dispatch } from '@wordpress/data';

dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );
dispatch( store ).setPrice( 'hammer', 9.75 );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this documentation page starts creating a store with the name store, I think it's intuitive that this is the store, right? I didn't want to add imports in these cases because we don't have file names and I think it could make it confusing.

Copy link
Member

Choose a reason for hiding this comment

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

it might be clearer if we do have an import, since actual code doing this will have to have the import as well. we can try and make the filename something that's obviously example code:

import { dispatch } from '@wordpress/data';
import { store as myCustomStore } from 'my-custom-store';

dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );

Copy link
Member

Choose a reason for hiding this comment

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

By the way the descriptions of these functions are generated from the actual code. Instead of editing it here we need to edit it in the source, which for this one is data/src/index.js.

Otherwise this change will be wiped out the next time someone makes a change to the source file and it will be confusing.

Copy link
Member

Choose a reason for hiding this comment

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

It would be worth updating the description of the above-mentioned source file (data/src/index.js) because it shouldn't say "Given the name of a registered store" but should say something like "Given a store descriptor returns an object of…(also supports legacy calling convention accepting the name of a registered store)."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dmsnell, thank you for the great suggestions! I applied them and I updated the documentation with npm run docs:build.

2e3fabd

It would be worth updating the description of the above-mentioned source file (data/src/index.js) because it shouldn't say "Given the name of a registered store" but should say something like "Given a store descriptor returns an object of…(also supports legacy calling convention accepting the name of a registered store)."

a79b8a7

@@ -481,7 +485,7 @@ _Usage_
```js
import { dispatch } from '@wordpress/data';

dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );
dispatch( store ).setPrice( 'hammer', 9.75 );
Copy link
Member

Choose a reason for hiding this comment

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

it might be clearer if we do have an import, since actual code doing this will have to have the import as well. we can try and make the filename something that's obviously example code:

import { dispatch } from '@wordpress/data';
import { store as myCustomStore } from 'my-custom-store';

dispatch( myCustomStore ).setPrice( 'hammer', 9.75 );

@@ -481,7 +485,7 @@ _Usage_
```js
import { dispatch } from '@wordpress/data';

dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );
dispatch( store ).setPrice( 'hammer', 9.75 );
Copy link
Member

Choose a reason for hiding this comment

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

By the way the descriptions of these functions are generated from the actual code. Instead of editing it here we need to edit it in the source, which for this one is data/src/index.js.

Otherwise this change will be wiped out the next time someone makes a change to the source file and it will be confusing.

@@ -481,7 +485,7 @@ _Usage_
```js
import { dispatch } from '@wordpress/data';

dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 );
dispatch( store ).setPrice( 'hammer', 9.75 );
Copy link
Member

Choose a reason for hiding this comment

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

It would be worth updating the description of the above-mentioned source file (data/src/index.js) because it shouldn't say "Given the name of a registered store" but should say something like "Given a store descriptor returns an object of…(also supports legacy calling convention accepting the name of a registered store)."

@renatho renatho force-pushed the update/wordpress-data-documentation branch from 7bb1010 to a79b8a7 Compare May 20, 2022 21:55
@renatho renatho requested a review from dmsnell May 20, 2022 21:58
* The selector functions are been pre-bound to pass the current state automatically.
* Given a store descriptor (also supports legacy calling convention accepting the name of a
* registered store), returns an object of the store's selectors. The selector functions are
* been pre-bound to pass the current state automatically.
Copy link
Member

@dmsnell dmsnell May 20, 2022

Choose a reason for hiding this comment

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

given that we want to discourage use of passing the string I feel like we could de-emphasize explaining the legacy usage and move it either to the end of the description here, or as an additional note inside the JSDoc area

/**
 * Given a store descriptor returns an object of the store's selectors.
 * The selector functions are pre-bound to pass the current state automatically.
 *
 * Note: The legacy calling convention of passing the store name is also supported.
 *
 * @example
 * …
 */

Same applies for all these case, but take my suggestion with a grain of salt. Others might feel differently.

Copy link
Contributor Author

@renatho renatho May 23, 2022

Choose a reason for hiding this comment

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

I updated it to add the explanation of the param in the JSDoc param. And I also updated the type to StoreDescriptor|string instead of string|StoreDescriptor. WDYT?

973c18a

Copy link
Member

Choose a reason for hiding this comment

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

thanks for rearranging those types. although it doesn't change anything from a TypeScript parameter, I do think you made it clearer still, and I had almost suggested it but didn't want to bog down this change.

@gziolo gziolo added [Type] Developer Documentation Documentation for developers [Package] Data /packages/data labels May 21, 2022
Copy link
Member

@dmsnell dmsnell left a comment

Choose a reason for hiding this comment

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

Seems like an overall positive move for the documentation. I'm sure we can continue to improve it, but this is good enough to be clearer than what we have IMO.

cc: @jsnajdr since you also have worked on these.

@renatho
Copy link
Contributor Author

renatho commented Jun 2, 2022

Hey folks! Should we go ahead and merge this?

@renatho
Copy link
Contributor Author

renatho commented Jun 29, 2022

Hey folks! 👋
I don't have the authorization to merge this PR. I'd appreciate it if someone could do that to update the documentation. 🙂

@dmsnell
Copy link
Member

dmsnell commented Jun 30, 2022

Sorry @renatho I missed that you couldn't merge. Can you rebase to trigger test runs again? Looks like a flakey test falsely failed this.

@renatho renatho force-pushed the update/wordpress-data-documentation branch from 2ff83cd to c8fb588 Compare June 30, 2022 13:50
@renatho
Copy link
Contributor Author

renatho commented Jun 30, 2022

Sorry @renatho I missed that you couldn't merge. Can you rebase to trigger test runs again? Looks like a flakey test falsely failed this.

Hey @dmsnell! No problem! Thank you for checking this! 😊
I rebased it and everything is green now. ✅

@dmsnell dmsnell merged commit 993836f into WordPress:trunk Jun 30, 2022
@github-actions github-actions bot added this to the Gutenberg 13.7 milestone Jun 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Data /packages/data [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants