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

Packages: Add new @wordpress/data-controls package. #15435

Merged
merged 25 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
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 May 5, 2019
628db6b
include new package in main package.json
nerrad May 5, 2019
989568d
Implement new package with @wordpress/editor store
nerrad May 5, 2019
1da55b7
docs tool generating this for some reason
nerrad May 5, 2019
f035a17
include new package with doc generation tool
nerrad May 5, 2019
63b00c5
updated manifest from doc generation
nerrad May 5, 2019
57ea88d
updated package-lock.json
nerrad May 5, 2019
9e76c48
not sure why docs build tool is doing this.
nerrad May 19, 2019
1642349
use ternary
nerrad May 19, 2019
dff65a5
data-controls added to manifest by docs build tool
nerrad May 19, 2019
0349090
update README for editor package
nerrad May 19, 2019
48107e0
updates to editor store actions tests
nerrad May 19, 2019
5748e1c
add missing `@example` tag and regenerate docs
nerrad May 19, 2019
e9dc0a6
add tests for package
nerrad May 19, 2019
1e0070f
fix typo in changelog for package name
nerrad May 19, 2019
a6467e5
fix typo for package name in readme
nerrad May 19, 2019
d62acd3
more typos
nerrad May 19, 2019
c7b2c61
Use lower version for initial release.
nerrad May 20, 2019
8689a77
Add heading for API.
nerrad May 20, 2019
d187fcc
Update CHANGELOG.md version reference.
nerrad May 22, 2019
b9d38ed
add data-controls to webpack plugin config
nerrad May 22, 2019
9ea3413
Revert "add data-controls to webpack plugin config"
nerrad May 22, 2019
ca4a16c
use named export for controls object
nerrad May 22, 2019
03823a0
update docs
nerrad May 22, 2019
5dfee2c
woop fix import on tests
nerrad May 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bin/update-readmes.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const packages = [
'Autogenerated selectors': 'src/selectors.js',
} ],
'data',
'data-controls',
Copy link
Member

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?

Copy link
Member

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.

'date',
'deprecated',
'dom',
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest-devhub.json
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,12 @@
"markdown_source": "../packages/custom-templated-path-webpack-plugin/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data-controls",
"slug": "packages-data-controls",
"markdown_source": "../packages/data-controls/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data",
"slug": "packages-data",
Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,12 @@
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/custom-templated-path-webpack-plugin/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data-controls",
"slug": "packages-data-controls",
"markdown_source": "https://raw.githubusercontent.com/WordPress/gutenberg/master/packages/data-controls/README.md",
"parent": "packages"
},
{
"title": "@wordpress/data",
"slug": "packages-data",
Expand Down
8 changes: 8 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@wordpress/compose": "file:packages/compose",
"@wordpress/core-data": "file:packages/core-data",
"@wordpress/data": "file:packages/data",
"@wordpress/data-controls": "file:packages/data-controls",
"@wordpress/date": "file:packages/date",
"@wordpress/deprecated": "file:packages/deprecated",
"@wordpress/dom": "file:packages/dom",
Expand Down
3 changes: 3 additions & 0 deletions packages/data-controls/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Master

Initial release of the @wordpress/data-controls package.
136 changes: 136 additions & 0 deletions packages/data-controls/README.md
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) -->
31 changes: 31 additions & 0 deletions packages/data-controls/package.json
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"
}
}
Loading