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

data: Add types to redux-store/metadata/selectors #32965

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion packages/data/src/redux-store/metadata/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Action =
typeof import('./actions').invalidateResolutionForStoreSelector
>;

type State = EquivalentKeyMap< unknown[] | unknown, boolean >;
export type State = EquivalentKeyMap< unknown[] | unknown, boolean >;

/**
* Reducer function returning next state for selector resolution of
Expand Down
34 changes: 18 additions & 16 deletions packages/data/src/redux-store/metadata/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,24 @@
*/
import { get } from 'lodash';

/** @typedef {Record<string, import('./reducer').State>} State */
ciampo marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns the raw `isResolving` value for a given selector name,
* and arguments set. May be undefined if the selector has never been resolved
* or not resolved for the given set of arguments, otherwise true or false for
* resolution started and completed respectively.
*
* @param {Object} state Data state.
* @param {string} selectorName Selector name.
* @param {Array} args Arguments passed to selector.
* @param {State} state Data state.
* @param {string} selectorName Selector name.
* @param {unknown[]} args Arguments passed to selector.
*
* @return {?boolean} isResolving value.
* @return {boolean | undefined} isResolving value.
*/
export function getIsResolving( state, selectorName, args ) {
const map = get( state, [ selectorName ] );
if ( ! map ) {
return;
return undefined;
}

return map.get( args );
Expand All @@ -28,9 +30,9 @@ export function getIsResolving( state, selectorName, args ) {
* Returns true if resolution has already been triggered for a given
* selector name, and arguments set.
*
* @param {Object} state Data state.
* @param {string} selectorName Selector name.
* @param {?Array} args Arguments passed to selector (default `[]`).
* @param {State} state Data state.
* @param {string} selectorName Selector name.
* @param {unknown[]} [args] Arguments passed to selector (default `[]`).
*
* @return {boolean} Whether resolution has been triggered.
*/
Expand All @@ -42,9 +44,9 @@ export function hasStartedResolution( state, selectorName, args = [] ) {
* Returns true if resolution has completed for a given selector
* name, and arguments set.
*
* @param {Object} state Data state.
* @param {string} selectorName Selector name.
* @param {?Array} args Arguments passed to selector.
* @param {State} state Data state.
* @param {string} selectorName Selector name.
* @param {unknown[]} [args] Arguments passed to selector.
*
* @return {boolean} Whether resolution has completed.
*/
Expand All @@ -56,9 +58,9 @@ export function hasFinishedResolution( state, selectorName, args = [] ) {
* Returns true if resolution has been triggered but has not yet completed for
* a given selector name, and arguments set.
*
* @param {Object} state Data state.
* @param {string} selectorName Selector name.
* @param {?Array} args Arguments passed to selector.
* @param {State} state Data state.
* @param {string} selectorName Selector name.
* @param {unknown[]} [args] Arguments passed to selector.
*
* @return {boolean} Whether resolution is in progress.
*/
Expand All @@ -69,9 +71,9 @@ export function isResolving( state, selectorName, args = [] ) {
/**
* Returns the list of the cached resolvers.
*
* @param {Object} state Data state.
* @param {State} state Data state.
*
* @return {Object} Resolvers mapped by args and selectorName.
* @return {State} Resolvers mapped by args and selectorName.
*/
export function getCachedResolvers( state ) {
return state;
Expand Down
5 changes: 1 addition & 4 deletions packages/data/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
// { "path": "../redux-routine" }
],
"include": [
"src/redux-store/metadata/actions.js",
"src/redux-store/metadata/equivalent-key-map.d.ts",
"src/redux-store/metadata/reducer.ts",
"src/redux-store/metadata/utils.js"
"src/redux-store/metadata/**/*",
]
}