Skip to content

Data: Improve documentation for new API added around stores#27061

Merged
gziolo merged 5 commits into
masterfrom
update/data-store-param-docs
Nov 19, 2020
Merged

Data: Improve documentation for new API added around stores#27061
gziolo merged 5 commits into
masterfrom
update/data-store-param-docs

Conversation

@gziolo
Copy link
Copy Markdown
Member

@gziolo gziolo commented Nov 18, 2020

Description

This PR improves @wordpress/data documentation based on the changes introduced in #26655. Some of the points were raised by @jsnajdr:

The data package adds a new API without breaking changes, so it deserves a minor version bump on next release.

Then, some other packages, like annotations, started to rely on the new data API, and would need a major bump. In a sense, they support only on the latest version of the underlying "operating system" and won't run on older versions.

The annotations package also adds a new named export (store) that wasn't there before. That would warrant a minor version bump if the package didn't already have a major one for a different reason.

The core-data package removes the storeConfig export (breaking change that warrants a major bump) and add a new store export (minor bump).

And so on for all other affected packages...

In a gist, this PR ensures that:

  • new API methods are properly documented in the README file of @wordpress/data ana listed in CHANGELOG file
  • unit tests for API changes are added
  • wp.data global gets replaced with import statements for @wordpress/data
  • CHANGELOG files for all packages that expose store definitions are updated
  • decide what to do about omit storeConfig from @wordpress/core-data as it was never published to npm

How has this been tested?

npm run test-unit
npm run docs:build

@gziolo gziolo self-assigned this Nov 18, 2020
@gziolo gziolo added [Package] Data /packages/data [Type] Developer Documentation Documentation for developers [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels Nov 18, 2020
@gziolo gziolo requested review from oandregal and sirreal November 18, 2020 09:16
import * as metadataSelectors from './metadata/selectors';
import * as metadataActions from './metadata/actions';

/** @typedef {import('../types').WPDataRegistry} WPDataRegistry */
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@sirreal - we have similar usage in other places, but this one is unique as it references a TypeScript file. Does it work correctly with our configuration? Is there a better way to code it in JSDoc?

Aside: I would mind if we were to use TypeScript files for type definitions rather than JSDoc comments but continue using JSDoc only approach for typing codebase 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I did this, I prefer a typescript file for type definition personally, it's easier than big JSDoc typedefs.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I did this, I prefer a typescript file for type definition personally, it's easier than big JSDoc typedefs.

I know you did, but I added a typedef (sort of proxy) to fix the documentation generated to output the actual type rather than the Unknown type string.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

true, the doc generator should be improved. We might want to try a typescript based one

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I thought this would be fine, but @saramarcondes pointed out to me that it can create a problem in the generated types. They would need to include the types, but .d.ts declaration files will not be included in the compiled types.

We may be able to work around that with some hacks, but the simplest way forward is to change from a declaration file (.d.ts) to a TypeScript file (.ts) which will then be bundled. I'd recommend that approach.

You can confirm this by checking build-types for the stan package, e.g. build-types/store.d.ts:

export function createStoreAtom<T>(subscribe: (listener: () => void) => (() => void), get: () => T, dispatch: (action: any) => void, config?: WPCommonAtomConfig | undefined): import("./types").WPAtom<T>;
export type WPAtom<T> = (registry: import("./types").WPAtomRegistry) => import("./types").WPAtomState<T>;
export type WPCommonAtomConfig = {
    id?: string | undefined;
    isAsync?: boolean | undefined;
};
//# sourceMappingURL=store.d.ts.map

This file references ./types, which doesn't exist. There's a Stack Overflow question that provides more detail.

This will create problems in the published types.

@youknowriad @gziolo What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

so by just renaming the file, it works? Sounds good to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As long as we don't use regular .ts files, it should be fine to rename to make it work 😃

/**
* Registers a standard `@wordpress/data` store definition.
*
* @param {import('./types').WPDataStore} store Store definition.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@nosolosw – is there any way we could improve @wordpress/docgen to ignore the import part so we don't have to use typedef workaround?

Comment thread packages/data/src/test/registry.js Outdated
@gziolo gziolo requested a review from youknowriad November 18, 2020 09:21
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Nov 18, 2020

Size Change: 0 B

Total Size: 1.19 MB

ℹ️ View Unchanged
Filename Size Change
build/a11y/index.js 1.14 kB 0 B
build/annotations/index.js 3.8 kB 0 B
build/api-fetch/index.js 3.42 kB 0 B
build/autop/index.js 2.84 kB 0 B
build/blob/index.js 664 B 0 B
build/block-directory/index.js 8.72 kB 0 B
build/block-directory/style-rtl.css 943 B 0 B
build/block-directory/style.css 942 B 0 B
build/block-editor/index.js 133 kB 0 B
build/block-editor/style-rtl.css 11.3 kB 0 B
build/block-editor/style.css 11.3 kB 0 B
build/block-library/editor-rtl.css 9.03 kB 0 B
build/block-library/editor.css 9.03 kB 0 B
build/block-library/index.js 147 kB 0 B
build/block-library/style-rtl.css 8.1 kB 0 B
build/block-library/style.css 8.1 kB 0 B
build/block-library/theme-rtl.css 792 B 0 B
build/block-library/theme.css 793 B 0 B
build/block-serialization-default-parser/index.js 1.87 kB 0 B
build/block-serialization-spec-parser/index.js 3.06 kB 0 B
build/blocks/index.js 48 kB 0 B
build/components/index.js 171 kB 0 B
build/components/style-rtl.css 15.3 kB 0 B
build/components/style.css 15.3 kB 0 B
build/compose/index.js 9.95 kB 0 B
build/core-data/index.js 14.8 kB 0 B
build/data-controls/index.js 827 B 0 B
build/data/index.js 8.8 kB 0 B
build/date/index.js 11.2 kB 0 B
build/deprecated/index.js 768 B 0 B
build/dom-ready/index.js 571 B 0 B
build/dom/index.js 4.92 kB 0 B
build/edit-navigation/index.js 11.2 kB 0 B
build/edit-navigation/style-rtl.css 881 B 0 B
build/edit-navigation/style.css 885 B 0 B
build/edit-post/index.js 306 kB 0 B
build/edit-post/style-rtl.css 6.45 kB 0 B
build/edit-post/style.css 6.44 kB 0 B
build/edit-site/index.js 23.3 kB 0 B
build/edit-site/style-rtl.css 3.85 kB 0 B
build/edit-site/style.css 3.85 kB 0 B
build/edit-widgets/index.js 26.4 kB 0 B
build/edit-widgets/style-rtl.css 3.13 kB 0 B
build/edit-widgets/style.css 3.13 kB 0 B
build/editor/editor-styles-rtl.css 476 B 0 B
build/editor/editor-styles.css 478 B 0 B
build/editor/index.js 42.7 kB 0 B
build/editor/style-rtl.css 3.85 kB 0 B
build/editor/style.css 3.85 kB 0 B
build/element/index.js 4.62 kB 0 B
build/escape-html/index.js 735 B 0 B
build/format-library/index.js 6.86 kB 0 B
build/format-library/style-rtl.css 547 B 0 B
build/format-library/style.css 548 B 0 B
build/hooks/index.js 2.16 kB 0 B
build/html-entities/index.js 623 B 0 B
build/i18n/index.js 3.57 kB 0 B
build/is-shallow-equal/index.js 698 B 0 B
build/keyboard-shortcuts/index.js 2.54 kB 0 B
build/keycodes/index.js 1.94 kB 0 B
build/list-reusable-blocks/index.js 3.1 kB 0 B
build/list-reusable-blocks/style-rtl.css 476 B 0 B
build/list-reusable-blocks/style.css 476 B 0 B
build/media-utils/index.js 5.32 kB 0 B
build/notices/index.js 1.81 kB 0 B
build/nux/index.js 3.42 kB 0 B
build/nux/style-rtl.css 671 B 0 B
build/nux/style.css 668 B 0 B
build/plugins/index.js 2.56 kB 0 B
build/primitives/index.js 1.43 kB 0 B
build/priority-queue/index.js 790 B 0 B
build/redux-routine/index.js 2.84 kB 0 B
build/reusable-blocks/index.js 3.06 kB 0 B
build/rich-text/index.js 13.3 kB 0 B
build/server-side-render/index.js 2.77 kB 0 B
build/shortcode/index.js 1.69 kB 0 B
build/token-list/index.js 1.27 kB 0 B
build/url/index.js 4.05 kB 0 B
build/viewport/index.js 1.86 kB 0 B
build/warning/index.js 1.14 kB 0 B
build/wordcount/index.js 1.22 kB 0 B

compressed-size-action

Comment thread packages/data/CHANGELOG.md Outdated
Comment thread packages/data/README.md
const { apiFetch } = wp;
const { registerStore } = wp.data;
import apiFetch from '@wordpress/api-fetch';
import { registerStore } from '@wordpress/data';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I believe we should remove "registerStore" and "registerGenericStore" from our docs and just use "register" and "createReduxStore"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it's a good idea. Let's do it separately as it requires more aggressive changes to README file.

@gziolo gziolo force-pushed the update/data-store-param-docs branch from dfae322 to 2a3683d Compare November 19, 2020 08:40
@gziolo gziolo marked this pull request as ready for review November 19, 2020 08:42
@gziolo
Copy link
Copy Markdown
Member Author

gziolo commented Nov 19, 2020

It's ready for final review, there are way too many whitespace changes in .md files because of Prettier formatting 😓

The diff mode that ignores them is very helpful: https://github.com/WordPress/gutenberg/pull/27061/files?diff=unified&w=1

Comment thread packages/data/CHANGELOG.md
Comment thread packages/data/src/components/use-dispatch/use-dispatch.js Outdated
@gziolo gziolo force-pushed the update/data-store-param-docs branch from 2a3683d to f5ae263 Compare November 19, 2020 15:12
@gziolo gziolo mentioned this pull request Nov 19, 2020
1 task
@gziolo gziolo merged commit 8428af0 into master Nov 19, 2020
@gziolo gziolo deleted the update/data-store-param-docs branch November 19, 2020 16:38
@github-actions github-actions Bot added this to the Gutenberg 9.5 milestone Nov 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Data /packages/data [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Developer Documentation Documentation for developers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants