-
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
Packages: Add new @wordpress/data-controls package. #15435
Conversation
9a9a4a1
to
b47c02c
Compare
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 guess this should be reviewed by @youknowriad or @aduth. I can try myself but I didn't follow recent changes in this area.
I left my comments related to the package itself. Everything looks great, there are some tiny things to updated which I highlighted.
@@ -17,6 +17,7 @@ const packages = [ | |||
'Autogenerated selectors': 'src/selectors.js', | |||
} ], | |||
'data', | |||
'data-controls', |
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.
@nosolosw, have you had a chance to revisit this list so we could use blacklist instead to make it easier to add new packages?
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 has grown on me that an allow list works better in this case for two reasons:
- I know we've talked about detecting the entry point from package.json. Note, however, how some packages will need more than this (example:
core-data
. This will require an allow list anyway. - Using a deny list will do unnecessary extra work. Currently, docgen will report an error if it doesn't find a token in a README file, but this can be improved to gracefully continue. However, we'll need parsing the package entry point files anyway to know whether there is a token or not - wasting those cycles.
Adding/Removing a package is not a common operation, so I think is fine to require authors to do this explicitely if they want API doc generation.
First thought: Is |
Thought: Should these (at least |
I like this enhancement 👍 |
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'd be more okay to start with just select
and dispatch
, but I could be convinced of apiFetch
if the arguments are made. The code looks good.
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.
We need to update this, since it has a default export. Otherwise the window global doesn't work as expected (wp.dataControls.default
):
Lines 71 to 78 in 8960509
new LibraryExportDefaultPlugin( [ | |
'api-fetch', | |
'deprecated', | |
'dom-ready', | |
'redux-routine', | |
'token-list', | |
'shortcode', | |
].map( camelCaseDash ) ), |
Although, this is a unique case of needing both default and named exports. How do you propose this might be handled from the global? Is referencing the controls object by .default
acceptable? It doesn't seem quite so obvious to me.
f7b2006
to
8ce6b53
Compare
Arguments for:
Interesting, this was a specific about the build process I wasn't aware of. I'm also a bit surprised that the implementation here of the new package (in @wordpress/editor) didn't break because of that. Typical usage will be importing the default for registering with the store (as done here) Are you thinking it'd be better to export it as a named export so that it's a bit more evident it's purpose on the global (i.e. |
Oh I see, the With configuration in webpack plugin
Without configuration in webpack plugin
|
- to use new data-controls package
Co-Authored-By: Grzegorz (Greg) Ziółkowski <[email protected]>
Co-Authored-By: Grzegorz (Greg) Ziółkowski <[email protected]>
Follows repo conventions about using Master as the version heading for unreleased changes.
This reverts commit 36a0b98.
5afd069
to
5dfee2c
Compare
I agree |
Merging this PR as it seems ready and was approved, and I have a PR depending on it that I would like to merge. If there are is any other improvement I think it can be shipped in a follow-up PR. |
Sorry, I missed this question, personally like the version that was proposed: |
Description
This is a new package triggered in part by this and this comment.
The
@wordpress/data-controls
package exposes a set of common controls consumers can use when registering custom stores. In the initial iteration the following controls are included:select
: For selecting from another data store in the registry.dispatch
: For dispatching actions to another store in the registry.apiFetch
: For doing a request via the@wordpress/api-fetch
module.Notes:
select
control has been made resolver aware. Essentially this means if the named selector has a sibling resolver registered in the given store, then a promise is returned that resolves to the value for the selector after any necessary resolution is completed. If the selector does not have a resolver sibling then it is called directly. This allows for client code to not have to worry about resolution when using this control (Note: This requires a change in@wordpress/data
: see @wordpress/data: ExposehasResolver
property on returned selectors #15436).@wordpress/editor
. Primarily I did this so that things could be tested but I'm on the fence with whether this should be done in its own pull. So I'm looking from feedback from reviewers on this. It turns out the the changes aren't that much (other than eliminating code 🎉) so I think it'd be good to merge with an initial implementation of the package.Todos:
@wordpress/data
exposing whether a selector has a resolver (see @wordpress/data: ExposehasResolver
property on returned selectors #15436)@wordpress/editor
) to ensure api is usable and works as expected.CHANGELOG.md
and tests will need updated.How has this been tested?
@wordpress/editor
and ensure the editor continues to work via user testing.Types of changes
core/editor
store. Thus the editor is impacted but impacted areas are covered by e2e and unit tests.Checklist: