-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
72bc8f1
Add new @wordpress/data-controls package
nerrad 628db6b
include new package in main package.json
nerrad 989568d
Implement new package with @wordpress/editor store
nerrad 1da55b7
docs tool generating this for some reason
nerrad f035a17
include new package with doc generation tool
nerrad 63b00c5
updated manifest from doc generation
nerrad 57ea88d
updated package-lock.json
nerrad 9e76c48
not sure why docs build tool is doing this.
nerrad 1642349
use ternary
nerrad dff65a5
data-controls added to manifest by docs build tool
nerrad 0349090
update README for editor package
nerrad 48107e0
updates to editor store actions tests
nerrad 5748e1c
add missing `@example` tag and regenerate docs
nerrad e9dc0a6
add tests for package
nerrad 1e0070f
fix typo in changelog for package name
nerrad a6467e5
fix typo for package name in readme
nerrad d62acd3
more typos
nerrad c7b2c61
Use lower version for initial release.
nerrad 8689a77
Add heading for API.
nerrad d187fcc
Update CHANGELOG.md version reference.
nerrad b9d38ed
add data-controls to webpack plugin config
nerrad 9ea3413
Revert "add data-controls to webpack plugin config"
nerrad ca4a16c
use named export for controls object
nerrad 03823a0
update docs
nerrad 5dfee2c
woop fix import on tests
nerrad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Master | ||
|
||
Initial release of the @wordpress/data-controls package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
# Data Controls | ||
|
||
The data controls module is a module intended to simplify implementation of common controls used with the [`@wordpress/data`](/packages/data/README.md) package. | ||
|
||
**Note:** It is assumed that the registry being used has the controls plugin enabled on it (see [more details on controls here](https://github.com/WordPress/gutenberg/tree/master/packages/data#controls)) | ||
|
||
## Installation | ||
|
||
Install the module | ||
|
||
```bash | ||
npm install @wordpress/data-controls --save | ||
``` | ||
|
||
_This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. Learn more about it in [Babel docs](https://babeljs.io/docs/en/next/caveats)._ | ||
|
||
The following controls are available on the object returned by the module: | ||
|
||
## API | ||
|
||
<!-- START TOKEN(Autogenerated API docs) --> | ||
nerrad marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<a name="apiFetch" href="#apiFetch">#</a> **apiFetch** | ||
|
||
Dispatches a control action for triggering an api fetch call. | ||
|
||
_Usage_ | ||
|
||
```js | ||
import { apiFetch } from '@wordpress/data-controls'; | ||
|
||
// Action generator using apiFetch | ||
export function* myAction { | ||
const path = '/v2/my-api/items'; | ||
const items = yield apiFetch( { path } ); | ||
// do something with the items. | ||
} | ||
``` | ||
|
||
_Parameters_ | ||
|
||
- _request_ `Object`: Arguments for the fetch request. | ||
|
||
_Returns_ | ||
|
||
- `Object`: The control descriptor. | ||
|
||
<a name="controls" href="#controls">#</a> **controls** | ||
|
||
The default export is what you use to register the controls with your custom | ||
store. | ||
|
||
_Usage_ | ||
|
||
```js | ||
// WordPress dependencies | ||
import { controls } from '@wordpress/data-controls'; | ||
import { registerStore } from '@wordpress/data'; | ||
|
||
// Internal dependencies | ||
import reducer from './reducer'; | ||
import * as selectors from './selectors'; | ||
import * as actions from './actions'; | ||
import * as resolvers from './resolvers'; | ||
|
||
registerStore ( 'my-custom-store', { | ||
reducer, | ||
controls, | ||
actions, | ||
selectors, | ||
resolvers, | ||
} ); | ||
``` | ||
|
||
_Returns_ | ||
|
||
- `Object`: An object for registering the default controls with the store. | ||
|
||
<a name="dispatch" href="#dispatch">#</a> **dispatch** | ||
|
||
Dispatches a control action for triggering a registry dispatch. | ||
|
||
_Usage_ | ||
|
||
```js | ||
import { dispatch } from '@wordpress/data-controls'; | ||
|
||
// Action generator using dispatch | ||
export function* myAction { | ||
yield dispatch( 'core/edit-post' ).togglePublishSidebar(); | ||
// do some other things. | ||
} | ||
``` | ||
|
||
_Parameters_ | ||
|
||
- _storeKey_ `string`: The key for the store the action belongs to | ||
- _actionName_ `string`: The name of the action to dispatch | ||
- _args_ `Array`: Arguments for the dispatch action. | ||
|
||
_Returns_ | ||
|
||
- `Object`: The control descriptor. | ||
|
||
<a name="select" href="#select">#</a> **select** | ||
|
||
Dispatches a control action for triggering a registry select. | ||
|
||
Note: when this control action is handled, it automatically considers | ||
selectors that may have a resolver. It will await and return the resolved | ||
value when the selector has not been resolved yet. | ||
|
||
_Usage_ | ||
|
||
```js | ||
import { select } from '@wordpress/data-controls'; | ||
|
||
// Action generator using select | ||
export function* myAction { | ||
const isSidebarOpened = yield select( 'core/edit-post', 'isEditorSideBarOpened' ); | ||
// do stuff with the result from the select. | ||
} | ||
``` | ||
|
||
_Parameters_ | ||
|
||
- _storeKey_ `string`: The key for the store the selector belongs to | ||
- _selectorName_ `string`: The name of the selector | ||
- _args_ `Array`: Arguments for the select. | ||
|
||
_Returns_ | ||
|
||
- `Object`: The control descriptor. | ||
|
||
|
||
<!-- END TOKEN(Autogenerated API docs) --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "@wordpress/data-controls", | ||
"version": "1.0.0-beta.1", | ||
"description": "A set of common controls for the @wordpress/data api.", | ||
"author": "The WordPress Contributors", | ||
"license": "GPL-2.0-or-later", | ||
"keywords": [ | ||
"wordpress", | ||
"data", | ||
"controls" | ||
], | ||
"homepage": "https://github.com/WordPress/gutenberg/tree/master/packages/data-controls/README.md", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/WordPress/gutenberg.git", | ||
"directory": "packages/data-controls" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/WordPress/gutenberg/issues" | ||
}, | ||
"main": "build/index.js", | ||
"module": "build-module/index.js", | ||
"react-native": "src/index", | ||
"dependencies": { | ||
"@wordpress/api-fetch": "file:../api-fetch", | ||
"@wordpress/data": "file:../data" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
core-data
. This will require an allow list anyway.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.