-
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
Data: Document WPDataRegistry properties #16693
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,18 @@ import metadataReducer from './metadata/reducer'; | |
import * as metadataSelectors from './metadata/selectors'; | ||
import * as metadataActions from './metadata/actions'; | ||
|
||
/** | ||
* @typedef {import('../registry').WPDataRegistry} WPDataRegistry | ||
*/ | ||
|
||
/** | ||
* Creates a namespace object with a store derived from the reducer given. | ||
* | ||
* @param {string} key Identifying string used for namespace and redex dev tools. | ||
* @param {Object} options Contains reducer, actions, selectors, and resolvers. | ||
* @param {Object} registry Registry reference. | ||
* @param {string} key Unique namespace identifier. | ||
* @param {Object} options Registered store options, with properties | ||
* describing reducer, actions, selectors, and | ||
* resolvers. | ||
* @param {WPDataRegistry} registry Registry reference. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no way for editors to know how to interpret this without importing it in the file as its own typedef. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hm, is this what the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Precisely. In javascript, in order to reference types that are defined elsewhere (be it in a typescript definition file, or as standard JSDoc), the types must first be imported in the referencing file as a Otherwise the editor will not be able to provide type hints or "intellisense" (in VS editors) |
||
* | ||
* @return {Object} Store Object. | ||
*/ | ||
|
@@ -102,10 +108,11 @@ export default function createNamespace( key, options, registry ) { | |
/** | ||
* Creates a redux store for a namespace. | ||
* | ||
* @param {string} key Part of the state shape to register the | ||
* selectors for. | ||
* @param {Object} options Registered store options. | ||
* @param {Object} registry Registry reference, for resolver enhancer support. | ||
* @param {string} key Unique namespace identifier. | ||
* @param {Object} options Registered store options, with properties | ||
* describing reducer, actions, selectors, and | ||
* resolvers. | ||
* @param {WPDataRegistry} registry Registry reference. | ||
* | ||
* @return {Object} Newly created redux store. | ||
*/ | ||
|
@@ -143,15 +150,16 @@ function createReduxStore( key, options, registry ) { | |
} | ||
|
||
/** | ||
* Maps selectors to a redux store. | ||
* Maps selectors to a store. | ||
* | ||
* @param {Object} selectors Selectors to register. Keys will be used as the | ||
* public facing API. Selectors will get passed the | ||
* state as first argument. | ||
* @param {Object} store The redux store to which the selectors should be mapped. | ||
* @param {Object} registry Registry reference. | ||
* @param {Object} selectors Selectors to register. Keys will be used as | ||
* the public facing API. Selectors will get | ||
* passed the state as first argument. | ||
* @param {Object} store The store to which the selectors should be | ||
* mapped. | ||
* @param {WPDataRegistry} registry Registry reference. | ||
* | ||
* @return {Object} Selectors mapped to the redux store provided. | ||
* @return {Object} Selectors mapped to the provided store. | ||
*/ | ||
function mapSelectors( selectors, store, registry ) { | ||
const createStateSelector = ( registeredSelector ) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,23 @@ import createCoreDataStore from './store'; | |
/** | ||
* An isolated orchestrator of store registrations. | ||
* | ||
* @typedef {WPDataRegistry} | ||
* @typedef {Object} WPDataRegistry | ||
* | ||
* @property {Function} registerGenericStore | ||
* @property {Function} registerStore | ||
* @property {Function} subscribe | ||
* @property {Function} select | ||
* @property {Function} dispatch | ||
* @property {Function} registerGenericStore Given a namespace key and settings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest making it the standard for this entire project (and all of WordPress, if possible) to use the tag It'll help somewhat with the smushed descriptions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In some respect I appreciate the constraints to encourage being brief with the names and descriptions. I don't have a strong feeling about |
||
* object, registers a new generic | ||
* store. | ||
* @property {Function} registerStore Given a namespace key and settings | ||
* object, registers a new namespace | ||
* store. | ||
* @property {Function} subscribe Given a function callback, invokes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using this property as an example because it's the easiest one to do. IMHO, it would be better to do one of the following options since the type Option 1/**
* @callback Subscriber Description of subscriber
* @param {() => void} callback Description of callback parameter.
* @return {void}
*/ Option 2/**
* @typedef {(callback: () => void) => void} Subscriber Description of subscriber
*/ And then use it on this line as... /**
* [...]
* @prop {Subscriber} registerGenericStore Given a namespace key and settings
* object, registers a new generic store.
* [...]
*/ I assume that this is also temporary though until typescript checking makes its way here. So not super important. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are those syntaxes standard in JSDoc? It would be a good thing to detail in the documentation standards, I think. In general, I agree with you. I didn't aim to change the types here, however. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I agree that the documentation standards should be combed through for accuracy and, ideally, these standards should be linted automatically. Pretty sure |
||
* the callback on any change to state | ||
* within any registered store. | ||
* @property {Function} select Given a namespace key, returns an | ||
* object of the store's registered | ||
* selectors. | ||
* @property {Function} dispatch Given a namespace key, returns an | ||
* object of the store's registered | ||
* action dispatchers. | ||
*/ | ||
|
||
/** | ||
|
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.
Type
Object
is not useful IMHO. I assume this is temporary until the typescript checking makes its way into this file, yes?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 say temporary, yes. I'm not really changing anything here aside from alignment and description.
WPDataRegistry
is the only type being changed throughout this pull request.