Skip to content

Commit

Permalink
ResolveStatus must be private of useEntityRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
widoz committed Aug 15, 2023
1 parent 98ee82b commit b665ff2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 0 additions & 6 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import { BaseEntityRecords, Context } from '@wordpress/core-data';
export default EntitiesSearch;

declare namespace EntitiesSearch {
enum ResolveStatus {
ERROR = 'ERROR',
SUCCESS = 'SUCCESS',
RESOLVING = 'RESOLVING',
}

type PostType<C extends Context = 'view'> = BaseEntityRecords.Type<C>;

type ViewablePostType = Readonly<{
Expand Down
10 changes: 8 additions & 2 deletions sources/js/src/hooks/use-entity-records.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { Set } from 'immutable';

import { useEntityRecords as useCoreEntityRecords } from '@wordpress/core-data';

enum ResolveStatus {
ERROR = 'ERROR',
SUCCESS = 'SUCCESS',
RESOLVING = 'RESOLVING',
}

/**

Check failure on line 12 in sources/js/src/hooks/use-entity-records.ts

View workflow job for this annotation

GitHub Actions / build

Expected JSDoc block lines to be aligned
* The hook will return an empty collection while resolving.
* This is to guarantee a better flow in the data manipulation, therefore do not count on the data returned by the
Expand All @@ -19,14 +25,14 @@ export function useEntityRecords<Entity>(
queryArgs: Record<string, unknown> = {}
): EntitiesSearch.EntitiesRecords<Entity> {
const entities = useCoreEntityRecords<Entity>(kind, name, queryArgs);
const status = entities.status as any as EntitiesSearch.ResolveStatus;
const status = entities.status as any as ResolveStatus;

return Object.freeze({
records: () => Set(entities.records ?? []),
isResolving: () =>
entities.isResolving &&
!entities.hasResolved &&
status === EntitiesSearch.ResolveStatus.RESOLVING,
status === ResolveStatus.RESOLVING,
errored: () => makeStatusCallback(entities, 'ERROR'),
succeed: () => makeStatusCallback(entities, 'SUCCESS'),
});
Expand Down

0 comments on commit b665ff2

Please sign in to comment.