-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Update wordpress/data documentation in order to prefer store object instead of store name to access the store #41210
Conversation
packages/data/README.md
Outdated
@@ -481,7 +485,7 @@ _Usage_ | |||
```js | |||
import { dispatch } from '@wordpress/data'; | |||
|
|||
dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 ); | |||
dispatch( store ).setPrice( 'hammer', 9.75 ); |
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.
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.
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.
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 );
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.
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.
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.
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)."
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.
@dmsnell, thank you for the great suggestions! I applied them and I updated the documentation with npm run docs:build
.
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)."
packages/data/README.md
Outdated
@@ -481,7 +485,7 @@ _Usage_ | |||
```js | |||
import { dispatch } from '@wordpress/data'; | |||
|
|||
dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 ); | |||
dispatch( store ).setPrice( 'hammer', 9.75 ); |
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.
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 );
packages/data/README.md
Outdated
@@ -481,7 +485,7 @@ _Usage_ | |||
```js | |||
import { dispatch } from '@wordpress/data'; | |||
|
|||
dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 ); | |||
dispatch( store ).setPrice( 'hammer', 9.75 ); |
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.
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.
packages/data/README.md
Outdated
@@ -481,7 +485,7 @@ _Usage_ | |||
```js | |||
import { dispatch } from '@wordpress/data'; | |||
|
|||
dispatch( 'my-shop' ).setPrice( 'hammer', 9.75 ); | |||
dispatch( store ).setPrice( 'hammer', 9.75 ); |
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.
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)."
7bb1010
to
a79b8a7
Compare
packages/data/src/index.js
Outdated
* 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. |
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.
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.
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 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?
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 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.
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.
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.
Hey folks! Should we go ahead and merge this? |
Hey folks! 👋 |
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. |
2ff83cd
to
c8fb588
Compare
What?
It updates part of the documentation (@wordpress/data) to use store object instead of store names when accessing the stores through the
select
anddispatch
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.